- 分享
- 0
- 人气
- 0
- 主题
- 8
- 帖子
- 3950
- UID
- 95252
- 积分
- 4741
- 阅读权限
- 22
- 注册时间
- 2007-8-24
- 最后登录
- 2013-6-29
- 在线时间
- 937 小时
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class A1 extends JFrame
{
private JButton Divede = new JButton ("Divede");
private JTextField number1 =new JTextField(8);
private JTextField number2 =new JTextField(8);
private JTextArea Result = new JTextArea();
public A1()
{
setLayout(new GridLayout(2, 6, 10, 10));
JPanel p1 = new JPanel(new GridLayout(1,6,5,5));
JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
p1.add (new JLabel("number1:"));
p1.add (number1);
p1.add (new JLabel("number2:"));
p1.add (number2);
p1.add (new JLabel("Result:"));
p1.add (Result);
p2.add(Divede);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
ActionListener listener = new OKListener();
Divede.addActionListener(listener);
Result.setEditable(false);
}
public static void main(String[] args)
{
A1 frame = new A1();
frame.setTitle("Divede");
frame.setSize(400, 250);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
}
class OKListener implements ActionListener
{
private String text;
private double num;
private double num1;
private double num2;
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Divede)
{
num1 = Double.parseDouble(number1.getText());
num2 = Double.parseDouble(number2.getText());
try
{
num = num1 / num2;
text = Double.toString(num);
Result.setText(text);
}
catch(ArithmeticException n)
{
System.out.println("Please Enter Number.");
}
finally
{
System.exit(0);
}
}
}
}
}
没有erro出现了,但是程式跑了就马上关><
[ 本帖最后由 natgnah 于 2009-5-31 10:39 PM 编辑 ] |
catch
, catch
, catch
, erro
, erro
, erro
, Java
, Java
, Java
, TRY
, TRY
, TRY
, 程式
, 程式
, 程式
|