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 ,,,,,

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax .swing.*;
    import java.io.*;
    
    
    
    public class SavePatient extends JFrame implements ActionListener
    {			 
    	private JLabel Name,MRN,Address,Age,Admission,Wardname,Wardnumber;
    	private JTextField name,mrn,address,age,admission,wardname,wardnumber;
    	private JButton Save;
    
    
    	public static void main(String args[])
    	{
    		FindPatient app = new FindPatient();
    	}
    
    	public SavePatient() //constructor
    	{
    	
    		super("Event Handling");
    		
       	Container c = getContentPane();
    		c.setLayout(new FlowLayout());
    		
    
    		Name = new JLabel("Patient Name");
    		c.add(Name);
    		
    		name = new JTextField(20);
    		c.add(name);
    		
    		Save = new JButton("Save");
    		Save.addActionListener(this);
    		c.add(Save);
    		
    		MRN = new JLabel("MRN");
    		c.add(MRN);
    		
    		mrn = new JTextField(20);
    		c.add(mrn);
    
    		Address = new JLabel("Address ");
    		c.add(Address);
    		
    		address = new JTextField(20);
    		c.add(address);
    		
    		Age = new JLabel("Age ");
    		c.add(Age);
    		
    		age = new JTextField(20);
    		c.add(age);
    
    
    		Admission = new JLabel("Admission ");
    		c.add(Admission);
    
    		admission = new JTextField(20);
    		c.add(admission);
    		
    		Wardname = new JLabel("Ward Name ");
    		c.add(Wardname);
    
    		wardname = new JTextField(20);
    		c.add(wardname);
    		
    		Wardnumber = new JLabel("Ward Number ");
    		c.add(Wardnumber);
    
    		wardnumber = new JTextField(20);
    		c.add(wardnumber);
    	
    		setSize(400, 300);
    		setVisible(true);
    		}
    
    	public void actionPerformed(ActionEvent e)
    	{
    		Save();
    	}
    	
    	public void Save()
    	{	
    												
    		try 	{
    			
    				BufferedWriter a = new BufferedWriter(new FileWriter("patient.txt",true  ));
    				a.write(name.getText()+ "!" + mrn.getText() + "!" + address.getText() + "!"+ age.getText() + "!" + admission.getText() + "!" + wardname.getText() + "!" + wardnumber.getText() + System.getProperty("line.separator"));
    				a.close();
    				
    				
    		
    				JOptionPane.showMessageDialog(this,"Successfully Saved");
    			   a.close();		 
    			}
    				
    			catch(Exception e)
    			{
    				JOptionPane.showMessageDialog(this,"Can't Open File");
    			}	
    	}
    	}

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

    Default

    Java Code:
    public class SavePatient extends JFrame implements ActionListener
    {
        public static void main(String args[])
        {
            // Looks like you are calling another class here.
            FindPatient app = new FindPatient();
            // What would this do instead?
            new SavePatient();
        }

  3. #3
    twinytwo is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    Nice one.... i changed the name of the class and never changed the main method... thanks very much:o

  4. #4
    Lindawool is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2009, 04:15 AM
  2. Disable Save button - Acrobar Reader
    By Deepa in forum New To Java
    Replies: 1
    Last Post: 03-06-2009, 12:15 PM
  3. Replies: 10
    Last Post: 12-30-2008, 03:46 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
  •