source file name: swingbiodata.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class swingbiodata extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,l5,l6,l7,l8;
JTextField t1,t2,t3;
JTextArea ta;
JList ls;
JComboBox cb;
JRadioButton cb1,cb2;
JTable tb;
public swingbiodata()
{
GridLayout fl=new GridLayout(0,2,10,10);
setLayout(fl);
l1=new JLabel("Name: ");
l2=new JLabel("Address: ");
l3=new JLabel("Mobile No: ");
l4=new JLabel("BOD: ");
l5=new JLabel("Gender: ");
l6=new JLabel("Language known: ");
l7=new JLabel("OS known: ");
l8=new JLabel("Qualification: ");
t1=new JTextField(25);
t1=new JTextField(25);
t2=new JTextField(25);
t3=new JTextField(25);
ta=new JTextArea(50,5);
JScrollPane sp1=new JScrollPane(ta);
cb=new JComboBox();
cb.addItem("Marathi");
cb.addItem("Hindi");
cb.addItem("English");
Panel p=new Panel();
ButtonGroup bg=new ButtonGroup();
cb1=new JRadioButton("Male");
cb2=new JRadioButton("Female");
bg.add(cb1);
bg.add(cb2);
p.add(cb1);
p.add(cb2);
String os[]={"Windows","Linux","Mac"};
ls=new JList(os);
JScrollPane sp2=new JScrollPane(ls);
String[][] data={
{"ssc","united","2015","75"},
{"hsc","dbj","2017","70"},
{"bsc","dbj","2020","68"},
};
String[] cols={"std","name","year","grade"};
tb=new JTable(data,cols);
JScrollPane sp3=new JScrollPane(tb);
Button b1=new Button("submit");
Button b2=new Button("clear");
add(l1);add(t1);
add(l2);add(sp1);
add(l3);add(t2);
add(l4);add(t3);
add(l5);add(p);
add(l6);add(sp2);
add(l7);add(cb);
add(l8);add(sp3);
add(b1);add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public static void main(String[] args)
{
swingbiodata f=new swingbiodata();
f.setTitle("student Biodata");
f.setSize(400,500);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String bts=ae.getActionCommand();
System.out.println("bt pressed "+bts);
String data="";
if(bts.equals("submit"))
{
data+="Name: "+t1.getText();
data+="\n Address: "+ta.getText();
data+="\n Mobile no: "+t2.getText();
data+="\n BOD: "+t3.getText();
String gn=" ";
if(cb1.isSelected())
gn=cb1.getText();
else
gn=" ";
if(cb2.isSelected())
gn=cb2.getText();
else
gn=" ";
data+="\n Gender: "+gn;
String os=" "+cb.getItemAt(cb.getSelectedIndex());
data+="\n OS selected: "+os;
opendialog(data);
}
if(bts.equals("clear"))
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
ta.setText(" ");
}
}
public void opendialog(String text)
{
Dialog dlg=new Dialog(this);
dlg.setLocation(550,50);
dlg.setSize(400,200);
dlg.setVisible(true);
TextArea ta=new TextArea(text,25,10);
dlg.add(ta);
}
}
Output:
0 Comments
Post a Comment