?? hw17_5.java
字號:
import java.awt.*;
import java.awt.event.*;
class hw17_5 extends Frame implements ItemListener
{
static hw17_5 frm=new hw17_5();
static Label lab=new Label();
static Choice chc=new Choice();
public static void main(String args[])
{
frm.setLayout(null);
frm.setTitle("Select a color");
chc.add("White");
chc.add("Black");
chc.add("Blue");
chc.add("Yellow");
chc.add("Green");
frm.setSize(200,150);
lab.setAlignment(Label.CENTER);
chc.setBounds(10,40,80,60);
lab.setBounds(100,40,80,100);
frm.add(chc);
frm.add(lab);
chc.addItemListener(frm);
frm.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
String color=chc.getSelectedItem();
if(color=="White")
{
lab.setBackground(Color.white);
lab.setText("White");
}
else if(color=="Black")
{
lab.setBackground(Color.black);
lab.setText("Black");
}
else if(color=="Blue")
{
lab.setBackground(Color.blue);
lab.setText("Blue");
}
else if(color=="Yellow")
{
lab.setBackground(Color.yellow);
lab.setText("Yellow");
}
else if(color=="Green")
{
lab.setBackground(Color.green);
lab.setText("Green");
}
frm.setTitle("you select "+color);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -