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

    Default Can some one tell me why the save button dosnt work... its wrecking my head

    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 
    			{	
    				File inFile = new File("patients.txt");
    				FileWriter fileWriter = new FileWriter(inFile);
    														
    				BufferedWriter a = new BufferedWriter(fileWriter);
    				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
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default

    where is ur FindPatient class??
    Java Code:
    FindPatient app = new FindPatient();
    change the above line with:

    Java Code:
    SavePatient app = new SavePatient();

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    The question seems to be strange )))
    Only one thing the author should do is modify the main method content from init-ing
    Java Code:
    FindPatient app = new FindPatient();
    to
    Java Code:
    new SavePatient()
    or as tomiu says
    Java Code:
    SavePatient app = new SavePatient();
    Author, can you tell us where is the head wrecking?

Similar Threads

  1. Disable Save button - Acrobar Reader
    By Deepa in forum New To Java
    Replies: 1
    Last Post: 03-06-2009, 12:15 PM
  2. Work & Earn money from home, use rebate lower price save money $$$
    By arturmoniswork in forum Reviews / Advertising
    Replies: 0
    Last Post: 12-30-2008, 05:57 AM
  3. javamail exception: 557 mail head error
    By allanwakes in forum Java Servlet
    Replies: 2
    Last Post: 10-02-2008, 11:05 AM
  4. HEAD first by kathy sierra
    By j2vdk in forum New To Java
    Replies: 0
    Last Post: 08-30-2008, 01:08 PM
  5. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:19 AM

Posting Permissions

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