📄 appletcolorexam.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class appletColorExam extends Applet implements ActionListener {
TextField t1, t2, t3; //3个文本框分别用户输入R、G、B颜色值
Button btn1, btn2;
public void init() {
Label l1 = new Label("输入R:(0~255)");
Label l2 = new Label("输入G:(0~255)");
Label l3 = new Label("输入B:(0~255)");
t1 = new TextField(10);
t2 = new TextField(10);
t3 = new TextField(10);
btn1 = new Button("前景");
btn2 = new Button("背景");
setLayout(new FlowLayout());
Panel p = new Panel(new GridLayout(4,2));
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(btn1);
p.add(btn2);
add(p);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void paint(Graphics g) {
g.drawString("字体和图形颜色为applet前景色", 15, 120);
g.fillOval(20,130,170,70);
}
public void actionPerformed(ActionEvent e) {
int R, G, B;
R = Integer.parseInt(t1.getText().toString());
G = Integer.parseInt(t2.getText().toString());
B = Integer.parseInt(t3.getText().toString());
Color myColor = new Color(R, G, B);
if (e.getActionCommand() == "背景") {
this.setBackground(myColor); //设置Applet的背景色
}
if (e.getActionCommand() == "前景") {
this.setForeground(myColor); //设置Applet的前景色
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -