| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 536 人关注过本帖
标题:怎么这个 小程序不能实现?请教
只看楼主 加入收藏
林浩
Rank: 2
等 级:论坛游民
帖 子:47
专家分:23
注 册:2011-1-12
结帖率:90.91%
收藏
 问题点数:0 回复次数:0 
怎么这个 小程序不能实现?请教
功能点击“登陆”后,能像QQ一样出现一个登陆中,当滚动条到了100时显示“登陆成功”。
那个事件监听里,警告说 jpb没有被读到, 不知道为什么?


package register;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class MyRegisterFrame extends JFrame
{   
    public void CreatRegisterFrame(String title)
    {
        final JFrame jf = new JFrame(title); //定义容器和各部件;
        Container c = jf.getContentPane();
        c.setLayout(null);
        JLabel jl1 = new JLabel("用户名");
        JLabel jl2 = new JLabel("密码");
        final JTextField jt  = new JTextField("");
        final JPasswordField jp = new JPasswordField("");
        final JButton jb1 = new JButton("登陆");
        final JButton jb2 = new JButton("重置");
        
        jf.setSize(600, 400);
        jf.setVisible(true);
        c.setBackground(Color.lightGray);
        
        jl1.setBounds(150, 100, 100, 50);
        jl2.setBounds(150, 155, 100, 50);
        jt.setBounds(200, 100, 200, 40);
        jp.setBounds(200, 155, 200, 40);
        jb1.setBounds(200, 220, 60, 40);
        jb2.setBounds(280, 220, 60, 40);
        jb1.setForeground(Color.gray);
        jb2.setForeground(Color.gray);
        
        c.add(jl1);  //添加各部件到容器;
        c.add(jl2);
        c.add(jt);
        c.add(jp);
        c.add(jb1);
        c.add(jb2);
        jp.setEchoChar('*');
        
        jb1.addActionListener(new ActionListener()  //为“登陆”按钮添加监听事件;
        {
            public void actionPerformed(ActionEvent e)
            {
                jb1.setForeground(Color.black);
                jb2.setForeground(Color.gray);
                Regist_ProgressBar rbp = new Regist_ProgressBar();
                if (jt.getText().equals("mr") && jp.getText().equals("mrsoft"))
                {
                    //new MyDialog(jf, "登陆成功").setVisibe(true);
                    MyDialog d = new MyDialog(jf, "登陆成功");
                    d.setLocation(200, 200);
                    d.setVisible(true);   
                }
                else
                {
                    //new MyDialog(jf, "用户名或密码错误").setVisible(true);
                    MyDialog d = new MyDialog(jf, "用户名或密码错误");
                    d.setLocation(200, 200);
                    d.setVisible(true);
                }
                jb1.setForeground(Color.gray);
            }
            
        });
        
        jb2.addActionListener(new ActionListener()  //为“重置”按钮添加监听事件;
        {   
            public void actionPerformed(ActionEvent e)
            {
                jb2.setForeground(Color.black);
                jt.setText("");
                jp.setText("");
            }
            
        });
                    
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
   
    public static void main(String[] args)
    {
        new MyRegisterFrame().CreatRegisterFrame("用户登陆窗口");
    }
}

class MyDialog extends JDialog   //自定义对话框类;
{
    public MyDialog(JFrame jf, String str)
    {
        super(jf, "提示信息", true);
        Container c = this.getContentPane();
        c.setLocale(null);
        c.add(new JLabel(str));        
        c.setSize(100, 100);        
    }
}

class Regist_ProgressBar extends JFrame
{
    public Regist_ProgressBar()
    {
        JFrame jf = new JFrame("");
        Container c = jf.getContentPane();
        c.setSize(300, 900);
        
        JLabel jl = new JLabel("登陆中...");
        final JProgressBar jpb = new JProgressBar();
        Thread t;
        c.setVisible(true);

        c.add(jl);
        c.add(jpb);
        c.setBackground(Color.gray);
        jl.setForeground(Color.blue);   
        jl.setBounds(100, 100, 50, 50);
        jpb.setStringPainted(true);   
        jpb.setBounds(190, 210, 100, 100);
        
        t = new Thread(new Runnable()  
        {
            int count = 0;
            public void run()
            {
                while(count <= 100)
                {
                    jpb.setValue(++count);
                    try
                    {
                        Thread.currentThread().sleep(500);
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        });
        t.start();        
    }
}
搜索更多相关主题的帖子: 成功 register package public import 
2011-11-02 08:06
快速回复:怎么这个 小程序不能实现?请教
数据加载中...
 
   



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

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