📄 example7_4.java.bak
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -