📄 example7_5.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Example7_5
{
public static void main(String[] args)
{
HisWindow win=new HisWindow();
}
}
class HisWindow extends Frame
{
TextField text1,text2,text3;
HisWindow()
{
text1=new TextField(10);
text2=new TextField(10);
text3=new TextField(10);
setLayout(new FlowLayout());
add(text1);add(text2);add(text3);
Policeman police=new Policeman();
text1.addActionListener(police);
text1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String number=e.getActionCommand();
int n=Integer.parseInt(number);
int m=n*n;
text2.setText(n+"的平方是"+m);
}
}
);
setBounds(100,100,150,150);
setVisible(true);
validate();
}
class Policeman implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String number=e.getActionCommand();
int n=Integer.parseInt(number);
int m=n*n*n;
text3.setText(n+"的平方是:"+m);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -