example7_4.java.bak
来自「不错的教程 适合中高级人员的使用」· BAK 代码 · 共 49 行
BAK
49 行
import java.awt.*;
import java.awt.event.*;
class YourWindow extends Frame implements ActionListener
{
TextField text1,text2;
Policeman police;
YourWindow()
{
text1=new TextField(10);
text2=new TextField(10);
police=new Policeman();
setLayout(new FlowLayout());
add(text1);add(text2);
text1.addActionListener(this);
text2.addActionListener(police);
setBounds(100,100,150,150);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
String number=e.getActionCommand();
int n=Integer.parseInt(number);
int m=n*n;
System.out.println("n的平方是:"+m);
}
}
class Policeman implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String number=e.getActionCommand();
int n=Integer.parseInt(number);
int m=n*n*n;
text2.setText("n的平方是:"+m);
}
}
public class Example7_4
{
public static void main(String[] args)
{
YourWindow win=new YourWindow();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?