Java Program to create Frame that display the student information

Write a Java Program to create Frame that display the student information:-

import java.awt.*;
import java.awt.event.*;
public class Studentinfo
{
static StudFrame sf;
public static void main(String args[])
{
sf = new StudFrame();
}
}
class mywindowadapter extends WindowAdapter
{
// StudFrame sf;
// public mywindowadapter(StudFrame sf)
// {
// this.sf=sf;
// }
//
public void windowClosing(WindowEvent we)
{
// sf.setVisible(false);
System.exit(0);
}
}
class StudFrame extends Frame implements ActionListener,ItemListener
{
Button b1,b2,b3,b4;
static TextField t1,t2;
static Choice c,c1,c2,cc;
static Label lh,l1,l2,l3,l4,l5,l6;
//static List lb;
static Checkbox cb1,cb2;
static CheckboxGroup gndr=new CheckboxGroup();
StudFrame()
{
super("Student Records Form");
//mywindowadapter mw=new mywindowadapter(this);
addWindowListener(new mywindowadapter());
addcontrols();
setSize(700,550);
setResizable(true);
setVisible(true);
}
void addcontrols()
{
setLayout(null);
lh=new Label("Student Records");
l1=new Label("Student ID");
l2=new Label();
l2.setText("Name");
l3=new Label("Gender");
l4=new Label("Age");
l5=new Label("Qualification");
l6=new Label("Course");
t1=new TextField(8);
t2=new TextField(8);
cb1=new Checkbox("Male",gndr,true);
cb2=new Checkbox("Female",gndr,false);
cc=new Choice();
for(int i=15;i<=80;i++)
cc.add(Integer.toString(i));
c=new Choice();
c.add("Under Graduate");
c.add("Graduate");
c1=new Choice();
c1.add("B.A.");
c1.add("B.B.A.");
c1.add("B.C.A.");
c1.add("B.Com");
c1.add("B.E./B.Tech");
c1.add("B.Pharma");
c1.add("B.Sc.");
c2=new Choice();
c2.add("M.B.A.");
c2.add("M.C.A.");
c2.add("M.E./M.Tech");
b1=new Button("OK");
b2=new Button("Cancel");
b3=new Button("Reset");
b4=new Button("Exit");
lh.setBounds(100,30,100,30);
l1.setBounds(100,60,100,30);
l2.setBounds(100,90,100,30);
l3.setBounds(100,120,100,30);
l4.setBounds(100,150,100,30);
l5.setBounds(100,180,100,30);
l6.setBounds(100,210,100,30);
t1.setBounds(250,60,150,20);
t2.setBounds(250,90,150,20);
cb1.setBounds(250,120,40,20); cb2.setBounds(310,120,60,20);
cc.setBounds(250,150,150,20);
c.setBounds(250,180,150,20);
c1.setBounds(250,210,150,20);
c2.setBounds(250,210,150,20);
b1.setBounds(500,90,100,35); b2.setBounds(500,180,100,35);
b3.setBounds(125,290,100,35); b4.setBounds(300,290,100,35);
add(lh);
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(t1);
add(t2);
add(cb1); add(cb2);
add(cc);
add(c);
add(c1); c1.setVisible(true);
add(c2); c2.setVisible(false);
add(b1);
add(b2);
add(b3);
add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
c.addItemListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
subframe s=new subframe("Submission","Data entered successfully.");
String s1=t1.getText();
String s2=t2.getText();
if(s1.length()==0 || s1.length()==0 )
{
s.setSize(300,100);
}
else
{
s.setSize(350,350);
}
s.setVisible(true);
StudentInfo.sf.setEnabled(false);
}
else if(ae.getSource()==b2)
{
subframe s=new subframe("Cancellation","Data is not
accepted(Cancellation done).");
s.setSize(300,100);
s.setVisible(true);
StudentInfo.sf.setEnabled(false);
}
else if(ae.getSource()==b3)
{
t1.setText("");
t2.setText("");
gndr.setSelectedCheckbox(cb1);
c.select(0);
cc.select(0);
c1.select(0);
c1.setVisible(true);
}
else if(ae.getSource()==b4)
{
System.exit(0);
}
}
public void itemStateChanged(ItemEvent ie)
{
String s = c.getSelectedItem();
if(s=="Under Graduate")
{
c1.setVisible(true);
c2.setVisible(false);
}
if(s=="Graduate")
{
c1.setVisible(false);
c2.setVisible(true);
}
}
}
class subwindowadapter extends WindowAdapter
{
subframe subf;
public subwindowadapter(subframe subf)
{
this.subf=subf;
}
public void windowClosing(WindowEvent we)
{
StudentInfo.sf.setEnabled(true);
subf.setVisible(false);
}
}
class subframe extends Frame implements ActionListener
{
Button bsubok=new Button("OK");
subframe() {}
subframe(String title) {}
subframe(String title,String msg)
{
super(title);
String s1=StudFrame.t1.getText();
String s2=StudFrame.t2.getText();
subwindowadapter sw=new subwindowadapter(this);
addWindowListener(sw);
if(title=="Cancellation")
{
// StudFrame.t1.setText("");
// StudFrame.t2.setText("");
setLayout(new FlowLayout(FlowLayout.CENTER));
add(new Label(msg));
add(bsubok);
bsubok.addActionListener(this);
}
else
{
if(s1.length()==0)
{
//resize(300,100);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(new Label("Please fill in Student Name."));
add(bsubok);
bsubok.addActionListener(this);
}
else if(s2.length()==0)
{
setLayout(new FlowLayout(FlowLayout.CENTER));
add(new Label("Please fill in Student Roll Number."));
add(bsubok);
bsubok.addActionListener(this);
}
else
//add(new Label(StudFrame.t1.getText() +", Student ID:
"+StudFrame.t2.getText()+" Accepted.",Label.CENTER));
{
setLayout(null);
Label lhl,ll1,ll2,ll3,ll4,ll5,ll6,la1,la2,la3,la4,la5,la6,ltl;
lhl=new Label("Your data is:");
ll1=new Label("Student ID");
ll2=new Label();
ll2.setText("Name");
ll3=new Label("Gender");
ll4=new Label("Age");
ll5=new Label("Qualification");
ll6=new Label("Course");
ltl=new Label(msg);
la1=new Label(StudFrame.t1.getText());
la2=new Label();
la2.setText(StudFrame.t2.getText());
la3=new
Label(StudFrame.gndr.getSelectedCheckbox().getLabel());
la4=new Label(StudFrame.cc.getSelectedItem());
la5=new Label(StudFrame.c.getSelectedItem());
if(StudFrame.c.getSelectedItem()=="Under Graduate")
la6=new Label(StudFrame.c1.getSelectedItem());
else
la6=new Label(StudFrame.c2.getSelectedItem());
add(lhl);
add(ll1);
add(ll2);
add(ll3);
add(ll4);
add(ll5);
add(ll6);
add(la1);
add(la2);
add(la3);
add(la4);
add(la5);
add(la6);
add(ltl);add(bsubok);
lhl.setBounds(50,30,100,30);
ll1.setBounds(50,60,100,30);
ll2.setBounds(50,90,100,30);
ll3.setBounds(50,120,100,30);
ll4.setBounds(50,150,100,30);
ll5.setBounds(50,180,100,30);
ll6.setBounds(50,210,100,30);
la1.setBounds(200,60,100,30);
la2.setBounds(200,90,100,30);
la3.setBounds(200,120,100,30);
la4.setBounds(200,150,100,30);
la5.setBounds(200,180,100,30);
la6.setBounds(200,210,100,30);
ltl.setBounds(75,240,200,30);
bsubok.setBounds(100,280,100,30);
bsubok.addActionListener(this);
}
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bsubok)
{
StudentInfo.sf.setEnabled(true);
setVisible(false);
}
}
}

Related Posts