| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:程序运行有错误
只看楼主 加入收藏
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
结帖率:100%
收藏
 问题点数:0 回复次数:1 
程序运行有错误
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;  // 导入包
import java.util.*;
class  DENGRU extends JFrame implements ActionListener //导入接
口类
{
    JPanel p1,p2,p3;      //定义3个面板
    JLabel l1,l2,l3,l4;   //定义4个标签
    JPasswordField pswf;  //定义一个密码文本
    JButton jb1,jb2,jb3;  //定义3个按钮
    JTextField jtf1;      //定义一个文本框
    JComboBox jc1;        //定义一个组合框
    ImageIcon myimage;    //定义导入图片
    Container content;    //定义一个容器
    Guest[] g=new Guest[4];  //定义客户类数组
   
    public DENGRU()       //布局
      {      
        g[0]=new Guest("chengchao","888888",5000);//客户类
数组里给的帐号,密码,钱数
        g[1]=new Guest("baijing","888888",5000);
        g[2]=new Guest("gaolingling","888888",5000);
        g[3]=new Guest("zhaofengying","888888",5000);
        p1 = new JPanel();                        //定
义第一个面板
        myimage = new ImageIcon("yl1.jpg");       //定
义填入的图片
        l1 = new JLabel(myimage);                 //定
义把图片放在标签的上面
        p1.add(l1);
   
         
        p2 = new JPanel();                        //定义第
二个面板
        l2 = new JLabel("卡号:");                //定
义标签l2         
          jc1 = new JComboBox();                    //定义组合框
          jc1.addItem( "chengchao" );               //组合框里赋

        jc1.addItem("baijing");
        jc1.addItem("zhaofengying");
        jc1.addItem("gaolingling");
          jc1.setSelectedIndex( 0 );                //组合框里的
下标从0开始
          jc1.setEditable(true);                    //里面还可以
输入
          l3=new JLabel("密  码:");                //定义标签l3
           pswf=new JPasswordField(12);              //定义密码文

        l4 = new JLabel("如果没有账号请注册");    //定
义标签l4
        jb3 = new JButton("注册");                //添
加注册按钮
        
        p2.add(l2);                               //把它们分别
镶在面板上
        p2.add(jc1);
        p2.add(l3);
        p2.add(pswf);
        p2.add(l4);
        p2.add(jb3);
        
        p3 = new JPanel();                        //定
义第三个面板  
        jb1 = new JButton("登录");                //定义按钮登
录jb1
        jb1.addActionListener(this);              //jb1
申请监听
        jb2 = new JButton("注销");                //定
义按钮注销jb2
        jb2.addActionListener(this);              //jb2
申请监听
        p3.add(jb1);                              //把
它们添加到p3面板里
        p3.add(jb2);
        content = this.getContentPane();          //布局定义
        content.setLayout(new BorderLayout());     
        content.add(p1,BorderLayout.NORTH);       //定义顶部为
面板p1
        content.add(p2,BorderLayout.CENTER);      //定义中部为
面板p2
        content.add(p3,BorderLayout.SOUTH);          //定
义底部为面板p3
        this.pack();
        this.setTitle("ATM 柜员机");              //定义为
窗口名称
        this.setSize(600,300);                    // 定义窗
口的大小
        this.setResizable(false);
        this.show();                             //显示
        this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE  
);// 关闭、退出
 }
 public void actionPerformed(ActionEvent e )   //监听类
    {String x= jc1.getSelectedItem().toString();  //把jc1的
值强制转换成字符
        if(e.getSource()==jb1)                //如果点
击是jb1按钮就进入For
        {
            for(int i=0;i<4;i++)                  
//判断名字在数组的位置
            if(x.equals(g[i].zh))                  
//检查到开始判断是否匹配
            {         
          if(pswf.getText().equals(g[i].pswf)) //名字匹配成功后
判断密码是否成功
                {
                          new KQ(g[i]);      
      //密码真确后进入KQ的界面
                     setVisible( false);
                 }
                 else
                {
                       JOptionPane.showMessageDialog( this,"密
码错误,拒绝登陆"); //密码错误弹出提示密码错误
                }
               }
        }
           else
        System.exit(0);   //注销事件退出
    }



 public static void main(String args[])   //定义的MAIN,才能进
入。
  {
        new DENGRU();
         
  }
}

