Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Callin class from J button Click

$
0
0
See code below for JBUTTON addpatient. The code below the button code is for a class i created to display the addpatient GUI. WHat code do I need to add to addnew button to get the addpatient form to fire up.
//Add New Patient Button
                JButton addNew = new JButton("Add Patient");
                editandSearchOptionsPanel.add( addNew );
                addNew.addActionListener( new ActionListener()
                {
                	public void actionPerformed(ActionEvent add) 
                    {
                      // JOptionPane.showMessageDialog(null, "Adding New Patient") ;
                        frame.validate();
                       // addPatientgui addPatient = new addPatientgui();
                 }

------------------------------------------------------
 public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
    	
    	
    	//Set look and feel to NImbus.
    	
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (Exception  UnsupportedLookAndFeelException) {
		    // If Nimbus is not available
			UIManager.getSystemLookAndFeelClassName();
		}
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}


Sorry i did not select all code for addpatientgui. See full class now.
 
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Container;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.TextArea;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
 
public class addPatientgui {
    public static void addComponentsToPane(Container pane) {
        pane.setLayout(null);
 
        //JFrame addPatientgui = new JFrame("Pats details"); 
        //addPatientgui.setBorder( new TitledBorder("Enter new patient details") );
       // addPatientgui.setSize(1024,768);
        JLabel lmain,lpi,lname,ladd,ltel,lbloodGrp,ldob,lgender,lhis,lppsno,lcur,lwork,lworkfrom,lworkto,lfee;
    	JTextField patientNameField, adressField,tfname,PatientNoField,ppsField,dobfield,tfworkf,tfworkt,tffee;
    	TextArea taadd,tacur,hisField;
    	JButton addBut,clearBut;
    	Choice chbg;
    	CheckboxGroup cbmf;
    	Checkbox cbm,cbf;
        
       lmain = new JLabel("Patient Details");
    	lmain.setBounds(440,35,107,15);
    	pane.add(lmain);   
        
    	

    	lpi=new JLabel("Patient Information");
    	lpi.setBounds(40,70,120,15);
    	pane.add(lpi);

    	lname=new JLabel("Name :");
    	lname.setBounds(104,97,70,25);
    	pane.add(lname);

    	
    	patientNameField = new JTextField();
    	//patientNameField.setPreferredSize(new Dimension(70, 50));
    	//patientNameField.setHorizontalAlignment(0);
    	//patientNameField.setMaximumSize( patientNameField.getPreferredSize() );
    	pane.add(patientNameField);
    	patientNameField.setBounds(270,97,100,25);
    	
    	

    	ladd=new JLabel("Address :");
    	ladd.setBounds(104,138,70,15);
    	pane.add(ladd);
    	
    	
    	adressField = new JTextField();
    	pane.add(adressField);
    	adressField.setBounds(270,138,250,100);
    	
        
        
    	ltel=new JLabel("TEL: :");
    	ltel.setBounds(575,138,50,25);
    	pane.add(ltel);

    	lppsno=new JLabel("PPS No.:");
    	lppsno.setBounds(570,97,70,25);
    	pane.add(lppsno);
    	
    	ppsField = new JTextField();
    	pane.add(ppsField);
    	ppsField.setBounds(643,97,250,25);
    	
    	
    	PatientNoField = new JTextField();
    	pane.add(PatientNoField);
    	PatientNoField.setBounds(640,138,150,25);
    	
    	

    	lbloodGrp=new JLabel("Blood Group :");
    	lbloodGrp.setBounds(104,306,79,15);
    	pane.add(lbloodGrp);
    	

    	chbg=new Choice();
    	chbg.setBounds(270,306,53,15);
    	chbg.addItem("A -ve");
    	chbg.addItem("A +ve");
    	chbg.addItem("B -ve");
    	chbg.addItem("B +ve");
    	chbg.addItem("AB -ve");
    	chbg.addItem("AB +ve");
    	chbg.addItem("O +ve");
    	chbg.addItem("O -ve");
    	pane.add(chbg);
    	
    	ldob=new JLabel("Date of Birth :");
    	ldob.setBounds(575,306,135,15);
    	pane.add(ldob);

    	dobfield=new JTextField(15);
    	dobfield.setBounds(720,305,80,20);
    	pane.add(dobfield);
    	
    	lgender=new JLabel("Gender :");
    	lgender.setBounds(596,223,50,15);
    	pane.add(lgender);


    	
    	cbmf=new CheckboxGroup();
    	cbm=new Checkbox("Male",cbmf,true);
    	cbf=new Checkbox("Female",cbmf,false);
    	cbm.setBounds(698,223,50,15);
    	pane.add(cbm);
    	cbf.setBounds(760,223,60,15);
    	pane.add(cbf);
    	
    	
    	
    	lhis=new JLabel("History :");
    	lhis.setBounds(104,365,50,15);
    	pane.add(lhis);

    	hisField=new TextArea();
    	hisField.setBounds(270,365,250,100);
    	pane.add(hisField);

    	lcur=new JLabel("Current Problem :");
    	lcur.setBounds(575,365,100,15);
    	pane.add(lcur);
    	
    	tacur=new TextArea();
    	tacur.setBounds(720,365,250,100);
    	pane.add(tacur);
    	
    	clearBut=new JButton("CLEAR");
    	clearBut.setBounds(400,643,100,30);
    	pane.add(clearBut);

    	addBut=new JButton("ADD");
    	addBut.setBounds(600,643,100,30);
    	pane.add(addBut);
       
    }
 
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame addPatientgui = new JFrame("Add Patient Form");
        addPatientgui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        //Set up the content pane.
        addComponentsToPane(addPatientgui.getContentPane());
 
        //Size and display the window.
        
        addPatientgui.setSize(1024,768);
        addPatientgui.setVisible(true);
    }
 
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
    	
    	
    	//Set look and feel to NImbus.
    	
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (Exception  UnsupportedLookAndFeelException) {
		    // If Nimbus is not available
			UIManager.getSystemLookAndFeelClassName();
		}
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

Viewing all articles
Browse latest Browse all 51036

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>