Write a java program with Textbox, Label, Button for displaying the information of a student like name, department etc.
import java.awt.*;
import java.awt.event.*; class Myapplication extends Frame implements ActionListener { TextField t1; TextField t2; Choice cb; Checkbox cb1,cb2; Checkbox b,i; TextArea ta; Button s,c; Myapplication() { setLayout(new FlowLayout()); Label sno; sno = new Label("Student Number : "); t1 = new TextField(5); Label sname; sname = new Label("Student Name : "); t2 = new TextField(10); Label course; course = new Label("Course : "); cb = new Choice(); cb.add("MCA"); cb.add("MBA"); cb.add("BioTech"); cb.add("M.A"); CheckboxGroup cg; cg = new CheckboxGroup(); Label gender; gender = new Label("Gender"); cb1 = new Checkbox("Male" , cg ,true); cb2 = new Checkbox("Female",cg,false); Label df; df = new Label("Data Format"); b = new Checkbox("BOLD",true); i = new Checkbox("ITALIC",false); Label op; op = new Label("OutPut"); ta = new TextArea(4,25); s = new Button("Submit"); c = new Button("Cancel"); add(sno); add(t1); add(sname); add(t2); add(course); add(cb); add(gender); add(cb1); add(cb2); add(df); add(b); add(i); add(op); add(ta); add(s); add(c); s.addActionListener(this); c.addActionListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } } ); } public void actionPerformed(ActionEvent ae) { String s ; Font fo=null; s = ae.getActionCommand(); if (s.equals("Submit" ) ) { String str = "STUDENT NO :: " + t1.getText(); str = str+"\n"+"STUDENT NAME : " + t2.getText(); str = str + "\n"+"COURSE : " + cb.getSelectedItem(); if ( cb1.getState() == true) { str = str + "\n" + "GENDER : " + "MALE" ; } if(cb2.getState() == true) { str = str + "\n" + "GENDER : " + "FEMALE"; } if( b.getState()) { fo = new Font("Serif",Font.BOLD,15); } if(i.getState() ) { if(b.getState() ) fo = new Font("Serif",Font.BOLD+Font.ITALIC,15); else fo = new Font("Serif",Font.ITALIC,15); } ta.setFont(fo); ta.setText(str); } if(s.equals("Cancel" ) ) { System.exit(0); } } public static void main(String args[]) { Myapplication m; m = new Myapplication(); m.setSize(250,500); m.setVisible(true); } } |