📄 example9_1.java
字号:
import java.awt.*;
import java.awt.event.*;
class Example9_1 extends WindowAdapter implements ActionListener
{
Frame f;
private Button bClear;
private Button bCopy;
private Button bClose;
TextField tfs,tft;
String ad="How are you";
Label lSource;
Label lTarget;
Label lSpace1;
Label lSpace2;
/**
* Method go
*
*
*/
public void go() {
// TODO: Add your code here
f=new Frame("My Frame");
f.setLayout(new GridLayout(6,1,10,10));
// the last two i s gap
f.setSize(350,350);
lSource=new Label("source");
lTarget=new Label("Target");
lSpace1=new Label();
lSpace2=new Label();
tfs=new TextField(ad,15);
tft=new TextField(15);
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
p3.setLayout(new FlowLayout(FlowLayout.CENTER,40,0));
p1.setSize(100,50);
p2.setSize(100,50);
p3.setSize(100,50);
p1.add(lSource);
p1.add(tfs);
p2.add(lTarget);
p2.add(tft);
bClear=new Button("clear");
bCopy=new Button ("copy");
bClose=new Button("close");
bClear.addActionListener(this);
bCopy.addActionListener(this);
bClose.addActionListener(this);
p3.add(bClear);
p3.add(bCopy);
p3.add(bClose);
f.add(lSpace1);
f.add(p1);
f.add(p2);
f.add(lSpace2);
f.add(p3);
f.addWindowListener(this);
f.setVisible(true);
}
//to implement ActionListener's interface actionPerformed() method
/**
* Method actionPerformed
*
*
*/
public void actionPerformed(ActionEvent e) {
// TODO: Add your code here
String sBlank="";
if(e.getSource()==bClear)
{
tfs.setText(sBlank);
tft.setText(sBlank);
}
if(e.getSource()==bCopy)
{
tft.setText(tfs.getText());
}
if(e.getSource()==bClose)
{
System.exit(0);
}
}
public void windowClosing(WindowEvent w){
System.exit(0);
}
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
Example9_1 be=new Example9_1();
be.go();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -