📄 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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -