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?

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));
    }
  }
}

what is happening and what do you think should happen/do you want to happen?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.