日期:2014-05-20 浏览次数:20648 次
/*Login.java*/ public class LoginManager extends JFrame { private JPanel contentPane; private JTextField textField; private JPasswordField passwordField; ClientReceive recvThread; String user1 = textField.getText(); String password1 = new String(passwordField.getPassword()); recvThread = new ClientReceive(user1,password1); recvThread.start(); /*CheckMoney.java*/ public class CheckMoney extends Thread { JTextField username; JTextField password; public CheckMoney(JTextField username, JTextField password){ this.username = username; this.password = password; /
------解决方案--------------------
呵呵呵,不好意思了,我也是正在做东西——聊天室,路过这里看见你的问题,就顺便看看了
我见我也用到这样的处理方式,所以就复制粘贴加修改发给你了,,,
/*Login.java*/ public class LoginManager extends JFrame { private JPanel contentPane; private JTextField textField; private JPasswordField passwordField; ClientReceive recvThread; String user1 = textField.getText(); String password1 = new String(passwordField.getPassword()); recvThread = new CheckMoney(user1,password1); recvThread.start(); /*CheckMoney.java*/ public class CheckMoney extends Thread { JTextField username; JTextField password; public CheckMoney(JTextField username, JTextField password){ this.username = username; this.password = password; /
------解决方案--------------------
Thread是程序中的执行线程。Java 虚拟机允许应用程序并发地运行多个执行线程。
start()是Thread下的函数
start()使该线程开始执行;Java 虚拟机调用该线程的 run 方法。
------解决方案--------------------
话说你的这句:String password1 = new String(passwordField.getPassword());
你是不是对密码那个文本字段处理过了啊?(比如说你输入密码的时候,显示回来的格式是 *******)
要是用户名,密码这两个文本字段都是明文的话,
那就改为:String password1 = pasawordtField.getText();
------解决方案--------------------
不过不管你处理没处理过,都改为:String password1 = pasawordtField.getText();试试吧,,,
------解决方案--------------------
我换了一种方法实现窗体间传参
/*login.java*/ static String username; static String password; private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { CheckMoney temp; username = jTextField1.getText(); password=String.valueOf(jPasswordField1.getPassword()); temp = new CheckMoney(); //!! 把两个窗口联系起来 temp.setVisible(true); //设置窗口2为可见 this.setVisible(false);//该窗口隐藏 } /*CheckMoney.java*/ //按钮点击事件响应。 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String str; str=jPasswordField.password;//从登陆窗体获取密码 jTextField1.setText(str); }