还有一张传不上去
这都是些什么问题?麻烦大致讲下 谢谢
代码如下
import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class Test extends JFrame implements ActionListener{ JLabel lbl1,lbl2; JTextField txt1,txt2,txtResult; JButton btnCalc; public Test(){ super("我的第一个Swing程序"); txt1=new JTextField(5); lbl1=new JLabel("="); txtResult=new JTextField(7); txtResult.setEditable(false); btnCalc=new JButton("计算"); btnCalc.addActionListener(this); Container c=getContentPane(); c.setLayout(new FlowLayout()); c.add(txt1); c.add(lbl1); c.add(txt2); c.add(lbl2); c.add(txtResult); c.add(btnCalc); setSize(500,100); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e){ float num1=0,num2=0,result=0; try{ num1=Float.parseFloat(txt1.getText()); num2=Float.parseFloat(txt2.getText()); result=num1+num2; }catch(Exception ex){ txtResult.setText("数据非法!"); return; } txtResult.setText(Float.valueOf(result).toString()); } public static void main(String[] args){ new Test(); } }
凤凰求蛊
蛊毒传说
慕村225694
相关分类