public class  KQ extends JFrame implements ActionListener  //导
入接口类
{
    JPanel p1,p2,p3;                                       //定
义3个面板
    JLabel l1;                                             
//定义1个标签
    JButton jb1,jb2,jb3,jb4,jb5;                           
//定义5个按钮
    ImageIcon myimage;                                      
//定义导入图片
    Container content;                                      
//定义一个容器

    Guest key;                                             //定
义客户类传从参数key
    public KQ(Guest key)
      {      
        this.key =key;                                     //把
key传到顶层容器
        p1 = new JPanel();                              
   //定义第一个面板
        myimage = new ImageIcon("yl1.jpg");              
   //定义填入的图片
        l1 = new JLabel(myimage);                        
   //定义把图片放在标签的上面
        p1.add(l1);
        p2 = new JPanel();                                 //定
义第二个面板                                 
        jb1 = new JButton("ATM取款");                    
   //定义jb1按钮ATM取款
          jb1.addActionListener(this);                  
     //jb1申请监听
        jb2 = new JButton("ATM存款");                    
   //定义jb2按钮ATM存款
          jb2.addActionListener(this);                  
     //jb2申请监听
        jb3 = new JButton("查询余额 ");                  
   //定义jb3按钮查询余额
          jb3.addActionListener(this);                  
     //jb3申请监听
        jb4 = new JButton("修改密码");                  
   //定义jb4按钮修改密码
          jb4.addActionListener(this);                  
     //jb4申请监听
        p2.add(jb1);
        p2.add(jb2);
        p2.add(jb3);
        p2.add(jb4);

        p3 = new JPanel();                              
  //定义第三个面板
        jb5 = new JButton("退出");                        //定
义jb5按钮退出                                             
        jb5.addActionListener(                           
  //定义一个匿名类
         new ActionListener()
         {
            public void actionPerformed( ActionEvent event )
            {
               System.exit(0);        //退出登陆
            }
 
         }
      );
        p3.add(jb5);
   content = this.getContentPane();                  //布局定义
   content.setLayout(new BorderLayout());
   content.add(p1,BorderLayout.NORTH);               //定义顶部
为面板p1
   content.add(p2,BorderLayout.CENTER);              //定义中部
为面板p2
   content.add(p3,BorderLayout.SOUTH);               //定义底部
为面板p3
    this.pack();
    this.setTitle("进入界面");                      //定义
为窗口名称
    this.setSize(400,300);                          // 定义
窗口的大小
    this.setResizable(false);
    this.show();
 }


public void actionPerformed ( ActionEvent event ) //接口监听
   {
            
        if (event.getSource()==jb4 )              //判断是否是
jb4
         {         
            
                     new Xgmm(key);         
      //进入Xgmm
                    setVisible( false);
                     }
         if (event.getSource()==jb1 )             //判断是否是
jb1
         {         
            
                         new Zdqk(key);      
      //进入Zdqk
                     setVisible( false);
                     }

         
        if (event.getSource()==jb2 )              //判断是否是
jb2
         {         
            
                         new Zdck(key);      
      //进入Zdck
                     setVisible( false);
                     }

         
        if (event.getSource()==jb3 )              //判断是否是
jb3
         {         
            
                         new Cxye(key);      
      //进入Cxye
                     setVisible( false);
                     }   

     }   
 }

class  Guest   // 定义客户类
{
    String zh;   //定义账号
    String pswf; //定义密码
    double jine; //定义金额

    public Guest(){}  //构造Guest
   
    public Guest(String zh,String pswf,double jine)
    {
        this.zh=zh;  //带入顶层容器,账号,密码,金额
        this.pswf=pswf;
        this.jine=jine;
    }

    String getzh() //定义成员变量账号
    {
        return zh; //成员方法
    }

    double setMima(double pswf)//定义成员变量密码
    {
        return pswf;//成员方法
    }


