?? componenttest.java
字號(hào):
package AWTTest;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//import javax.swing.*;
public class ComponentTest extends Applet {
boolean isStandalone = false;
Panel panel1 = new Panel();
Button button1 = new Button();
Button button2 = new Button();
TextArea textArea1 = new TextArea();
//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 ComponentTest() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
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);
}
});
textArea1.setText("請(qǐng)壓按鈕一");
this.getContentPane().add(panel1, BorderLayout.SOUTH);
panel1.add(button1, null);
panel1.add(button2, null);
this.getContentPane().add(textArea1, BorderLayout.CENTER);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
// static initializer for setting look & feel
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (Exception e) {}
}
void button1_actionPerformed(ActionEvent e) {
String btn1name=button1.getName ();
textArea1.append("按鈕一的名稱:"+btn1name);
String lbl1=button1.getLabel();
textArea1.append ("按鈕一的標(biāo)簽:"+lbl1);
Dimension size1=button1.getSize ();
textArea1.append ("按鈕一的大小:"+size1);
}
void button2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -