package studentform;
import java.awt.*; import java.awt.event.*;
public class StudentForm extends Frame {
private Label l1,l2,l3,l4,l5,l6,l7; private TextField tfid,tfname,tfa; private TextArea out;
private Checkbox ch1,ch2; private Choice cb1,cb2; private Button bi,be;
public void initForm(){
setSize(400,400); setVisible(true); setLayout(null);
setLocationRelativeTo(null); closeForm();
}
public void closeForm(){addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
public void initControls()
{
l1 =new Label("Student Form"); l1.setBounds(150, 40, 100, 20); add(l1);
l2=new Label("ID:"); l2.setBounds(100, 60, 40, 20); add(l2);
tfid=new TextField(); tfid.setBounds(150, 60, 100, 20); add(tfid);
bi=new Button("Insert"); bi.setBounds(280, 60, 60, 20); add(bi);
l3=new Label("Name"); l3.setBounds(100,80, 40, 20); add(l3);
tfname=new TextField(); tfname.setBounds(150, 85, 100, 20); add(tfname);
be=new Button("Exit"); be.setBounds(280, 85, 60, 20); add(be);
l4=new Label("Gender"); l4.setBounds(100, 105, 40, 20); add(l4);
CheckboxGroup g =new CheckboxGroup();
ch1=new Checkbox("Male",g,false); ch2=new Checkbox("Female",g,false);
ch1.setBounds(150, 105, 60,20); ch2.setBounds(200, 105, 60,20);
add(ch1); add(ch2);
l5=new Label("Year"); l5.setBounds(100, 125, 40,20); add(l5);
cb1=new Choice(); cb1.addItem("one"); cb1.addItem("two");
cb1.addItem("three"); cb1.addItem("four");
cb1.setBounds(150, 125, 100, 20); add(cb1);
l5=new Label("Group"); l5.setBounds(100, 145, 40,20); add(l5);
cb2=new Choice(); cb2.addItem("A1"); cb2.addItem("A2");
cb2.addItem("M1"); cb2.addItem("E1"); cb2.addItem("M2");
cb2.setBounds(150, 145, 100, 20); add(cb2);
l7=new Label("Amount"); l7.setBounds(100, 170, 40, 20); add(l7);
tfa=new TextField(); tfa.setBounds(150, 170, 100, 20); add(tfa);
out=new TextArea(); out.setBounds(50, 200, 300, 180); add(out);
}
public void myevent(){
be.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
bi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String id=tfid.getText(); String name=tfname.getText();
String g=cb1.getSelectedItem(); String y=cb2.getSelectedItem();
String gender=""; String amount=tfa.getText();
if (ch1.getState()) gender="Male"; if (ch2.getState()) gender="Female";
String data=id+" "+name+" "+gender+" "+y+" "+g+" "+"\n";
out.append(data);
}
});
}
public StudentForm(){
initForm(); initControls(); myevent();
}
public static void main(String[] args) {
new StudentForm();
}
}
No comments:
Post a Comment