-
Notifications
You must be signed in to change notification settings - Fork 3
/
DemoJComboBox.java
60 lines (51 loc) · 1.47 KB
/
DemoJComboBox.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
// Demonstrating JComboBox
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Saket
*/
public class DemoJComboBox extends JFrame implements ActionListener{
Container cp;
JComboBox jcb;
public DemoJComboBox(String title)
{
super(title);
this.setSize(1200,800);
cp=getContentPane();
cp.setBackground(Color.cyan);
cp.setLayout(null);
Font f=new Font("arial",Font.BOLD,20);
jcb=new JComboBox();
jcb.setFont(f);
jcb.setForeground(Color.red);
jcb.addItem("Select Your City");
jcb.addItem("Nagpur");
jcb.addItem("Yeotmal");
jcb.addItem("Pune");
jcb.addItem("Mumbai");
jcb.addItem("Delhi");
jcb.addActionListener(this);
jcb.setBounds(400,200,300, 30);
cp.add(jcb);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jcb)
{
String str=jcb.getSelectedItem().toString();
JOptionPane.showMessageDialog(this, str);
}
}
public static void main(String [] args)
{
new DemoJComboBox("Demo JComboBox");
}
}