943,515 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1110
  • Java RSS
Apr 5th, 2007
0

Really really strugglisng with Jlist

Expand Post »
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?


java Syntax (Toggle Plain Text)
  1.  
  2. package milestonemyworkspace;
  3. import javax.swing.*;
  4. import java.awt.BorderLayout;
  5. import com.borland.jbcl.layout.XYLayout;
  6. import com.borland.jbcl.layout.*;
  7. import java.awt.*;
  8. import java.awt.event.*;
  9. import java.awt.Font;
  10. import java.awt.Dimension;
  11. import java.util.ArrayList;
  12. import java.io.ObjectOutputStream;
  13. import java.io.FileOutputStream;
  14. /**
  15.  * <p>Title: </p>
  16.  *
  17.  * The GUI for the Operating System
  18.  *
  19.  * @author Abimar Skrubel
  20.  * @version 1.0
  21.  */
  22. public class GUI
  23. extends JFrame {
  24. public GUI() {
  25. try {
  26. jbInit();
  27. }
  28. catch (Exception ex) {
  29. ex.printStackTrace();
  30. }
  31. }
  32. private void jbInit() throws Exception {
  33.  
  34. //Ommitted some GUI stuff (button etc)
  35.  
  36.  
  37. }
  38. });
  39. //For going to create account page.
  40. btnGoCreateAccount.addActionListener(new ActionListener() {
  41. public void actionPerformed(ActionEvent e) {
  42. loginPanel.setVisible(false);
  43. createAccountPanel.setVisible(true);
  44. }
  45. });
  46. //Selecting Pic1 as your password for your new account
  47. btnAccountPic1.addActionListener(new ActionListener() {
  48. public void actionPerformed(ActionEvent e) {
  49. user.setPassword("1");
  50. System.out.println(user.getPassword());
  51. }
  52. });
  53. //Selecting Pic2 as your password for your new account
  54. btnAccountPic2.addActionListener(new ActionListener() {
  55. public void actionPerformed(ActionEvent e) {
  56. user.setPassword("2");
  57. System.out.println(user.getPassword());
  58. }
  59. });
  60. //Selecting Pic3 as your password for your new account
  61. btnAccountPic3.addActionListener(new ActionListener() {
  62. public void actionPerformed(ActionEvent e) {
  63. user.setPassword("3");
  64. System.out.println(user.getPassword());
  65. }
  66. });
  67. //Selecting Pic4 as your password for your new account
  68. btnAccountPic4.addActionListener(new ActionListener() {
  69. public void actionPerformed(ActionEvent e) {
  70. user.setPassword("4");
  71. System.out.println(user.getPassword());
  72. }
  73. });
  74. //btnCreateAccount selected
  75. //For creating an account
  76. btnCreateAccount.addActionListener(new ActionListener() {
  77. public void actionPerformed(ActionEvent e) {
  78. if (user.getPassword() != null && user.getName() != "") //Password and user selection condition
  79. {
  80. user.setName(accountTextField.getText().toLowerCase());
  81. user.saveUser();
  82. createAccountPanel.setVisible(false);
  83. loginPanel.setVisible(true);
  84. JOptionPane.showMessageDialog(null, "Account Created!");
  85. }
  86. else {
  87. JOptionPane.showMessageDialog(null,
  88. "Sorry. You need to select a picture or name.");
  89. }
  90. }
  91. });
  92. //Choosing Pic1 as your password to login
  93. btnLoginPic1.addActionListener(new ActionListener() {
  94. public void actionPerformed(ActionEvent e) {
  95. user.setPassword("1");
  96. System.out.println(user.getPassword());
  97. }
  98. });
  99. //Choosing Pic2 as your password to login
  100. btnLoginPic2.addActionListener(new ActionListener() {
  101. public void actionPerformed(ActionEvent e) {
  102. user.setPassword("2");
  103. System.out.println(user.getPassword());
  104. }
  105. });
  106. //Choosing Pic3 as your password to login
  107. btnLoginPic3.addActionListener(new ActionListener() {
  108. public void actionPerformed(ActionEvent e) {
  109. user.setPassword("3");
  110. System.out.println(user.getPassword());
  111. }
  112. });
  113. //Choosing Pic4 as your password to login
  114. btnLoginPic4.addActionListener(new ActionListener() {
  115. public void actionPerformed(ActionEvent e) {
  116. user.setPassword("4");
  117. System.out.println(user.getPassword());
  118. }
  119. });
  120. //btnLogin selected
  121. //For loginning in
  122. btnLogin.addActionListener(new ActionListener() {
  123. public void actionPerformed(ActionEvent e) {
  124. user.setName(loginTextField.getText().toLowerCase());
  125. user.loadUser();
  126. if (user.getAccess() == true) {
  127. String[] data = {files.toString()};
  128. writeFiles();
  129. addToList();
  130.  
  131. myWorkSpacePanel.setVisible(true);
  132. loginPanel.setVisible(false);
  133. user.login();
  134. }
  135. else {
  136. JOptionPane.showMessageDialog(null,
  137. "Sorry. You may have used the wrong name or picture.");
  138. }
  139. }
  140. });
  141.  
  142. //btnLogout selected
  143. //For loginning out
  144. btnLogout.addActionListener(new ActionListener() {
  145. public void actionPerformed(ActionEvent e) {
  146. loginPanel.setVisible(true);
  147. myWorkSpacePanel.setVisible(false);
  148. }
  149. });
  150.  
  151.  
  152. }
  153.  
  154. XYLayout xYLayout1 = new XYLayout();
  155. JButton btnMusicBox = new JButton();
  156. JButton btnPictureAlbum = new JButton();
  157. JButton btnStoryBook = new JButton();
  158.  
  159.  
  160. private JList fileList;
  161. private ArrayList files;
  162. private ImageIcon boy = new ImageIcon("Pictures/boy.png");
  163. private ImageIcon girl = new ImageIcon("Pictures/girl.png");
  164. private ImageIcon dog = new ImageIcon("Pictures/dog.png");
  165. private ImageIcon cat = new ImageIcon("Pictures/cat.png");
  166. JPanel myWorkSpacePanel = new JPanel();
  167. XYLayout xYLayout2 = new XYLayout();
  168. JPanel loginPanel = new JPanel();
  169. XYLayout xYLayout3 = new XYLayout();
  170. JPanel createAccountPanel = new JPanel();
  171. XYLayout xYLayout4 = new XYLayout();
  172. JButton btnGoCreateAccount = new JButton();
  173. JButton btnLogin = new JButton();
  174. JButton btnLoginPic1 = new JButton();
  175. JButton btnLoginPic2 = new JButton();
  176. JButton btnLoginPic3 = new JButton();
  177. JButton btnLoginPic4 = new JButton();
  178. JButton btnGoLogin = new JButton();
  179. JButton btnAccountPic4 = new JButton();
  180. JButton btnAccountPic3 = new JButton();
  181. JButton btnAccountPic2 = new JButton();
  182. JButton btnAccountPic1 = new JButton();
  183. JButton btnCreateAccount = new JButton();
  184. JTextField accountTextField = new JTextField();
  185. JTextField loginTextField = new JTextField();
  186. //Creates user object
  187. User user = new User();
  188. //Creates arraylist object
  189. ArrayList objs = new ArrayList();
  190. JLabel jLabel2 = new JLabel();
  191. JLabel jLabel3 = new JLabel();
  192. JButton btnLogout = new JButton();
  193. JList datalist = new JList(files);
  194.  
  195. /**
  196.   * Write files to files object
  197.   */
  198. public void writeFiles()
  199. {
  200. try
  201. {
  202. FileOutputStream fOut = new FileOutputStream("highScores.dat");
  203. ObjectOutputStream oOut = new ObjectOutputStream(fOut);
  204. oOut.writeObject(files);
  205.  
  206. oOut.close();
  207. System.out.println("Files saved successfully!");
  208. }
  209. catch(Exception e)
  210. {
  211. System.out.println("Error! High Scores not saved");
  212. e.printStackTrace();
  213. }
  214. }
  215. /**
  216.   * Adds object to list
  217.   */
  218. public void addToList() {
  219. for (int i = 0; i < dataList.getModel().getSize(); i++) {
  220. System.out.println(dataList.getModel().getElementAt(i));
  221. }
  222. }
  223. }
Last edited by eeeman; Apr 5th, 2007 at 6:09 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007
Apr 6th, 2007
0

Re: Really really strugglisng with Jlist

what is happening and what do you think should happen/do you want to happen?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: I need Help
Next Thread in Java Forum Timeline: need help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC