java问题帮我看看

来源:百度知道 编辑:UC知道 时间:2024/05/06 01:37:18
import java.awt.*;
import java.awt.event.*;

public class Exam1_4
{
public static void main(String args[])
{
ApplicationFrame AF=new ApplicationFrame();
}
}
class ApplicationFrame extends Frame implements ActionListener
{
Label prompt;
TextField text1,text2;
Button btn;
int a=0,b=0;
ApplicationFrame()
{
super("我的窗口");
prompt=new Label("请输入两个整型数:");
text1=new TextField(4);
text2=new TextField(4);
btn=new Button("计算");
setLayout(new FlowLayout());
add(text1);
add(text2);
add(btn);
btn.addActionListener(this);
show();
}
public void actionPerformed(ActionEvent e)
{
a=Integer.parseInt(text1.getText());
b=Integer.parseInt(text2.getText());
}
public void paint(Graphics g)
{
g.drawSting("运行结果:"+a+&qu

首先少了个R,还有你程序里有很多不协调的地方,我给改了改,你看看吧~
import java.awt.*;
import java.awt.event.*;

import javax.swing.JFrame;

public class Exam1_4
{
public static void main(String args[])
{
ApplicationFrame AF=new ApplicationFrame();
}
}
class ApplicationFrame extends Frame implements ActionListener
{
Label prompt,show;
TextField text1,text2;
Button btn;
int a=0,b=0;
ApplicationFrame()
{
super("我的窗口");
prompt=new Label("请输入两个整型数:");
add(prompt);
show=new Label("运行结果");
text1=new TextField(4);
text2=new TextField(4);
btn=new Button("计算");
setLayout(new FlowLayout());
add(text1);
add(text2);
add(btn);

add(show);
btn.addActionListener(this);
setSize(150, 200);
show();
}
public void actionPerformed(ActionEvent e)
{
a=Integer.parseI