943,188 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 991
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 14th, 2009
0

drop down menu question

Expand Post »
hi,
i have a JFrame... one menuBar placed on a JPanel.. and then two JPanel with different things (let me call them ActionPanelOne, and ActionPanelTwo).

i put the JPanel (with JMenuBar) North of the JFrame, and menuIteam will call the 2 ActionPanel individually to come up.

my problem is:
Once the ActionPanel is visible, the view of my dropped down menu items will be partially block by the ActionPanel.

is there a way to set the Panel(with menuBar) or the menuBar dropped down list alway on top or something? This is really bothering me.

thanks.
Similar Threads
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Apr 14th, 2009
0

Re: drop down menu question

I'm hardly an expert, but have you tried programmatically "clicking" the menu item again after the JPanel is set visible? That might make it appear on top again. Worth a try anyway, although even if it works, there is probably a better solution. I ran into a similar problem but mine was because I was using netbeans and the panels actually overlapped on each other.
Last edited by BestJewSinceJC; Apr 14th, 2009 at 12:46 am.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 14th, 2009
0

Re: drop down menu question

I'm hardly an expert, but have you tried programmatically "clicking" the menu item again after the JPanel is set visible? That might make it appear on top again. Worth a try anyway, although even if it works, there is probably a better solution. I ran into a similar problem but mine was because I was using netbeans and the panels actually overlapped on each other.

i am using eclipse, i don't know if it has the same problem netbeans has. but it is weird that i have a JScrollPane that works perfectly fine along with the JMenu.. the dropped down wouldn't be blocked. but the Jpanel just block the dropped down. huh... tried diff things and no luck so far... hope someone GUI expert stopped by and shed me some light.

sigh... never had a professor really know stuffs. people in this forum can answer my question much better.
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Apr 14th, 2009
0

Re: drop down menu question

Well, post your code. I'll run it and fool with it and try to help you out. Also, I didn't post this yesterday because I don't want to lead you in the wrong direction, but perhaps it has something to do with some of the issues discussed here?

edit:

And this is a guess, but I think JPanels are opaque by default, (see: setOpaque method) whereas JScrollPanes are not. So that would mean that when you add the JPanel, it paints the entire JPanel, covering your menu. But since JScrollPanes are not, this doesn't happen when you add it. Try invoking the JPanels setOpaque(false) method before you add it and see what happens.

set opaque method
Last edited by BestJewSinceJC; Apr 14th, 2009 at 3:33 pm.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 15th, 2009
0

Re: drop down menu question

well, i do have to say thank you for the on going help.

but yea, i tried the setOpaque(false) for my panel and guess this is not the solution.

i'll post my code and see if you may see something.
those sql thing you may comment out .. sorry, i can't send you the mdb file here so...