   double getJine()//定义成员变量金额
   {
        return jine;//定义成员方法
   }

   void cunkuan(double money)//定义成员变量存款
   {
        jine=jine+money;     //定义成员方法
   }

   void quqian(double money)//定义成员变量取款
   {
         jine=jine-money;    //定义成员方法
   }
   String xiugaim(String mi)//定义成员变量密码
   {
         pswf = mi;          //定义成员方法
         return pswf;
     }

}
import javax.swing.*;
class Zdck extends JFrame implements ActionListener //导入接口

{
    JPanel p1,p2,p3;                                //定义3个面

    JLabel l1;                                      //定义1
个标签
    JButton jb1,jb2;                                //定义2
个按钮
    JTextField jtf1;                                //定义
一个文本框
    ImageIcon myimage;                              //定义
导入图片
    Container content;                              //定义
一个容器
    Guest key;                                      //定义
客户类传从参数key
public Zdck(Guest key){
   this.key=key;                                 //把key传到顶
层容器
   p1=new JPanel();                              //定义第一个面

   myimage = new ImageIcon("yl1.jpg");           //定义填入的图

   l1 = new JLabel(myimage);                     //定义把图片放
在标签的上面
   p1.add(l1);
      
   p2=new JPanel();                              //定义第二个面

       l1=new JLabel("请输入您要存入的金额:");      //定义一个
标签请输入您要存入的金额:
   jtf1 = new JTextField(10);                    //定义一个文本
               
   p2.add(l1);
   p2.add(jtf1);

   p3=new JPanel();                              //定义第三个面

   jb1=new JButton("确定");                      //定义一个按钮
确定
   jb1.addActionListener(this);                  //jb1申请一个
监听
   jb2=new JButton("返回");                      //定义一个按钮
返回
       jb2.addActionListener(                        //定义一个
匿名类监听
      new ActionListener()
          {
                public void actionPerformed(ActionEvent event)
                 {
                       KQActionPerformed(event);
                 }
          }
          );
   p3.add(jb1);
   p3.add(jb2);
content=this.getContentPane();                //布局定义
content.setLayout(neBorderLayout());
content.add(p1,BorderLayout.NORTH);         //定义顶部为面板p1   
                              content.add
(p2,BorderLayout.CENTER);                //定义中部为面板p2
      content.add(p3,BorderLayout.SOUTH);           //定义
底部为面板p3
      this.pack();
      this.setTitle("自         款");           //定义
为窗口名称
      this.setSize(320,300);                        // 定义
窗口的大小
      this.setResizable(false);
      this.show();                                  //显示
      }
       public void actionPerformed (ActionEvent e)  //接口
监听类
          {   
             if(e.getSource()==jb1)                   //判断是是
否是jb1
             {
                 double money = Double.parseDouble(jtf1.getText
());// 把money转成Double
            JOptionPane.showMessageDialog(this,"成功取
款"+jtf1.getText()+"元!");//一个提示框填出你成功存了多少
              key.cunkuan(money);                    //把存的
钱传回客户类
              jtf1.setText("0");                       
              return;
              }
          }   
              
      public void KQActionPerformed ( ActionEvent event )  
//匿名类监听过程
   {
         if (event.getSource()==jb2 )                     //判
断要是jb2
         {         
            
                         new KQ(key);        
              //返回KQ界面
                     setVisible( false);
                     }
         }   
}
class Zdqk extends JFrame implements ActionListener //导入接口

{
    JPanel p1,p2,p3;                                //定义3
个面板
    JLabel l1;                                      //定义1
个标签
    JButton jb1,jb2;                                //定义2
个按钮
    JTextField jtf1;                                //定义
一个文本框
    ImageIcon myimage;                              //定义
导入图片
    Container content;                              //定义
一个容器
    Guest key;                                      //定义客户
类传从参数key
      public Zdqk(Guest key){
      this.key=key;                                 //把key传到
顶层容器
      p1=new JPanel();                              //定义
第一个面板
      myimage = new ImageIcon("yl1.jpg");           //定义填入
的图片        
      l1 = new JLabel(myimage);                     //定义把图
片放在标签的上面
      p1.add(l1);
      
      p2=new JPanel();                             //定义第
二个面板
      l1=new JLabel("请输入您要取的金额:");        //定义
一个标签请输入您要取的金额:
      jtf1 = new JTextField(10);                   //定义一
个文本框
      p2.add(l1);
      p2.add(jtf1);

      p3=new JPanel();                             //定义第
三个面板
      jb1=new JButton("确定");                     //定义一
个按钮确定
      jb1.addActionListener(this);                 //jb1申
请一个监听
      jb2=new JButton("返回");                     //定义一
个按钮返回
      jb2.addActionListener(this);                 //jb1申
请一个监听
      p3.add(jb1);
      p3.add(jb2);
      content=this.getContentPane();               //布局定

      content.setLayout(new BorderLayout());
      content.add(p1,BorderLayout.NORTH);          //定义顶
部为面板p1
      content.add(p2,BorderLayout.CENTER);         //定义中
部为面板p2
      content.add(p3,BorderLayout.SOUTH);          //定义底
部为面板p3
      this.pack();                                         
      this.setTitle("自         款");          //定义为
窗口名称                 
      this.setSize(320,300);                       // 定义
窗口的大小
      this.setResizable(false);
      this.show();
 }
      
