Sei sulla pagina 1di 17

SWING 1.

Label,TextFields,ComboBox,Radio,checkbox OUTPUT

Prrogram

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class swingallinone extends JApplet { JRadioButton Male,Female; JButton b1,b2,b3,b4; JTextField jtf1,jtf2; JComboBox jcb; JCheckBox eng,hindi,punjabi; JLabel one,two,three,four,five,six,seven ;

public void init() {

setLayout(null);

JLabel one = new JLabel("STUDENT INFORMATION SYSTEM"); JLabel two = new JLabel("ROLL NO"); JLabel three = new JLabel("NAME"); JLabel four = new JLabel("CLASS"); JLabel five = new JLabel("GENDER"); JLabel six = new JLabel("LANGUAGE"); JLabel seven = new JLabel("CREATED BY : SANDEEP SONKA"); jtf1 = new JTextField(100); jtf2 = new JTextField(100); JComboBox jcb = new JComboBox(); jcb.addItem("MCA"); jcb.addItem("MSC IT"); jcb.addItem("BCA"); JRadioButton Male = new JRadioButton("Male"); JRadioButton Female = new JRadioButton("Female"); ButtonGroup bg = new ButtonGroup(); bg.add(Male); bg.add(Female); JCheckBox eng =new JCheckBox("eng"); JCheckBox hindi = new JCheckBox("hindi"); JCheckBox punjabi = new JCheckBox("punjabi");

one.setBounds(120,60,200,20); two.setBounds(40,100,60,20); three.setBounds(40,130,40,20); four.setBounds(40,160,40,20); five.setBounds(40,190,50,20); six.setBounds(40,220,70,20);

seven.setBounds(120,300,250,20); jtf1.setBounds(150,100,150,20); jtf2.setBounds(150,130,150,20); jcb.setBounds(150,160,90,20); Male.setBounds(150,190,60,20); Female.setBounds(210,190,120,20); eng.setBounds(150,220,60,20); hindi.setBounds(220,220,60,20); punjabi.setBounds(290,220,80,20); getContentPane().add(one); getContentPane().add(two); getContentPane().add(three); getContentPane().add(four); getContentPane().add(five); getContentPane().add(six); getContentPane().add(seven); getContentPane().add(jtf1); getContentPane().add(jtf2); getContentPane().add(jcb); getContentPane().add(Male); getContentPane().add(Female); getContentPane().add(eng); getContentPane().add(hindi); getContentPane().add(punjabi); } }

===============================================================

2. all in one SWING WITH ACTION LISTENER OUTPUT

Program import java.awt.*; import java.awt.event.*; import javax.swing.*; public class swingallinoneActionListener extends JApplet implements ActionListener { JRadioButton Male,Female; JButton b1,b2,b3,b4; JTextField jtf1,jtf2,jtf3,jtf4; JComboBox jcb; JCheckBox eng,hindi,punjabi; JLabel one,two,three,four,five,six,seven ;

public void init() { setLayout(null); JLabel one = new JLabel("STUDENT INFORMATION SYSTEM"); JLabel two = new JLabel("ROLL NO"); JLabel three = new JLabel("NAME"); JLabel four = new JLabel("CLASS"); JLabel five = new JLabel("GENDER"); JLabel six = new JLabel("LANGUAGE"); JLabel seven = new JLabel("CREATED BY : SANDEEP SONKA"); jtf1 = new JTextField(100); jtf2 = new JTextField(100); jtf3 = new JTextField(100); jtf4 = new JTextField(100); JComboBox jcb = new JComboBox(); jcb.addItem("MCA"); jcb.addItem("MSC IT"); jcb.addItem("BCA"); JRadioButton Male = new JRadioButton("Male"); JRadioButton Female = new JRadioButton("Female"); ButtonGroup bg = new ButtonGroup(); bg.add(Male); bg.add(Female); JCheckBox eng =new JCheckBox("eng"); JCheckBox hindi = new JCheckBox("hindi"); JCheckBox punjabi = new JCheckBox("punjabi");

one.setBounds(120,60,200,20); two.setBounds(40,100,60,20); three.setBounds(40,130,40,20); four.setBounds(40,160,40,20); five.setBounds(40,190,50,20); six.setBounds(40,220,70,20); seven.setBounds(120,250,250,20); jtf1.setBounds(150,100,150,20);

jtf2.setBounds(150,130,150,20); jtf3.setBounds(400,190,120,20); jtf4.setBounds(400,220,80,20); jcb.setBounds(150,160,90,20); Male.setBounds(150,190,60,20); Female.setBounds(210,190,120,20); eng.setBounds(150,220,60,20); hindi.setBounds(220,220,60,20); punjabi.setBounds(290,220,80,20); getContentPane().add(one); getContentPane().add(two); getContentPane().add(three); getContentPane().add(four); getContentPane().add(five); getContentPane().add(six); getContentPane().add(seven); Male.addActionListener(this); Female.addActionListener(this); eng.addActionListener(this); hindi.addActionListener(this); punjabi.addActionListener(this); getContentPane().add(jtf1); getContentPane().add(jtf2); getContentPane().add(jtf3); getContentPane().add(jtf4); getContentPane().add(jcb); getContentPane().add(Male); getContentPane().add(Female); getContentPane().add(eng); getContentPane().add(hindi); getContentPane().add(punjabi); } public void actionPerformed(ActionEvent ae) {

jtf3.setText(ae.getActionCommand()); jtf4.setText(ae.getActionCommand()); } } ========================================================== 3. ALL IN SWING WITH ITEM LISTENER

