Skip to main content

COMBO BOX EVENT HANDLING CODE IN SWING JAVA

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();
    }
}

Comments

Popular posts from this blog

SELECT | INSERT | UPDATE | DELETE CODE IN VB.NET WITH AUTO INCREMENT CONCEPT

Database.vb Imports System.Data.SqlClient Public Class Database     Dim con As New SqlConnection( "Data Source=G20;Initial Catalog=Me;Integrated Security=True" )     Public Sub cnopen()         If con.State = ConnectionState.Open Then             con.Close()         End If         con.Open()     End Sub     Public Sub cnclose()         If con.State <> ConnectionState.Closed Then             con.Close()         End If     End Sub     Public Function Displaygrid( ByVal query As String ) As DataTable         Dim dt As N...

CLASSIFICATION OF OPERATING SYSTEMS

Operating systems can be classified into different types based on their interface, user friendliness, and functionality. Different types of operating systems are: Character user interface (CUI)-based operating systems Graphical user interface (GUI)-based operating systems Single-user operating systems Multi-user operating systems Single-tasking operating systems Multitasking operating systems Real-time operating systems 1. Character User Interface (CUI)-Based Operating Systems: MS-DOS and UNIX (not newer Linux) Such an interface is also called a Command-Line Interface (CLI). 2. Graphical User Interface (GUI)-Based Operating Systems GUI-based operating systems are easy to use because the user can click menus and icons rather than type cryptic commands. Users can use a device called a mouse to select an application, after which the operating system will load and run it. In comparison to a CUI-based operating system, a GUI based operating system is slower and needs ...

DIFFERENCE BETWEEN DBMS AND RDBMS

Sl.# DBMS RDBMS 1 Introduced in 1960s. Introduced in 1970s. 2 During introduction it followed the navigational modes (Navigational DBMS) for data storage and fetching. This model uses relationship between tables using primary keys, foreign keys and indexes. 3 Data fetching is slower for complex and large amount of data. Comparatively faster because of its relational model. 4 Used for applications using small amount of data. Used for complex and large amount of data. 5 Data Redundancy is common in this model Keys and indexes are used in the tables to avoid redundancy. 6 Example systems are dBase, Microsoft Acces. Example systems are  SQL Server , Oracle .