原帖由 natgnah 于 2009-5-29 12:31 PM 发表
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 int num;
private int num1;
private int num2;
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Result)
{
num1 = Integer.parseInt(number1.getText());
num2 = Integer.parseInt(number2.getText());
do
{
try
{
num = num1 / num2;
text = Integer.ToSting(num);
Result.setText(text);
}
catch(ArithmeticException n)
{
System.out.println("Please Enter Number.");
}
finally
{
System.exit();
}
}
}
}
}
}
不知道哪里出现问题,请各位帮小弟看看一下。。。
原帖由 natgnah 于 2009-5-30 11:28 PM 发表
我是参考老师的做法,我还不熟do。。。
去了do之后,还是有erro
erro:
C:\Users\yuan\Desktop\homework\A1.java:61: 找不到符号
符号: 方法 ToSting(int)
位置: 类 java.lang.Integer
...
原帖由 natgnah 于 2009-5-29 12:31 发表
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 JT ...
欢迎光临 JBTALKS.CC (https://jbtalks.my/) | Powered by Discuz! X2.5 |