java jtextfield 事件_JAVA JTextField事件处理
初學(xué)JAVA,筆記:
package windows;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class WindowFlow extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JTextField text1,text2;
WindowFlow(String s){
super(s);
FlowLayout flow=new FlowLayout();
setLayout(flow);
text1=new JTextField(10);
text2=new JTextField(10);
text2.setEditable(false);
add(text1);
add(text2);
text1.addActionListener(this);
setBounds(100,100,330,70);
validate();
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==text1){
int n=0,m=0;
try{
n=Integer.parseInt(text1.getText());
m=n*n;
text2.setText(n+"的平方是:"+m);
}
catch(Exception ee){
text2.setText("請輸入數(shù)字字符!");
text1.setText(null);
}
}
}
}
public class JButtonE {
public static void main(String args[]){
new WindowFlow("JAVA控件示例程序");
}
}
總結(jié)
以上是生活随笔為你收集整理的java jtextfield 事件_JAVA JTextField事件处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java web 线程数_Java We
- 下一篇: 谷歌发出“威胁”:印度反垄断处罚将使安卓