package Swing;
/**
*
* @author Administrator
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComboBox1 implements ActionListener
{
JFrame fr;
JPanel p;
JTextField t1;
JComboBox c1;
ComboBox1()
{
fr=new JFrame("My ComboBox");
p=new JPanel();
t1=new JTextField();
p.setLayout(null);
c1=new JComboBox();
c1.addItem("INDIA");
c1.addItem("JAPAN");
c1.addItem("ENGLAND");
c1.addItem("AUSTRALIA");
c1.addItem("NEW ZEELAND");
c1.addActionListener(this);
t1.setBounds(120,60, 100,25);
c1.setBounds(20,60,100,25);
p.add(t1);
p.add(c1);
fr.add(p);
fr.addWindowListener(new wclose());
fr.setSize(500,500);
fr.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
String c=(String) c1.getSelectedItem();
System.out.println("Msg = "+c);
if(c.equals("INDIA"))
{
System.out.println("INDIA");
t1.setText(c);
}
else if(c.equals("JAPAN"))
{
System.out.println("JAPAN");
t1.setText(c);
}
else if(c.equals("ENGLAND"))
{
System.out.println("ENGLAND");
t1.setText(c);
}
else if(c.equals("AUSTRALIA"))
{
System.out.println("AUSTRALIA");
t1.setText(c);
}
else if(c.equals("NEW ZEELAND"))
{
System.out.println("NEW ZEELAND");
t1.setText(c);
}
}
public static void main (String args[])
{
ComboBox1 obj=new ComboBox1();
}
}
/**
*
* @author Administrator
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComboBox1 implements ActionListener
{
JFrame fr;
JPanel p;
JTextField t1;
JComboBox c1;
ComboBox1()
{
fr=new JFrame("My ComboBox");
p=new JPanel();
t1=new JTextField();
p.setLayout(null);
c1=new JComboBox();
c1.addItem("INDIA");
c1.addItem("JAPAN");
c1.addItem("ENGLAND");
c1.addItem("AUSTRALIA");
c1.addItem("NEW ZEELAND");
c1.addActionListener(this);
t1.setBounds(120,60, 100,25);
c1.setBounds(20,60,100,25);
p.add(t1);
p.add(c1);
fr.add(p);
fr.addWindowListener(new wclose());
fr.setSize(500,500);
fr.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
String c=(String) c1.getSelectedItem();
System.out.println("Msg = "+c);
if(c.equals("INDIA"))
{
System.out.println("INDIA");
t1.setText(c);
}
else if(c.equals("JAPAN"))
{
System.out.println("JAPAN");
t1.setText(c);
}
else if(c.equals("ENGLAND"))
{
System.out.println("ENGLAND");
t1.setText(c);
}
else if(c.equals("AUSTRALIA"))
{
System.out.println("AUSTRALIA");
t1.setText(c);
}
else if(c.equals("NEW ZEELAND"))
{
System.out.println("NEW ZEELAND");
t1.setText(c);
}
}
public static void main (String args[])
{
ComboBox1 obj=new ComboBox1();
}
}
Comments
Post a Comment