Results 1 to 4 of 4
  1. #1
    twinytwo is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    And your tittle misleading too. Anyway, specifically ask your question please rather posting a long code.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    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

  1. Replies: 2
    Last Post: 03-26-2009, 04:15 AM
  2. Save button not working ,,,,,
    By twinytwo in forum AWT / Swing
    Replies: 3
    Last Post: 03-25-2009, 08:22 PM
  3. Disable Save button - Acrobar Reader
    By Deepa in forum New To Java
    Replies: 1
    Last Post: 03-06-2009, 12:15 PM
  4. [SOLVED] Disabling a button not working
    By Leprechaun in forum New To Java
    Replies: 2
    Last Post: 04-24-2008, 04:46 AM
  5. Applet button not working
    By letmeoutofhere in forum Java Applets
    Replies: 9
    Last Post: 11-14-2007, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •