?? multilistener.java
字號(hào):
/*
* 1.1 code.
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.*;
public class MultiListener extends Applet
implements ActionListener {
TextArea topTextArea;
TextArea bottomTextArea;
Button button1, button2;
public void init() {
Label l = null;
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER;
l = new Label("多監(jiān)聽(tīng)器聽(tīng)到的:");
gridbag.setConstraints(l, c);
add(l);
c.weighty = 1.0;
topTextArea = new TextArea(5, 20);
topTextArea.setEditable(false);
gridbag.setConstraints(topTextArea, c);
add(topTextArea);
c.weightx = 0.0;
c.weighty = 0.0;
l = new Label("偷聽(tīng)者聽(tīng)到的:");
gridbag.setConstraints(l, c);
add(l);
c.weighty = 1.0;
bottomTextArea = new TextArea(5, 20);
bottomTextArea.setEditable(false);
gridbag.setConstraints(bottomTextArea, c);
add(bottomTextArea);
c.weightx = 1.0;
c.weighty = 0.0;
c.gridwidth = 1;
c.insets = new Insets(10, 10, 0, 10);
button1 = new Button("啦 啦 啦");
gridbag.setConstraints(button1, c);
add(button1);
c.gridwidth = GridBagConstraints.REMAINDER;
button2 = new Button("你別說(shuō)話!");
gridbag.setConstraints(button2, c);
add(button2);
button1.addActionListener(this);
button2.addActionListener(this);
button2.addActionListener(new Eavesdropper(bottomTextArea));
}
public void actionPerformed(ActionEvent e) {
topTextArea.append(e.getActionCommand() + "\n");
}
public static void main(String[] args){
Frame f = new Frame("Converter Applet/Application");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
MultiListener m=new MultiListener( );
m.init();
f.add("Center", m);
f.pack(); //Resizes the window to its natural size.
f.setVisible(true);
}
}
class Eavesdropper implements ActionListener {
TextArea myTextArea;
public Eavesdropper(TextArea ta) {
myTextArea = ta;
}
public void actionPerformed(ActionEvent e) {
myTextArea.append(e.getActionCommand() + "\n");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -