当前位置: 代码迷 >> Java相关 >> 有错,寻解决
  详细解决方案

有错,寻解决

热度:126   发布时间:2011-04-17 21:18:52.0
有错,寻解决
以下代码为计算器框架,但在编译时出错,能力有限无法解决,特来请教
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Calculator extends JFrame{
    private JTextField tf1;
    private JTextField tf2;
    private Container cp;
    private String btn[]={"0","1","2","3","4","5","6","7","8","9","+","-","*","/","=","."};
    JButton b[]=new JButton[16];
    public Calculator(){
        setTitle("简易计算器");
        setSize(300,200);
        cp=getContentPane();
        cp.setLayout(new BorderLayout());
        JPanel jp1=new JPanel();
        JPanel jp2=new JPanel();
        JPanel jp3=new JPanel();
        Font ft1=new Font("Times",Font.PLAIN,20);
        Font ft2=new Font("宋体",Font.PLAIN,14);
        tf1=new JTextField(26);
        jp1.add(tf1);
        tf2=new JTextField(18);
        JLabel label=new JLabel("事件来源按钮");
        jp2.add(label);
        label.setFont(ft2);
        jp2.add(tf2);
        jp3.setLayout(new GridLayout(4,4));
        for(int j=0;j<btn.length;j++){
            b[j]=new JButton(btn[j]);
            jp3.add(b[j]);
            b[j].setFont(ft1);
        }
        cp.add(jp1,BorderLayout.NORTH);
        cp.add(jp2,BorderLayout.SOUTH);
        cp.add(jp3,BorderLayout.CENTER);
        addWindowListener(new WindowDestroyer());
    }
}
class WindowDestroyer extends WindowAdapter{
    public void windowClosing(WindowEvent e){
        System.exit(0);
    }
}
public class calculateor{
    public static void main(String args[]) {
        Calculator win=new Calculator();
        win.setVisible(true);
    }
}

红色字体为程序报错处.
搜索更多相关的解决方案: 计算器  

----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽
2011-04-17 13:37:16
飒沓

来 自:安徽
等 级:新手上路
帖 子:10
专家分:7
注 册:2011-3-27
  得分:0 
1.没有主程序
2.依然还是那个地方错了--“the type WindowDestroyer is already defined”
3.是不是重复了WindowDestroyer类还是需要些什么WindowDestroyer类
----------------解决方案--------------------------------------------------------
回复 3楼 飒沓
复制了你的程序 可以出界面  
----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽
2011-04-18 00:52:32
w123012306

来 自:湖南
等 级:蜘蛛侠
帖 子:298
专家分:1154
注 册:2010-4-22
  得分:3 
WindowDestroyer把这类名称改下!
----------------解决方案--------------------------------------------------------
  相关解决方案