| | |
Really really strugglisng with Jlist
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
Hi Im am so far trying to get the Jlist in my gui to display all the files in my directory H:\SDI\MileStoneMyworkspace\MileStoneMyWorkSpace\users\abimar
How can I do this. If you look I madde an attempt, tried to write files to object and list objects in J list.
What am I doing wrong?
How can I do this. If you look I madde an attempt, tried to write files to object and list objects in J list.
What am I doing wrong?
java Syntax (Toggle Plain Text)
package milestonemyworkspace; import javax.swing.*; import java.awt.BorderLayout; import com.borland.jbcl.layout.XYLayout; import com.borland.jbcl.layout.*; import java.awt.*; import java.awt.event.*; import java.awt.Font; import java.awt.Dimension; import java.util.ArrayList; import java.io.ObjectOutputStream; import java.io.FileOutputStream; /** * <p>Title: </p> * * The GUI for the Operating System * * @author Abimar Skrubel * @version 1.0 */ public class GUI extends JFrame { public GUI() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } private void jbInit() throws Exception { //Ommitted some GUI stuff (button etc) } }); //For going to create account page. btnGoCreateAccount.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { loginPanel.setVisible(false); createAccountPanel.setVisible(true); } }); //Selecting Pic1 as your password for your new account btnAccountPic1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("1"); System.out.println(user.getPassword()); } }); //Selecting Pic2 as your password for your new account btnAccountPic2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("2"); System.out.println(user.getPassword()); } }); //Selecting Pic3 as your password for your new account btnAccountPic3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("3"); System.out.println(user.getPassword()); } }); //Selecting Pic4 as your password for your new account btnAccountPic4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("4"); System.out.println(user.getPassword()); } }); //btnCreateAccount selected //For creating an account btnCreateAccount.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (user.getPassword() != null && user.getName() != "") //Password and user selection condition { user.setName(accountTextField.getText().toLowerCase()); user.saveUser(); createAccountPanel.setVisible(false); loginPanel.setVisible(true); JOptionPane.showMessageDialog(null, "Account Created!"); } else { JOptionPane.showMessageDialog(null, "Sorry. You need to select a picture or name."); } } }); //Choosing Pic1 as your password to login btnLoginPic1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("1"); System.out.println(user.getPassword()); } }); //Choosing Pic2 as your password to login btnLoginPic2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("2"); System.out.println(user.getPassword()); } }); //Choosing Pic3 as your password to login btnLoginPic3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("3"); System.out.println(user.getPassword()); } }); //Choosing Pic4 as your password to login btnLoginPic4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setPassword("4"); System.out.println(user.getPassword()); } }); //btnLogin selected //For loginning in btnLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user.setName(loginTextField.getText().toLowerCase()); user.loadUser(); if (user.getAccess() == true) { String[] data = {files.toString()}; writeFiles(); addToList(); myWorkSpacePanel.setVisible(true); loginPanel.setVisible(false); user.login(); } else { JOptionPane.showMessageDialog(null, "Sorry. You may have used the wrong name or picture."); } } }); //btnLogout selected //For loginning out btnLogout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { loginPanel.setVisible(true); myWorkSpacePanel.setVisible(false); } }); } XYLayout xYLayout1 = new XYLayout(); JButton btnMusicBox = new JButton(); JButton btnPictureAlbum = new JButton(); JButton btnStoryBook = new JButton(); private JList fileList; private ArrayList files; private ImageIcon boy = new ImageIcon("Pictures/boy.png"); private ImageIcon girl = new ImageIcon("Pictures/girl.png"); private ImageIcon dog = new ImageIcon("Pictures/dog.png"); private ImageIcon cat = new ImageIcon("Pictures/cat.png"); JPanel myWorkSpacePanel = new JPanel(); XYLayout xYLayout2 = new XYLayout(); JPanel loginPanel = new JPanel(); XYLayout xYLayout3 = new XYLayout(); JPanel createAccountPanel = new JPanel(); XYLayout xYLayout4 = new XYLayout(); JButton btnGoCreateAccount = new JButton(); JButton btnLogin = new JButton(); JButton btnLoginPic1 = new JButton(); JButton btnLoginPic2 = new JButton(); JButton btnLoginPic3 = new JButton(); JButton btnLoginPic4 = new JButton(); JButton btnGoLogin = new JButton(); JButton btnAccountPic4 = new JButton(); JButton btnAccountPic3 = new JButton(); JButton btnAccountPic2 = new JButton(); JButton btnAccountPic1 = new JButton(); JButton btnCreateAccount = new JButton(); JTextField accountTextField = new JTextField(); JTextField loginTextField = new JTextField(); //Creates user object User user = new User(); //Creates arraylist object ArrayList objs = new ArrayList(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JButton btnLogout = new JButton(); JList datalist = new JList(files); /** * Write files to files object */ public void writeFiles() { try { FileOutputStream fOut = new FileOutputStream("highScores.dat"); ObjectOutputStream oOut = new ObjectOutputStream(fOut); oOut.writeObject(files); oOut.close(); System.out.println("Files saved successfully!"); } catch(Exception e) { System.out.println("Error! High Scores not saved"); e.printStackTrace(); } } /** * Adds object to list */ public void addToList() { for (int i = 0; i < dataList.getModel().getSize(); i++) { System.out.println(dataList.getModel().getElementAt(i)); } } }
Last edited by eeeman; Apr 5th, 2007 at 6:09 pm.
![]() |
Similar Threads
- Updating a JList Renderer (Java)
- Populate data from database into JList (Java)
- A Default size for a blank JList? (Java)
- I can't get scrollbars on my JList box... (Java)
- JList - CellRendering (Java)
Other Threads in the Java Forum
- Previous Thread: I need Help
- Next Thread: need help
| Thread Tools | Search this Thread |
3d @param affinetransform android api applet application arc arguments array arrays automation binary bluetooth byte capture chat class classes click client code color compare component count database design detection eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer interface j2me java java.xls javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong print problem producer program programming project projectideas read recursion replaysolutions rim scanner screen server set size sms sort sql string swing terminal threads transforms tree ui web windows