Java Syntax (Toggle Plain Text)
  1. ////// main , the frame ///////
  2. import java.text.MessageFormat;
  3. import java.sql.*;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.awt.print.*;
  8.  
  9. public class TheFrame extends JFrame
  10. {
  11. private JPanel menuPanel;
  12. private JPanel text;
  13. private BorderLayout bl = new BorderLayout();
  14.  
  15.  
  16. public TheFrame()
  17. {
  18.  
  19. menuPanel = new MenuBar(this);
  20. menuPanel.setBackground(java.awt.Color.white);
  21.  
  22. JLabel one = new JLabel("Java Final Project: Employee Record");
  23. one.setAlignmentX(0.5f);
  24. one.setAlignmentY(1f);
  25. JLabel two = new JLabel("Written by Henry Li");
  26. two.setAlignmentX(0.5f);
  27. two.setAlignmentY(1f);
  28.  
  29. text = new JPanel();
  30. text.setBackground(java.awt.Color.white);
  31. LayoutManager boxLayout = new BoxLayout(text, BoxLayout.Y_AXIS);
  32.  
  33. text.setLayout(boxLayout);
  34. text.add(one);
  35. text.add(two);
  36.  
  37.  
  38.  
  39.  
  40.  
  41. add(menuPanel, BorderLayout.NORTH);
  42. add(text, BorderLayout.CENTER);
  43. validate();
  44.  
  45. setBounds(400, 400, 600, 300);
  46. setVisible(true);
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. public static void main(String arg[]) throws SQLException
  56. {
  57. TheFrame frame = new TheFrame();
  58. }
  59.  
  60.  
  61. }// end the Class TheFrame

Java Syntax (Toggle Plain Text)
  1. // the menu class
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.awt.print.*;
  6.  
  7. public class MenuBar extends JPanel
  8. {
  9. private FlowLayout fl = new FlowLayout();
  10. private JMenuBar menuBar;
  11. private JMenu menuFile, menuEdit;
  12. private JMenuItem closeMenuItem, printMenuItem, showTableMItem, addRecordMItem;
  13.  
  14. private JFrame frame;
  15. private JScrollPane scrollPane;
  16. private JPanel panel;
  17.  
  18.  
  19. public MenuBar(JFrame theFrame)
  20. {
  21.  
  22. this.frame = theFrame;
  23.  
  24. menuFile = new JMenu("File"); // menu file
  25. menuFile.setForeground(java.awt.Color.black);
  26. closeMenuItem = new JMenuItem("Close"); // menu closeItem
  27. menuFile.add(closeMenuItem); // menu file with closeItem
  28. closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
  29. closeMenuItem.addActionListener(new closeMenuHandler());
  30.  
  31.  
  32. printMenuItem = new JMenuItem("Print"); // menu printItem
  33. menuFile.add(printMenuItem); // menu file with printItem
  34. printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', java.awt.Event.CTRL_MASK, false));
  35. ////////////// ActionListener /////////////
  36.  
  37.  
  38.  
  39. //*****************************************************************************
  40. //////////// Menu Bar Edit items /////////////////
  41. menuEdit= new JMenu("Edit"); // menu edit
  42. showTableMItem = new JMenuItem("Show Table"); // showTable item
  43. menuEdit.add(showTableMItem); // menu edit with showTable item
  44. showTableMItem.addActionListener(new ShowTable(frame));
  45.  
  46. //*****************************************************************************
  47.  
  48.  
  49. addRecordMItem = new JMenuItem("Add Record"); // addRecord item
  50. menuEdit.add(addRecordMItem); // edit menu with addRecord item
  51. addRecordMItem.addActionListener(new AddRecord(frame));
  52. ///////////////////////////////////////
  53.  
  54. //////// Add all menu things to the menu bar /////////
  55. menuBar = new JMenuBar(); // menu bar
  56. menuBar.setBackground(java.awt.Color.white);
  57. menuBar.add(menuFile); // menu bar with menu file
  58. menuBar.add(menuEdit); // menu bar with menu edit
  59.  
  60.  
  61.  
  62. setLayout(fl);
  63. fl.setAlignment(FlowLayout.LEFT);
  64.  
  65. add(menuBar);
  66. setVisible(true);
  67.  
  68.  
  69. }// end Constructor
  70.  
  71.  
  72.  
  73. }
  74.  
  75.  
  76. class closeMenuHandler implements ActionListener
  77. {
  78. public void actionPerformed(ActionEvent ae)
  79. {
  80. System.exit(0);
  81.  
  82. }
  83. }

Java Syntax (Toggle Plain Text)
  1. /// and the Jpanel class which blocks my dropped down//
  2. import java.sql.*;
  3. import java.text.MessageFormat;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. public class AddRecord implements ActionListener
  9. {
  10. // DataHolder is another sql class to get all the data from mdb file
  11. private DataHolder dh = new DataHolder();
  12. private JFrame frame;
  13. private JPanel panel;
  14. private JTextField idField, fnField, lnField, phoneField, addField, cityField, stateField, zipField,
  15. sexField, ageField, hourlyField, hoursField;
  16. private JButton saveButton, cancelButton;
  17. private int id, age;
  18. private String fn=null, ln=null, phone=null, add=null, city=null, state=null, zip=null, sex=null;
  19. private double hourly, hours;
  20.  
  21. public AddRecord(JFrame frame)
  22. {
  23. this.frame = frame;
  24. GridLayout gl = new GridLayout(13,2);
  25. panel = new JPanel();
  26. panel.setBackground(java.awt.Color.white);
  27. panel.setOpaque(false);
  28. panel.setLayout(gl);
  29. panel.setSize(500, 500);
  30.  
  31. /////////// the labels and fields //////////////
  32. panel.add(new Label("Employee Serial #:"));
  33. idField = new JTextField();
  34. panel.add(idField);
  35. panel.add(new Label("First Name:"));
  36. fnField = new JTextField();
  37. panel.add(fnField);
  38. panel.add(new Label("Last Name:"));
  39. lnField = new JTextField();
  40. panel.add(lnField);
  41. panel.add(new Label("Telephone:"));
  42. phoneField = new JTextField();
  43. panel.add(phoneField);
  44. panel.add(new Label("Address:"));
  45. addField = new JTextField();
  46. panel.add(addField);
  47. panel.add(new Label("City:"));
  48. cityField = new JTextField();
  49. panel.add(cityField);
  50. panel.add(new Label("State:"));
  51. stateField = new JTextField();
  52. panel.add(stateField);
  53. panel.add(new Label("Zip Code:"));
  54. zipField = new JTextField();
  55. panel.add(zipField);
  56. panel.add(new Label("Sex:"));
  57. sexField = new JTextField();
  58. panel.add(sexField);
  59. panel.add(new Label("Age:"));
  60. ageField = new JTextField();
  61. panel.add(ageField);
  62. panel.add(new Label("Hourly Rate:"));
  63. hourlyField = new JTextField();
  64. panel.add(hourlyField);
  65. panel.add(new Label("Hours per week:"));
  66. hoursField = new JTextField();
  67. panel.add(hoursField);
  68.  
  69. ////////////// the Labels and Fields ////////////////////
  70.  
  71. saveButton = new JButton("Save");
  72. saveButton.addActionListener(this);
  73. panel.add(saveButton);
  74.  
  75. cancelButton = new JButton("Cancel");
  76. cancelButton.addActionListener(this);
  77. panel.add(cancelButton);
  78. //panel.setOpaque(false);
  79.  
  80. }// end AddRecord Constructor
  81.  
  82.  
  83.  
  84.  
  85. public void actionPerformed(ActionEvent e)
  86. {
  87. boolean status= true;
  88. frame.getContentPane().remove(1);
  89. frame.add(panel);
  90. frame.setBounds(400, 400, 500, 300);
  91. frame.setVisible(true);
  92. frame.repaint();
  93.  
  94. //////////////////// another action perform ////////////////////
  95.  
  96. if(e.getSource() == saveButton)
  97. {
  98. if(idField.getText().equals(""))
  99. {
  100. JOptionPane.showMessageDialog(null, "Employee ID must be entered!");
  101. status=false;
  102. }
  103.  
  104. else
  105. {
  106.  
  107. id = new Integer(idField.getText());
  108. fn = fnField.getText();
  109. ln = lnField.getText();
  110. phone = phoneField.getText();
  111. add = addField.getText();
  112. city= cityField.getText();
  113. state = stateField.getText();
  114. zip = zipField.getText();
  115. sex = sexField.getText();
  116.  
  117.  
  118. if(ageField.getText().equals(""))
  119. {
  120. age=0;
  121. }
  122.  
  123. else
  124. {
  125. age = new Integer(ageField.getText());
  126. }
  127.  
  128. if(hourlyField.getText().equals(""))
  129. {
  130. hourly= 0;
  131. }
  132.  
  133. else
  134. {
  135. hourly = new Double(hourlyField.getText());
  136. }
  137.  
  138. if(hoursField.getText().equals(""))
  139. {
  140. hours=0;
  141. }
  142.  
  143. else
  144. {
  145. hours = new Double(hoursField.getText());
  146. }
  147. }// end idField has something
  148.  
  149.  
  150. //fieldReset();
  151. idField.setText("");
  152. fnField.setText("");
  153. lnField.setText("");
  154. phoneField.setText("");
  155. addField.setText("");
  156. cityField.setText("");
  157. stateField.setText("");
  158. zipField.setText("");
  159. sexField.setText("");
  160. ageField.setText("");
  161. hourlyField.setText("");
  162. hoursField.setText("");
  163. idField.requestFocus();
  164.  
  165. if(status == true)
  166. {
  167. dh.addRecord(id, fn, ln, phone, add, city, state, zip, age, sex, hourly, hours);
  168. JOptionPane.showMessageDialog(null, "The new record has been saved!");
  169. }
  170. }// ENN SAVE BUTTON
  171.  
  172.  
  173. else if(e.getSource()== cancelButton)
  174. {
  175. frame.remove(panel);
  176. }
  177.  
  178. /////////////// end of another action perform /////////////////////
  179.  
  180.  
  181. } // end ActionPerformed method
  182.  
  183. }// end class
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Apr 15th, 2009
0

Re: drop down menu question

I haven't found out the cause of your problem. . I did look through your code, and there are certainly some things I thought should be changed (minor issues).

1. Why are you adding things explicitly to the JFrame, instead of putting them in a panel, then adding the panel to the JFrame? (I'm referring to the text that shows up when you first start the program). I'm not positive that this is bad practice, but I would do it with a panel.
2. I also think the reason the menu isn't showing up might be that you are adding your items directly to the frame, rather than to a panel. Add a panel to the frame, then add everything else to that panel. . so your AddRecord would be in the panel.

You'd have

JFrame
|
PanelWDesiredLayout
|
AddRecordPanel
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 15th, 2009
0

Re: drop down menu question

huh, that is what it is though. i have a JMenuBar directly added to the JFrame, and then everything else is added to the JPanel or JScrollPane, then add the JPanel or JScrollPane to the Frame.
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Apr 16th, 2009
0

Re: drop down menu question

I just quickly glanced through the code, so perhaps I missed something, but it looks like you've added a JMenuBar to a JPanel and added that to your JFrame. I would recommend using setJMenuBar() method on JFrame to add the menu to the frame.
Last edited by Ezzaral; Apr 16th, 2009 at 12:09 am.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,754 posts
since May 2007
Apr 16th, 2009
0

Re: drop down menu question

^ I tried that when I edited his code, it didn't change anything (as far as the problem he mentioned). Good catch though, I forgot to add that to my comments.

edit:

And k2k, I'm not sure if it matters or not, but you didn't add everything to panels. You added your two labels directly to the frame. If I were you though, I would try out some different layout managers. Like I said, I think CardLayout would be a good idea considering you're flipping through different same-sized windows.
Last edited by BestJewSinceJC; Apr 16th, 2009 at 3:14 am.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 16th, 2009
2

Re: drop down menu question

Ok, I had a few minutes to play with the code. The main problem is that you are using java.awt.Label instead of javax.swing.JLabel for the labels in AddRecord. It' not a good idea to mix heavyweight AWT components with Swing components in the same UI. That was causing the problems with painting your menu properly.

Here's some revised code that behaves properly. Note that I put some of the separate classes inside "TheFrame" as inner classes just for my own convenience. You can certainly move them back out.
java Syntax (Toggle Plain Text)
  1. ////// main , the frame ///////
  2. import java.text.MessageFormat;
  3. import java.sql.*;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.awt.print.*;
  8.  
  9. public class TheFrame extends JFrame
  10. {
  11. private JPanel menuPanel;
  12. private JPanel text;
  13. private BorderLayout bl = new BorderLayout();
  14.  
  15.  
  16. public TheFrame()
  17. {
  18.  
  19. JLabel one = new JLabel("Java Final Project: Employee Record");
  20. one.setAlignmentX(0.5f);
  21. one.setAlignmentY(1f);
  22. JLabel two = new JLabel("Written by Henry Li");
  23. two.setAlignmentX(0.5f);
  24. two.setAlignmentY(1f);
  25.  
  26. text = new JPanel();
  27. text.setBackground(java.awt.Color.white);
  28. LayoutManager boxLayout = new BoxLayout(text, BoxLayout.Y_AXIS);
  29.  
  30. text.setLayout(boxLayout);
  31. text.add(one);
  32. text.add(two);
  33.  
  34. // add the menu
  35. createMenu();
  36. // set close op also
  37. setDefaultCloseOperation(EXIT_ON_CLOSE);
  38. // don't need
  39. // add(menuPanel, BorderLayout.NORTH);
  40. getContentPane().add(text, BorderLayout.CENTER);
  41. validate();
  42.  
  43. setBounds(400, 400, 600, 300);
  44. setVisible(true);
  45.  
  46. }
  47.  
  48. // Moved everything from menu panel here
  49. private void createMenu(){
  50. JMenuBar menuBar;
  51. JMenu menuFile, menuEdit;
  52. JMenuItem closeMenuItem, printMenuItem, showTableMItem, addRecordMItem;
  53.  
  54. menuFile = new JMenu("File"); // menu file
  55. menuFile.setForeground(java.awt.Color.black);
  56. closeMenuItem = new JMenuItem("Close"); // menu closeItem
  57. menuFile.add(closeMenuItem); // menu file with closeItem
  58. closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
  59. closeMenuItem.addActionListener(new closeMenuHandler());
  60.  
  61.  
  62. printMenuItem = new JMenuItem("Print"); // menu printItem
  63. menuFile.add(printMenuItem); // menu file with printItem
  64. printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', java.awt.Event.CTRL_MASK, false));
  65. ////////////// ActionListener /////////////
  66.  
  67.  
  68.  
  69. //*****************************************************************************
  70. //////////// Menu Bar Edit items /////////////////
  71. menuEdit= new JMenu("Edit"); // menu edit
  72. showTableMItem = new JMenuItem("Show Table"); // showTable item
  73. menuEdit.add(showTableMItem); // menu edit with showTable item
  74. // I didn't have this class - you'll want to re-enable this I imagine
  75. // showTableMItem.addActionListener(new ShowTable(frame));
  76.  
  77. //*****************************************************************************
  78.  
  79.  
  80. addRecordMItem = new JMenuItem("Add Record"); // addRecord item
  81. menuEdit.add(addRecordMItem); // edit menu with addRecord item
  82. addRecordMItem.addActionListener(new AddRecord(this));
  83. ///////////////////////////////////////
  84.  
  85. //////// Add all menu things to the menu bar /////////
  86. menuBar = new JMenuBar(); // menu bar
  87. menuBar.setBackground(java.awt.Color.white);
  88. menuBar.add(menuFile); // menu bar with menu file
  89. menuBar.add(menuEdit); // menu bar with menu edit
  90.  
  91. // set this as the frame's menu
  92. setJMenuBar(menuBar);
  93. }
  94.  
  95.  
  96.  
  97. public static void main(String arg[]) throws SQLException
  98. {
  99. TheFrame frame = new TheFrame();
  100. }
  101.  
  102.  
  103. }// end the Class TheFrame
  104.  
  105. // removed this entirely
  106. class MenuBar extends JPanel {}
  107.  
  108. class closeMenuHandler implements ActionListener
  109. {
  110. public void actionPerformed(ActionEvent ae)
  111. {
  112. System.exit(0);
  113.  
  114. }
  115. }
  116.  
  117. /// and the Jpanel class which blocks my dropped down//
  118. class AddRecord implements ActionListener
  119. {
  120. // didn't have this class
  121. // DataHolder is another sql class to get all the data from mdb file
  122. // private DataHolder dh = new DataHolder();
  123. private JFrame frame;
  124. private JPanel panel;
  125. private JTextField idField, fnField, lnField, phoneField, addField, cityField, stateField, zipField,
  126. sexField, ageField, hourlyField, hoursField;
  127. private JButton saveButton, cancelButton;
  128. private int id, age;
  129. private String fn=null, ln=null, phone=null, add=null, city=null, state=null, zip=null, sex=null;
  130. private double hourly, hours;
  131.  
  132. public AddRecord(JFrame frame)
  133. {
  134. this.frame = frame;
  135. GridLayout gl = new GridLayout(13,2);
  136. panel = new JPanel();
  137. panel.setBackground(java.awt.Color.white);
  138. // panel.setOpaque(false); // no need
  139. panel.setLayout(gl);
  140. panel.setSize(500, 500);
  141.  
  142. /////////// the labels and fields //////////////
  143.  
  144. // NOTE THE JLabel CHANGE
  145. panel.add(new JLabel("Employee Serial #:"));
  146. idField = new JTextField();
  147. panel.add(idField);
  148. panel.add(new JLabel("First Name:"));
  149. fnField = new JTextField();
  150. panel.add(fnField);
  151. panel.add(new JLabel("Last Name:"));
  152. lnField = new JTextField();
  153. panel.add(lnField);
  154. panel.add(new JLabel("Telephone:"));
  155. phoneField = new JTextField();
  156. panel.add(phoneField);
  157. panel.add(new JLabel("Address:"));
  158. addField = new JTextField();
  159. panel.add(addField);
  160. panel.add(new JLabel("City:"));
  161. cityField = new JTextField();
  162. panel.add(cityField);
  163. panel.add(new JLabel("State:"));
  164. stateField = new JTextField();
  165. panel.add(stateField);
  166. panel.add(new JLabel("Zip Code:"));
  167. zipField = new JTextField();
  168. panel.add(zipField);
  169. panel.add(new JLabel("Sex:"));
  170. sexField = new JTextField();
  171. panel.add(sexField);
  172. panel.add(new JLabel("Age:"));
  173. ageField = new JTextField();
  174. panel.add(ageField);
  175. panel.add(new JLabel("Hourly Rate:"));
  176. hourlyField = new JTextField();
  177. panel.add(hourlyField);
  178. panel.add(new JLabel("Hours per week:"));
  179. hoursField = new JTextField();
  180. panel.add(hoursField);
  181.  
  182. ////////////// the Labels and Fields ////////////////////
  183.  
  184. saveButton = new JButton("Save");
  185. saveButton.addActionListener(this);
  186. panel.add(saveButton);
  187.  
  188. cancelButton = new JButton("Cancel");
  189. cancelButton.addActionListener(this);
  190. panel.add(cancelButton);
  191. //panel.setOpaque(false);
  192.  
  193. }// end AddRecord Constructor
  194.  
  195.  
  196.  
  197.  
  198. public void actionPerformed(ActionEvent e)
  199. {
  200. boolean status= true;
  201. // add components to content pane
  202. frame.getContentPane().removeAll();
  203. frame.getContentPane().add(panel);
  204. frame.setBounds(400, 400, 500, 300);
  205. frame.pack();
  206. frame.repaint();
  207.  
  208. //////////////////// another action perform ////////////////////
  209.  
  210. if(e.getSource() == saveButton)
  211. {
  212. if(idField.getText().equals(""))
  213. {
  214. JOptionPane.showMessageDialog(null, "Employee ID must be entered!");
  215. status=false;
  216. }
  217.  
  218. else
  219. {
  220.  
  221. id = new Integer(idField.getText());
  222. fn = fnField.getText();
  223. ln = lnField.getText();
  224. phone = phoneField.getText();
  225. add = addField.getText();
  226. city= cityField.getText();
  227. state = stateField.getText();
  228. zip = zipField.getText();
  229. sex = sexField.getText();
  230.  
  231.  
  232. if(ageField.getText().equals(""))
  233. {
  234. age=0;
  235. }
  236.  
  237. else
  238. {
  239. age = new Integer(ageField.getText());
  240. }
  241.  
  242. if(hourlyField.getText().equals(""))
  243. {
  244. hourly= 0;
  245. }
  246.  
  247. else
  248. {
  249. hourly = new Double(hourlyField.getText());
  250. }
  251.  
  252. if(hoursField.getText().equals(""))
  253. {
  254. hours=0;
  255. }
  256.  
  257. else
  258. {
  259. hours = new Double(hoursField.getText());
  260. }
  261. }// end idField has something
  262.  
  263.  
  264. //fieldReset();
  265. idField.setText("");
  266. fnField.setText("");
  267. lnField.setText("");
  268. phoneField.setText("");
  269. addField.setText("");
  270. cityField.setText("");
  271. stateField.setText("");
  272. zipField.setText("");
  273. sexField.setText("");
  274. ageField.setText("");
  275. hourlyField.setText("");
  276. hoursField.setText("");
  277. idField.requestFocus();
  278.  
  279. if(status == true)
  280. {
  281. // dh.addRecord(id, fn, ln, phone, add, city, state, zip, age, sex, hourly, hours);
  282. JOptionPane.showMessageDialog(null, "The new record has been saved!");
  283. }
  284. }// ENN SAVE BUTTON
  285.  
  286.  
  287. else if(e.getSource()== cancelButton)
  288. {
  289. frame.remove(panel);
  290. }
  291.  
  292. /////////////// end of another action perform /////////////////////
  293.  
  294.  
  295. } // end ActionPerformed method
  296.  
  297. }// end class
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,754 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Trouble with a code about Date
Next Thread in Java Forum Timeline: JAVA





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


Follow us on Twitter


© 2011 DaniWeb® LLC