📄 applet1.java
字号:
package ex12_02;import java.awt.*;import java.awt.event.*;import java.applet.*;public class Applet1 extends Applet { boolean isStandalone = false; Button button1 = new Button(); Button button2 = new Button(); Button button3 = new Button(); /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public Applet1() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { button1.setLabel("红色"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button2.setLabel("蓝色"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); button3.setLabel("绿色"); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button3_actionPerformed(e); } }); this.add(button1, null); this.add(button2, null); this.add(button3, null); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void button1_actionPerformed(ActionEvent e) { //将Applet显示的区域颜色改变为红色this.setBackground(Color.red); } void button2_actionPerformed(ActionEvent e) { //将Applet显示的区域颜色改变为蓝色this.setBackground(Color.blue); } void button3_actionPerformed(ActionEvent e) { //将Applet显示的区域颜色改变为绿色this.setBackground(Color.green); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -