import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Patient extends JFrame implements ActionListener
{
public static void main(String [] args)
{
new Patient();
}
JTextField pName, doBirth, hAddress,hospital,diagnosis;
JComboBox sex;
JRadioButton medical, dentistry, optical,oPatient,admitted;
JCheckBox died, discharged;
JButton Apply, clearButton, exitButton;
String[] theBox= {"male","female"};
public Patient()
{
this.setTitle("PATIENT REGISTRATION FORM");
this.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel();
panel1.setLayout(new GridBagLayout());
addItem(panel1, new JLabel("FULL NAME OF PATIENT:"),
0, 0, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel("DATE OF BIRTH:"),
0, 1, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel("HOME ADDRESS ( Vge / TA / District):"),
0, 2, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel("SEX:"),
0, 3, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel("HOSPITAL:"),
0, 4, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel("DIAGNOSIS:"),
0, 5, 1, 1, GridBagConstraints.EAST);
pName = new JTextField(20);
doBirth = new JTextField(20);
hAddress = new JTextField(20);
sex = new JComboBox(theBox);
hospital = new JTextField(20);
diagnosis= new JTextField(20);
addItem(panel1, pName, 1, 0, 2, 1,
GridBagConstraints.WEST);
addItem(panel1, doBirth, 1, 1, 1, 1,
GridBagConstraints.WEST);
addItem(panel1, hAddress, 1, 2, 2, 1,
GridBagConstraints.WEST);
addItem(panel1, sex, 1, 3, 2, 1,
GridBagConstraints.WEST);
addItem(panel1,hospital, 1,4,2,1,
GridBagConstraints.WEST);
addItem(panel1, diagnosis, 1,5,2,1,
GridBagConstraints.WEST);
Box sizeBox = Box.createVerticalBox();
medical = new JRadioButton("medical");
dentistry = new JRadioButton("dentistry");
optical = new JRadioButton("optical");
ButtonGroup sizeGroup = new ButtonGroup();
sizeGroup.add(medical);
sizeGroup.add(dentistry);
sizeGroup.add(optical);
sizeBox.add(medical);
sizeBox.add(dentistry);
sizeBox.add(optical);
sizeBox.setBorder(
BorderFactory.createTitledBorder("TREATMENT"));
addItem(panel1, sizeBox, 0,6, 1, 1,
GridBagConstraints.NORTH);
Box styleBox = Box.createVerticalBox();
oPatient = new JRadioButton("Out Patient");
admitted = new JRadioButton("Admitted");
ButtonGroup styleGroup = new ButtonGroup();
styleGroup.add(oPatient);
styleGroup.add(admitted);
styleBox.add(oPatient);
styleBox.add(admitted);
styleBox.setBorder(BorderFactory.
createTitledBorder("RHESUS FACTOR"));
addItem(panel1, styleBox, 1,6, 1, 1,
GridBagConstraints.NORTH);
Box topBox = Box.createVerticalBox();
discharged = new JCheckBox("yes");
died = new JCheckBox("no");
ButtonGroup topGroup = new ButtonGroup();
topGroup.add(discharged);
topGroup.add(died);
topBox.add(discharged);
topBox.add(died);
topBox.setBorder(BorderFactory.
createTitledBorder("APPOINTMENT"));
addItem(panel1, topBox, 2, 6, 1, 1,
GridBagConstraints.NORTH);
Box buttonBox = Box.createHorizontalBox();
Apply = new JButton("Apply");
clearButton = new JButton("Clear");
exitButton = new JButton("Exit");
buttonBox.add(Apply);
buttonBox.add(Box.createHorizontalStrut(25));
buttonBox.add(clearButton);
clearButton.addActionListener(this);
buttonBox.add(Box.createHorizontalStrut(25));
buttonBox.add(exitButton);
exitButton.addActionListener(this);
addItem(panel1, buttonBox, 0, 7, 3, 1, GridBagConstraints.CENTER);
pName.setText(" ");
doBirth.setText(" ");
hAddress.setText(" ");
hospital.setText(" ");
diagnosis.setText(" ");
oPatient.setText("positive ");
oPatient.setSelected(true);
admitted.setText("negative ");
admitted.setSelected(true);
medical.setText("medical");
medical.setSelected(true);
dentistry.setText("dentistry");
dentistry.setSelected(true);
optical.setText("optical");
optical.setSelected(true);
discharged.setText("yes ");
discharged.setSelected(true);
died.setText("no ");
died.setSelected(true);
Apply.setText("Apply");
Apply.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JTextArea textarea=new JTextArea();
JScrollPane scroll=new JScrollPane( textarea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JFrame frame= new JFrame();
if (e.getSource()==Apply){
String name= pName.getText();
textarea.append("\n\n");
textarea.append(" FULL NAME OF PATIENT: "+name+"\n\n");
String name1= doBirth.getText();
textarea.append(" DATE OF BIRTH: "+name1+"\n\n");
String name3 = hAddress.getText();
textarea.append(" HOME ADDRESS (Vge / TA / District): "+ name3+"\n\n");
String enteredText = (String)sex.getSelectedItem();
textarea.append(" SEX: "+enteredText+"\n\n");
String name4=hospital.getText();
textarea.append(" HOSPITAL: "+name4+"\n\n");
String name5=diagnosis.getText();
textarea.append(" DIAGNOSIS: "+name5+"\n\n");
if (oPatient.isSelected())
textarea.append(" RHESUS FACTOR: positive\n\n");
if (admitted.isSelected())
textarea.append(" RHESUS FACTOR: negative\n\n");
if (medical.isSelected())
textarea.append(" TREATMENT: Medical\n\n");
if (dentistry.isSelected())
textarea.append(" TREATMENT: Dentistry\n\n");
if (optical.isSelected())
textarea.append(" TREATMENT: Optical\n\n");
if (discharged.isSelected())
textarea.append(" APPOINTMENT: Yes\n\n");
if (died.isSelected())
textarea.append(" APPOINTMENT: No\n\n");
textarea.setEditable(false);
}
frame.add(scroll);
frame.setTitle(" DETAILS OF REGISTERED PATIENT");
frame.setSize(500,500);
frame.setLocation(350,50);
frame.setVisible(true);
}
});
this.add(panel1);
this.pack();
this.setVisible(true);
}
public void actionPerformed(ActionEvent evnt){
if(evnt.getSource()==exitButton){
System.exit(0);
}
else if (evnt.getSource()==clearButton){
cancel1();
}
}
public void cancel1() {
pName.setText("");
}
private void addItem(JPanel p, JComponent c,
int x, int y, int width, int height,
int align)
{
GridBagConstraints gc =
new GridBagConstraints();
gc.gridx = x;
gc.gridy = y;
gc.gridwidth = width;
gc.gridheight = height;
gc.weightx = 100.0;
gc.weighty = 100.0;
gc.insets = new Insets(20, 20, 20, 20);
gc.anchor = align;
gc.fill = GridBagConstraints.NONE;
p.add(c, gc);
}
}
No comments:
Post a Comment