Results 1 to 4 of 4
Thread: Save button not working
- 03-27-2009, 01:28 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 7
- Rep Power
- 0
Save button not working
I meant to say that the back button was not working
Java Code:import java.awt.*; import java.awt.event.*; import javax .swing.*; import java.io.*; import java.awt.event.ActionEvent; import java.util.StringTokenizer; public class FindPatient extends JFrame implements ActionListener { private JLabel Name,MRN,Address,Age,Admission,Wardname,Wardnumber,Blank1,Blank2,Blank3,Blank4,Blank5;// declares the labels,the blank labels are used for spaces in the layout private JTextField name,mrn,address,age,admission,wardname,wardnumber;//declares the text fields private JButton Search,Back;// declares the buttons public static void main(String args[])//main method { FindPatient app = new FindPatient(); } public FindPatient() //constructor { super("Patient Search");//title of Frame Container c = getContentPane(); c.setLayout(new GridLayout(11,2,0,0));//set the layout manager to grid and set the number of rows and columns in the grid Name = new JLabel("Patient Name");// set the text property of the label c.add(Name);//add the label to the container name = new JTextField(20); c.add(name);//add the textfield to the container Blank3 = new JLabel(" "); c.add(Blank3);//add the label to the container Search = new JButton("Search"); Search.addActionListener(this); c.add(Search); Blank4 = new JLabel(" "); c.add(Blank4);//add the label to the container Blank5 = new JLabel(" "); c.add(Blank5);//add the label to the container MRN = new JLabel("MRN"); c.add(MRN);//add the label to the container mrn = new JTextField(20); c.add(mrn);//add the textfield to the container Address = new JLabel("Address "); c.add(Address);//add the label to the container address = new JTextField(20); c.add(address);//add the textfield to the container Age = new JLabel("Age "); c.add(Age);//add the label to the container age = new JTextField(20); c.add(age); Admission = new JLabel("Admission "); c.add(Admission);//add the label to the container admission = new JTextField(20); c.add(admission); Wardname = new JLabel("Ward Name "); c.add(Wardname);//add the label to the container wardname = new JTextField(20); c.add(wardname); Wardnumber = new JLabel("Ward Number "); c.add(Wardnumber);//add the label to the container wardnumber = new JTextField(20); c.add(wardnumber); Blank1 = new JLabel(" "); c.add(Blank1);//add the label to the container Blank2 = new JLabel(" "); c.add(Blank2); //add the label to the container Back = new JButton("Back"); Search.addActionListener(this); c.add(Back); setSize(400, 300);//set the size of the frame setVisible(true);//set the frame to visible } public void Search_actionPerformed(ActionEvent e) { Find();// call the find method } public void Back_actionPerformed(ActionEvent e) { Menu Menu = new Menu(); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==Search) { Search_actionPerformed(ae); } else { Back_actionPerformed(ae); } } public void Find()//find method { try{ BufferedReader d = new BufferedReader(new FileReader("patient.txt"));// open and read for the text file "patient.txt" String str =""; while((str = d.readLine())!=null) { StringTokenizer stz = new StringTokenizer(str,"/"); if(stz.nextToken().equals(name.getText())) { mrn.setText((String)stz.nextToken()); address.setText((String)stz.nextToken()); age.setText((String)stz.nextToken()); admission.setText((String)stz.nextToken()); wardname.setText((String)stz.nextToken()); wardnumber.setText((String)stz.nextToken()); } } } catch(Exception u) { JOptionPane.showMessageDialog(this,"Can't Open File"); } } }
-
Please define what "not working" and "working" mean.
I see that pressing the back button seems to create a new "Menu" object. What is this Menu object, and how will creating a new one do anything for your GUI?
- 03-27-2009, 05:51 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And your tittle misleading too. Anyway, specifically ask your question please rather posting a long code.
- 03-28-2009, 12:05 AM #4
Java Code:// Instantiate the Back button Back = new JButton("Back"); // and add the ActionListener to the Search button. // But wait, you already added the listener to the // Search button above - just after you instantiated // it. So this next line is not needed. Search.addActionListener(this); // Instead, this would be a good place to add the // listener to the Back button: // Back.addActionListener(this); c.add(Back); ... public void Back_actionPerformed(ActionEvent e) { Menu Menu = new Menu(); // This method is never called because the ActionListener // which calls this method was not added to the Back button. // If you add the listener and this method does get called // it doesn't do anything anyway. You could put a println // statement in here to see if the button-listener-method // sequence fires, eg, System.out.println("Back_actionPerformed"); }
Similar Threads
-
Can some one tell me why the save button dosnt work... its wrecking my head
By twinytwo in forum New To JavaReplies: 2Last Post: 03-26-2009, 04:15 AM -
Save button not working ,,,,,
By twinytwo in forum AWT / SwingReplies: 3Last Post: 03-25-2009, 08:22 PM -
Disable Save button - Acrobar Reader
By Deepa in forum New To JavaReplies: 1Last Post: 03-06-2009, 12:15 PM -
[SOLVED] Disabling a button not working
By Leprechaun in forum New To JavaReplies: 2Last Post: 04-24-2008, 04:46 AM -
Applet button not working
By letmeoutofhere in forum Java AppletsReplies: 9Last Post: 11-14-2007, 12:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks