CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

大家帮帮我,我的程序为什么不出界面(编译通过,执行时一闪即逝)

楼主feitianfly(feitian)2003-11-03 19:40:03 在 Java / J2SE / 基础类 提问

是一个简单的计算器程序,运行时闪都不闪,直接结束了,不知为什么,请指点一下  
  主要是为什么jframe都不显示出来,什么反映都没有,我同学也遇到了这个问题,  
  我们想可能是   JPanel,JFrame   没有设置好,  
  谢谢了  
   
   
  import   javax.swing.*;  
  import   java.awt.*;  
  import   java.awt.event.*;  
  import   java.lang.*;  
  import   java.math.*;  
  public   class   Calculator   implements   ActionListener{  
        double   OP1=0,OP2=0,OP3=0,OP4=0;  
        Double   op;  
        int   FLAG1=0,FLAG2=-1;  
        JFrame   counterFrame;  
        JPanel   resultPanel,keyPanel;  
        JLabel   result;  
        public   void   Calculator(){  
                counterFrame=new   JFrame("Calculator");  
                  resultPanel=new   JPanel();  
                  keyPanel=new   JPanel();  
                  keyPanel.setLayout(new   GridLayout(5,4,5,5));  
                  addWidgets();  
                  counterFrame.add(resultPanel);  
                  counterFrame.add(keyPanel);  
                  counterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                  counterFrame.pack();  
                  counterFrame.setVisible(true);  
        }  
        private   void   addWidgets(){  
                  result=new   JLabel("                                         ");  
                  resultPanel.add(result);  
                  Button     button1=new   Button("7");      
                  Button     button2=new   Button("8");  
                  Button     button3=new   Button("9");  
                  Button     button4=new   Button("/");  
                  Button     button5=new   Button("4");  
                  Button     button6=new   Button("5");  
                  Button     button7=new   Button("6");  
                  Button     button8=new   Button("*");  
                  Button     button9=new   Button("1");  
                  Button     button10=new   Button("2");  
                  Button     button11=new   Button("3");  
                  Button     button12=new   Button("-");  
                  Button     button13=new   Button("0");  
                  Button     button14=new   Button("Л");  
                  Button     button15=new   Button("ln");  
                  Button     button16=new   Button("+");  
                  Button     button17=new   Button("DEL");  
                  Button     button18=new   Button("+/-");  
                  Button     button19=new   Button(".");  
                  Button     button20=new   Button("=");  
                  keyPanel.add(button1);  
                  keyPanel.add(button2);  
                  keyPanel.add(button3);  
                  keyPanel.add(button4);  
                  keyPanel.add(button5);  
                  keyPanel.add(button6);  
                  keyPanel.add(button7);  
                  keyPanel.add(button8);  
                  keyPanel.add(button9);  
                  keyPanel.add(button10);  
                  keyPanel.add(button11);  
                  keyPanel.add(button12);  
                  keyPanel.add(button13);  
                  keyPanel.add(button14);  
                  keyPanel.add(button15);  
                  keyPanel.add(button16);  
                  keyPanel.add(button17);  
                  keyPanel.add(button18);  
                  keyPanel.add(button19);  
                  keyPanel.add(button20);  
                  button1.addActionListener(this);    
                  button2.addActionListener(this);  
                  button3.addActionListener(this);  
                  button4.addActionListener(this);  
                  button5.addActionListener(this);  
                  button6.addActionListener(this);  
                  button7.addActionListener(this);  
                  button8.addActionListener(this);  
                  button9.addActionListener(this);  
                  button10.addActionListener(this);  
                  button11.addActionListener(this);  
                  button12.addActionListener(this);  
                  button13.addActionListener(this);  
                  button14.addActionListener(this);  
                  button15.addActionListener(this);  
                  button16.addActionListener(this);  
                  button17.addActionListener(this);  
                  button18.addActionListener(this);  
                  button19.addActionListener(this);  
                  button20.addActionListener(this);  
        }                        
        public   void   actionPerformed(ActionEvent   e){  
                  if(e.getActionCommand()=="button1")   {    
                            if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+7;  
                                                            op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=7/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+7;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=7/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                    }  
                              if(e.getActionCommand()=="button2")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+8;  
                                                              op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=8/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+8;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=8/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                              }  
                              if(e.getActionCommand()=="button3")   {  
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+9;  
                                                            op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  问题点数:0、回复次数:7Top

1 楼feitianfly(feitian)回复于 2003-11-03 19:40:47 得分 0

else{  
                                                            FLAG2++;  
                                                            OP3+=9/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+9;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=9/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }    
                            if(e.getActionCommand()=="button4")   {    
                                        FLAG1=4;    
                                        FLAG2=-1;  
                            }  
                            if(e.getActionCommand()=="button5")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+4;  
                                                            op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=4/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+4;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=4/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }                                
                            if(e.getActionCommand()=="button6")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+5;  
                                                            op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=5/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+5;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=5/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }        
                            if(e.getActionCommand()=="button7")   {  
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+6;  
                                                            op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=6/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+6;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=6/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }  
                            if(e.getActionCommand()=="button8")   {    
                                        FLAG1=8;  
                                        FLAG2=-1;  
                            }  
                            if(e.getActionCommand()=="button9")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+1;  
                                                              op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=1/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                         
   
  else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+1;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=1/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }  
                            if(e.getActionCommand()=="button10")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+2;  
                                                              op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=2/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }Top