OUTPUT

PROGRAM import java.awt.*; import java.awt.event.*; import javax.swing.*; public class swingallinoneActionListener extends JApplet implements ItemListener { JRadioButton Male,Female; JButton b1,b2,b3,b4; JTextField jtf1,jtf2,jtf3,jtf4; JComboBox jcb; JCheckBox eng,hindi,punjabi; JLabel one,two,three,four,five,six,seven ; public void init() { setLayout(null); JLabel one = new JLabel("STUDENT INFORMATION SYSTEM"); JLabel two = new JLabel("ROLL NO"); JLabel three = new JLabel("NAME"); JLabel four = new JLabel("CLASS"); JLabel five = new JLabel("GENDER"); JLabel six = new JLabel("LANGUAGE"); JLabel seven = new JLabel("CREATED BY : SANDEEP SONKA"); jtf1 = new JTextField(100); jtf2 = new JTextField(100); jtf3 = new JTextField(100); jtf4 = new JTextField(100); JComboBox jcb = new JComboBox(); jcb.addItem("MCA"); jcb.addItem("MSC IT"); jcb.addItem("BCA"); JRadioButton Male = new JRadioButton("Male"); JRadioButton Female = new JRadioButton("Female"); ButtonGroup bg = new ButtonGroup(); bg.add(Male); bg.add(Female);

JCheckBox eng =new JCheckBox("eng"); JCheckBox hindi = new JCheckBox("hindi"); JCheckBox punjabi = new JCheckBox("punjabi");

one.setBounds(120,60,200,20); two.setBounds(40,100,60,20); three.setBounds(40,130,40,20); four.setBounds(40,160,40,20); five.setBounds(40,190,50,20); six.setBounds(40,220,70,20); seven.setBounds(120,250,250,20); jtf1.setBounds(150,100,150,20); jtf2.setBounds(150,130,150,20); jtf3.setBounds(400,190,120,20); jtf4.setBounds(400,220,80,20); jcb.setBounds(150,160,90,20); Male.setBounds(150,190,60,20); Female.setBounds(210,190,120,20); eng.setBounds(150,220,60,20); hindi.setBounds(220,220,60,20); punjabi.setBounds(290,220,80,20); getContentPane().add(one); getContentPane().add(two); getContentPane().add(three); getContentPane().add(four); getContentPane().add(five); getContentPane().add(six); getContentPane().add(seven); Male.addItemListener(this); Female.addItemListener(this); eng.addItemListener(this); hindi.addItemListener(this); punjabi.addItemListener(this); getContentPane().add(jtf1);

getContentPane().add(jtf2); getContentPane().add(jtf3); getContentPane().add(jtf4); getContentPane().add(jcb); getContentPane().add(Male); getContentPane().add(Female); getContentPane().add(eng); getContentPane().add(hindi); getContentPane().add(punjabi); } public void itemStateChanged(ItemEvent ie) { //JRadioButton Male = (JRadioButton)ie.getItem(); //JRadioButton Female = (JRadioButton)ie.getItem(); // // jtf3.setText(Male.getText()); jtf3.setText(Female.getText()); JCheckBox eng = (JCheckBox)ie.getItem(); JCheckBox hindi = (JCheckBox)ie.getItem(); JCheckBox punjabi = (JCheckBox)ie.getItem(); jtf4.setText(eng.getText()); jtf4.setText(hindi.getText()); jtf4.setText(punjabi.getText()); } }

OUTPUT

Program

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class swingallinone extends JApplet implements ActionListener { JRadioButton Male,Female; JButton b1,b2; JTextField jtf1,jtf2,jtf3,jtf4; JComboBox jcb; JCheckBox eng,hindi,punjabi; JLabel one,two,three,four,five,six,seven ;

public void init() { setLayout(null); JLabel one = new JLabel("STUDENT INFORMATION SYSTEM"); JLabel two = new JLabel("ROLL NO"); JLabel three = new JLabel("NAME"); JLabel four = new JLabel("CLASS"); JLabel five = new JLabel("GENDER"); JLabel six = new JLabel("LANGUAGE"); JLabel seven = new JLabel("CREATED BY : SANDEEP SONKA"); jtf1 = new JTextField(100); jtf2 = new JTextField(100); jtf3 = new JTextField(100); jtf4 = new JTextField(100); JComboBox jcb = new JComboBox(); jcb.addItem("MCA"); jcb.addItem("MSC IT"); jcb.addItem("BCA"); JRadioButton Male = new JRadioButton("Male"); JRadioButton Female = new JRadioButton("Female"); ButtonGroup bg = new ButtonGroup(); bg.add(Male); bg.add(Female); JCheckBox eng =new JCheckBox("eng"); JCheckBox hindi = new JCheckBox("hindi"); JCheckBox punjabi = new JCheckBox("punjabi"); b1 = new JButton("Amritsar"); b2 = new JButton("Batala");

one.setBounds(120,60,200,20); two.setBounds(40,100,60,20); three.setBounds(40,130,40,20); four.setBounds(40,160,40,20); five.setBounds(40,190,50,20); six.setBounds(40,220,70,20);

seven.setBounds(120,280,250,20); jtf1.setBounds(150,100,150,20); jtf2.setBounds(150,130,150,20); jtf3.setBounds(400,190,120,20); jtf4.setBounds(400,220,80,20); jcb.setBounds(150,160,90,20); Male.setBounds(150,190,60,20); Female.setBounds(210,190,120,20); eng.setBounds(150,220,60,20); hindi.setBounds(220,220,60,20); punjabi.setBounds(290,220,80,20); b1.setBounds(220,260,100,20); b2.setBounds(330,260,80,20); getContentPane().add(one); getContentPane().add(two); getContentPane().add(three); getContentPane().add(four); getContentPane().add(five); getContentPane().add(six); getContentPane().add(seven); Male.addActionListener(this); Female.addActionListener(this); eng.addActionListener(this); hindi.addActionListener(this); punjabi.addActionListener(this); getContentPane().add(jtf1); getContentPane().add(jtf2); getContentPane().add(jtf3); getContentPane().add(jtf4); getContentPane().add(jcb); getContentPane().add(Male); getContentPane().add(Female); getContentPane().add(eng);

getContentPane().add(hindi); getContentPane().add(punjabi); getContentPane().add(b1); getContentPane().add(b2); } public void actionPerformed(ActionEvent ae) {

jtf3.setText(ae.getActionCommand()); jtf4.setText(ae.getActionCommand()); } } ==========================================================

Output

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class swingbuttonactionlistner extends JApplet implements ActionListener { JRadioButton Male,Female; JButton b1,b2; JTextField jtf1,jtf2,jtf3; JComboBox jcb; JCheckBox eng,hindi,punjabi; JLabel one,two,three,four,five,six,seven ; public void init() { setLayout(null); JLabel one = new JLabel("STUDENT INFORMATION SYSTEM"); JLabel two = new JLabel("ROLL NO"); JLabel three = new JLabel("NAME"); JLabel four = new JLabel("CLASS"); JLabel five = new JLabel("GENDER"); JLabel six = new JLabel("LANGUAGE"); JLabel seven = new JLabel("CREATED BY : SANDEEP SONKA"); jtf1 = new JTextField(100); jtf2 = new JTextField(100); jtf3 = new JTextField(100); JComboBox jcb = new JComboBox(); jcb.addItem("MCA"); jcb.addItem("MSC IT"); jcb.addItem("BCA"); JRadioButton Male = new JRadioButton("Male"); JRadioButton Female = new JRadioButton("Female"); ButtonGroup bg = new ButtonGroup(); bg.add(Male); bg.add(Female); JCheckBox eng =new JCheckBox("eng"); JCheckBox hindi = new JCheckBox("hindi"); JCheckBox punjabi = new JCheckBox("punjabi");

b1 = new JButton("Amritsar"); b2 = new JButton("Batala"); one.setBounds(120,60,200,20); two.setBounds(40,100,60,20); three.setBounds(40,130,40,20); four.setBounds(40,160,40,20); five.setBounds(40,190,50,20); six.setBounds(40,220,70,20); seven.setBounds(120,280,250,20); jtf1.setBounds(150,100,150,20); jtf2.setBounds(150,130,150,20); jtf3.setBounds(420,260,120,20); jcb.setBounds(150,160,90,20); Male.setBounds(150,190,60,20); Female.setBounds(210,190,120,20); eng.setBounds(150,220,60,20); hindi.setBounds(220,220,60,20); punjabi.setBounds(290,220,80,20); b1.setBounds(220,260,100,20); b2.setBounds(330,260,80,20); getContentPane().add(one); getContentPane().add(two); getContentPane().add(three); getContentPane().add(four); getContentPane().add(five); getContentPane().add(six); getContentPane().add(seven); b1.addActionListener(this); b2.addActionListener(this); getContentPane().add(jtf1); getContentPane().add(jtf2); getContentPane().add(jtf3);

getContentPane().add(jcb); getContentPane().add(Male); getContentPane().add(Female); getContentPane().add(eng); getContentPane().add(hindi); getContentPane().add(punjabi); getContentPane().add(b1); getContentPane().add(b2); } public void actionPerformed(ActionEvent ae) { jtf3.setText(ae.getActionCommand()); } } ==================================

Potrebbero piacerti anche