-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorChoice.java
More file actions
50 lines (49 loc) · 1.1 KB
/
ColorChoice.java
File metadata and controls
50 lines (49 loc) · 1.1 KB
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
import java.awt.*;
import java.awt.event.*;
public class ColorChoice extends Frame implements ItemListener{
Choice c;
String msg="";
public ColorChoice(){
c=new Choice();
c.add("WHITE");
c.add("RED");
c.add("GREEN");
c.add("BLUE");
c.add("YELLOW");
c.add("BLACK");
c.setBounds(20,50,200,50);
add(c);
setLayout(null);
c.addItemListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);}});
}
public void itemStateChanged(ItemEvent ie) {
repaint();
}
public void paint(Graphics g) {
Font f=new Font("dialog",Font.BOLD,20);
g.setFont(f);
g.drawString("Selected Color: ", 20, 200);
msg=c.getSelectedItem();
g.drawString(msg, 180, 200);
if(msg=="GREEN")
setBackground(Color.green);
if(msg=="WHITE")
setBackground(Color.white);
if(msg=="RED")
setBackground(Color.red);
if(msg=="BLUE")
setBackground(Color.blue);
if(msg=="YELLOW")
setBackground(Color.yellow);
if(msg=="BLACK")
setBackground(Color.black);
}
public static void main(String args[]){
ColorChoice cc=new ColorChoice();
cc.setSize(400,300);
cc.setVisible(true);
}
}