2 楼feitianfly(feitian)回复于 2003-11-03 19:41:13 得分 0

 
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+2;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=2/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }  
                            if(e.getActionCommand()=="button11")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+3;  
                                                              op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=3/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+3;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=3/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }  
                            if(e.getActionCommand()=="button12")   {  
                                        FLAG1=12;  
                                        FLAG2=-1;  
                            }  
                            if(e.getActionCommand()=="button13")   {    
                                        if(FLAG1==0){  
                                                    if(FLAG2<0){  
                                                            OP1=10*OP1+0;  
                                                            op=new   Double(OP1);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=0/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP1+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                                        else{  
                                                    if(FLAG2<0){  
                                                            OP2=10*OP2+0;  
                                                            op=new   Double(OP2);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                                    else{  
                                                            FLAG2++;  
                                                            OP3+=0/Math.pow(10,(double)FLAG2);  
                                                            op=new   Double(OP2+OP3);  
                                                            result.setText(op.toString(op.doubleValue()));  
                                                    }  
                                        }  
                            }  
                            if(e.getActionCommand()=="button14")   {    
                                        if(FLAG1==0){  
                                                    OP1=Math.PI;  
                                                    op=new   Double(OP1);  
                                                    result.setText(op.toString(op.doubleValue()));  
                                        }  
                                        else{  
                                                    OP2=Math.PI;  
                                                    op=new   Double(OP2);  
                                                    result.setText(op.toString(op.doubleValue()));  
                                        }              
                              }                
                            if(e.getActionCommand()=="button15")   {  
                                        OP4=Math.log(OP1);  
                                        op=new   Double(OP4);  
                                        result.setText(op.toString(op.doubleValue()));  
                                        FLAG1=0;  
                                        FLAG2=-1;  
                            }  
                            if(e.getActionCommand()=="button16")   {  
                                        FLAG1=16;  
                                        FLAG2=-1;  
                            }  
                            if(e.getActionCommand()=="button17")   {  
                                        result.setText("                                               ");  
                                        FLAG1=0;  
                                        FLAG2=-1;  
                            }  
                            if(e.getActionCommand()=="button18")   {  
                                        if(FLAG1==0){  
                                                    OP1=-1*OP1;  
                                                    op=new   Double(OP1);  
                                                    result.setText(op.toString(op.doubleValue()));  
                                        }  
                                        else{  
                                                    OP2=-1*OP2;  
                                                    op=new   Double(OP2);  
                                                    result.setText(op.toString(op.doubleValue()));  
                                        }  
                            }  
                            if(e.getActionCommand()=="button19")   {  
                                        FLAG2=0;  
                            }  
                            if(e.getActionCommand()=="button20")   {  
                                        switch(FLAG1){  
                                                    case   4:  
                                                                OP4=OP1/OP2;  
                                                                op=new   Double(OP4);  
                                                                result.setText(op.toString(op.doubleValue()));  
                                                                FLAG1=0;  
                                                                FLAG2=-1;break;  
                                                    case   8:  
                                                                OP4=OP1*OP2;  
                                                                op=new   Double(OP4);  
                                                                result.setText(op.toString(op.doubleValue()));  
                                                                FLAG1=0;  
                                                                FLAG2=-1;break;  
                                                    case   12:  
                                                                OP4=OP1-OP2;  
                                                                op=new   Double(OP4);  
                                                                result.setText(op.toString(op.doubleValue()));  
                                                                FLAG1=0;  
                                                                FLAG2=-1;break;  
                                                    case   16:  
                                                                OP4=OP1+OP2;  
                                                                op=new   Double(OP4);  
                                                                result.setText(op.toString(op.doubleValue()));  
                                                                FLAG1=0;  
                                                                FLAG2=-1;break;  
                                          }  
                            }  
                   
        }  
        public   static   void   main(String[]   args){  
                      /*counterFrame=new   JFrame("Calculator");*/  
                      try   {  
                         
                                        UIManager.setLookAndFeel(  
    UIManager.getCrossPlatformLookAndFeelClassName());  
     
                        }   catch   (Exception   e)   {}  
   
     
                    Calculator   calculator1=new   Calculator();  
                    /*   counterFrame.add(resultPanel);  
                  counterFrame.add(keyPanel);  
                  counterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                  counterFrame.pack();  
                  counterFrame.setVisible(true);*/  
        }  
  }  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  Top

3 楼samus(kmlzkma)回复于 2003-11-03 20:11:12 得分 0

太他妈长了!Top

4 楼zhanghuazhanghome(517(张))回复于 2003-11-03 20:15:16 得分 0

构建器应为public   Calculator(){},那有void啊!Top

5 楼zhanghuazhanghome(517(张))回复于 2003-11-03 20:28:57 得分 0

counterFrame.add(resultPanel);  
  counterFrame.add(keyPanel);  
   
  改为  
   
  counterFrame.getContentPane().add(resultPanel);  
  counterFrame.getContentPane().add(keyPanel);Top

6 楼d992901(沉思)回复于 2003-11-03 20:55:59 得分 0

jFrame.setVisible(true);  
  写的好乱阿,ft  
  Top

7 楼feitianfly(feitian)回复于 2003-11-03 22:38:18 得分 0

谢谢zhanghuazhanghome,你是对的,解决了让我们很郁闷的问题  
  也代我同学谢谢你Top

相关问题

  • 大家帮帮忙,Delphi无法直接运行,程序界面一闪而过,但是编译exe文件成功.
  • 编译后,程序界面出不了是什么回事?
  • vfp程序编译成EXE文件后,为什么菜单一闪而过???
  • 程序编译
  • 编译程序
  • 如何改变已经只有编译好的程序的界面?
  • Win98中编译的程序在Win2000中运行时界面问题
  • 一个无用户界面的Active EXE程序如何设置编译后执行程序的图表?
  • 我用dev-c++编译一个程序时,结果一闪而过。如何让其显示啊?
  • vc编译 程序

关键词

  • counterframe
  • keypanel
  • resultpanel
  • jframe
  • jpanel
  • op
  • calculator
  • result
  • import java
  • add

得分解答快速导航

  • 帖主:feitianfly

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo