怎么这个 小程序不能实现?请教
功能点击“登陆”后,能像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();
}
}