黑马程序员技术交流社区
标题:
以前编了一个计算器,有个错误,找不到。哪个大神帮看...
[打印本页]
作者:
nuoxi0318
时间:
2013-7-14 21:17
标题:
以前编了一个计算器,有个错误,找不到。哪个大神帮看...
本帖最后由 杨兴庭 于 2013-7-16 17:45 编辑
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator1 extends Frame
{ private static String[] KEYS={"0","1","2","3",
"4","5","6","7",
"8","9","+","-",
"*","/","=","%"};
private Panel keys;
private Panel text;
public Calculator1(String title)
{super(title);
setSize(200,200);
setLocation(100,100);
setKeys();
setText();
setLayout(new BorderLayout(3,3));
add(keys,BorderLayout.CENTER);
add(text,BorderLayout.NORTH );
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void setKeys()
{
Panel keys=new Panel();
keys.setLayout(new GridLayout(4,4,3,3));
for(int i=0;i<KEYS.length;i++)
{
keys.add(new JButton(KEYS[i]));
}
}
public void setText()
{
Panel text=new Panel();
TextField f=new TextField(25);
text.add(f);
}
public static void main(String[] args) throws HeadlessException
{ Calculator1 f=new Calculator1("计算器");
f.pack();
f.show();
}
}
复制代码
作者:
草貌路飞
时间:
2013-7-15 00:59
晕..你的setKeys和setText方法里面都重新定义了新的变量了..肯定以本地的为主么,把Panel keys和Panel text前的Panel删了吧
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2