      public void actionPerformed (ActionEvent e)   //接口监听

          {   
             if(e.getSource()==jb1)                   //判断是是
否是jb1
             {
                 
              double money = Double.parseDouble(jtf1.getText
());// 把money转成Double
              if(money<key.jine)
              {
            JOptionPane.showMessageDialog(this,"成功取
款"+jtf1.getText()+"元!");//一个提示框填出你成功取了多少
              key.quqian(money);                       //把存
的钱传回客户类
              jtf1.setText("0");
              return;
              }
              else
              {
              JOptionPane.showMessageDialog(this,"你的卡即将
要已透支");//一个提示框提示你你的卡即将要已透支
              }
         }
              
            if (e.getSource()==jb2 )//判断是是否是jb2
            {         
            
                   new KQ(key);    //放回KQ
            setVisible( false);
             }
              
          }

}
class Cxye extends JFrame implements ActionListener  //导入接口

{
    JPanel p1,p2,p3;                                 //定义
3个面板
    JLabel l1;                                       //定义
1个标签
    JButton jb1;                                     //定义
3个按钮     
    ImageIcon myimage;                               //定义
导入图片
    Container content;                               //定义
一个容器
    Guest key;                                       //定义
客户类传从参数key

      public Cxye(Guest key){         
      this.key=key;                                  //把key传
到顶层容器
      p1=new JPanel();                               //定义第一
个面板
      myimage = new ImageIcon("yl1.jpg");            //定义填入
的图片
      l1 = new JLabel(myimage);                      //定义把图
片放在标签的上面
      p1.add(l1);
      
      p2=new JPanel();                               //定义
第二个面板
      l1=new JLabel("您的剩余金额为:"+ key.getJine());?
      p2.add(l1);
      
      
      p3=new JPanel();                               //定义
第三个面板
      jb1=new JButton("返回");
       jb1.addActionListener(this);
      p3.add(jb1);
      content=this.getContentPane();                  //布
局定义
      content.setLayout(new BorderLayout());
      content.add(p1,BorderLayout.NORTH);             //定
义顶部为面板p1
      content.add(p2,BorderLayout.CENTER);            //定
义中部为面板p2
      content.add(p3,BorderLayout.SOUTH);             //定
义底部为面板p3
      this.pack();
      this.setTitle("查      额");                //定
义为窗口名称
      this.setSize(320,300);                          // 定
义窗口的大小
      this.setResizable(false);
      this.show();
      }

      public void actionPerformed ( ActionEvent e )    //接
口监听类
   {
         if (e.getSource()==jb1 )                       //判断
是否是jb1                     
         {         
            
                         new KQ(key);        
            //放回KQ
                     setVisible( false);
                     }

         }   

}
class  Xgmm extends JFrame implements ActionListener  //导入接
口类
{
    JPanel p1,p2,p3;                                 //定义
3个面板
    JLabel l1, l2, l3, l4;                           //定义
4个标签
    JTextField jtf1,jtf2,jtf3;                       //定义
3个文本框
    JButton jb1,jb2;                                 //定义
2个按钮
    ImageIcon myimage;                               //定义
导入图片
    Container content;                               //定义
一个容器
    Guest key;                                      //定义
客户类传从参数key
    public Xgmm(Guest key)
{
        this.key=key;                              //把
key传到顶层容器
        p1 = new JPanel();                         //定
义第一个面板
        myimage = new ImageIcon("yl1.jpg");        //定
义填入的图片
        l1 = new JLabel(myimage);                 //定
义把图片放在标签的上面                                
        p1.add(l1);
     
        
        p2=new JPanel();                           //定
义第二个面板
        l2=new JLabel("请输入原始密码:");       //定义
标签请输入原始密码:
        l3=new JLabel("输入要修改的密码:");      //定
义标签输入要修改的密码
        l4=new JLabel("确认输入的新密码:");     //定义
标签确认输入的新密码:
        jtf1=new JTextField(15);                 //定义
文本框jtf1
        jtf2=new JTextField(15);                 //定义
文本框jtf2
        jtf3=new JTextField(15);                 //定义文本框
jtf3
        p2.add(l2);
        p2.add(jtf1);
        p2.add(l3);
        p2.add(jtf2)
        p2.add(l4);
        p2.add(jtf3)


        p3=new JPanel();                             //
定义第三个面板
         jb1 = new JButton("确定");                  //定义按钮
jb1 确定
         jb1.addActionListener(this);                //jb1申请
监听               
         jb2 = new JButton("放回登录");              //
定义按钮jb2 放回登录
         jb2.addActionListener(this);                 
//jb2申请监听
         p3.add(jb1);
         p3.add(jb2);
         content = this.getContentPane();            //布局定义
         content.setLayout(new BorderLayout());
         content.add(p1,BorderLayout.NORTH);         //定义顶部
为面板p1
         content.add(p2,BorderLayout.CENTER);        //定义中部
为面板p2
         content.add(p3,BorderLayout.SOUTH);         //
定义底部为面板p3        
         this.pack();
         this.setTitle("修      码");            //
定义为窗口名称
         this.setSize(400,350);                      // 定
义窗口的大小
         this.setResizable(false);
         this.show();                                //显示
         }
         public void actionPerformed(ActionEvent e)  //
接口监听类
        {
            if(e.getSource()==jb1)                  
 //判断是否是jb1
                if(jtf1.getText().equals
(key.pswf))  //判断是否是你输入的pswf正确
                {
                    if (jtf2.getText
().equals(jtf3.getText()))//判断是否是jtf2和jtf3相等不
                    {
                        key.xiugaim
(jtf2.getText()); //把改的密码传回Guest类中
    JOptionPane.showMessageDialog( this,"修改成功!"); //定
义一个提示框成功
                        jtf1.setText
("");
                        jtf2.setText
("");
                        jtf3.setText
("");
                    }
                    else
                    {
                        jtf2.setText
("");
                        jtf3.setText
("");
                        JOptionPane.showMessageDialog( this,"两
次输入密码不相符,请确认后重新输入!");//定义一个提示栏不成功
                    }
                }
              else
                  {
                       
JOptionPane.showMessageDialog( this,"密码输入错误,请确认后重新
输入!");//定义一个提示栏原密码错误
                      jtf1.setText("");
                    jtf2.setText("");
                    jtf3.setText("");
                  }
            if(e.getSource()==jb2)   //判断是是否是
jb2
            {
                new DENGRU();        //返回
DENGRU
                setVisible( false);
            }
     
         }
   
}


搜索更多相关主题的帖子: 文本框 图片 密码 
2011-06-12 00:52
xy2bl
Rank: 1
等 级:新手上路
帖 子:61
专家分:2
注 册:2010-12-2
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2011-06-12 00:59
快速回复:程序运行有错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033172 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved