追加10分,JAVA问题,怎么得到密码框和用户账号框,里面的数据,然后把值赋给变量user和password

追加10分,JAVA问题,怎么得到密码框和用户账号框,里面的数据,然后把值赋给变量user和password,第1张

private void jButton1ActionPerformed(javaawteventActionEvent evt) {

new 菜单界面();

thissetVisible(false);

// TODO add your handling code here:

}

private void jPasswordField1ActionPerformed(javaawteventActionEvent evt) {

password = new String(jPasswordField1getPassword());

}

private void jTextField1ActionPerformed(javaawteventActionEvent evt) {

user = jTextField1getText();

}

JPasswordField jpf=new JPasswordField(允许用户输入的长度),如果放JPF的容器的布局管理器设为NULL时,此长度无效,即设置了长度为10是,还是可以输入N个字符

jpfsetEchoChar(''),设置显示为黑点

只有integer可以判断为空

Integer number;

if(number!=null){

int num = numberintValue();

switch (number){

case 1645:

oneJTextAreaappend(datetimeformat(new Date()) + "\t\ttechnician\n");

oneJPasswordFieldsetText("");

break;

default:

oneJTextAreaappend(datetimeformat(new Date()) +"\t\tAccess Denied\n");

oneJPasswordFieldsetText("");

}

}

应用的还是web的啊

我给你写了个应用的哈

你在C盘建个testtxt文件

里面

username:用户名(这里可以随便写哈)

password:同上哈

注意是要换行的哦。。

比如

username:tiger

password:tiger

然后你建个Login的类

然后把下面的代码弄进去

运行就是了

注意登陆的时候你文件里面设定的什么用户名和密码就输入什么哈

输入错误就会提示输入错误的

import javaioBufferedReader;

import javaioFileReader;

import javaxswingJFrame;

import javaxswingJOptionPane;

/

@author thinkpad

/

public class Login extends javaxswingJFrame {

/ Creates new form Login /

private static String username;

private static String password;

public Login() {

initComponents();

try {

BufferedReader br = new BufferedReader(new FileReader("C:\\testtxt"));

username = brreadLine()split("\\:")[1];

password = brreadLine()split("\\:")[1];

Systemoutprintln(username + password);

} catch(Exception e) {

eprintStackTrace();

}

}

/ This method is called from within the constructor to

initialize the form

WARNING: Do NOT modify this code The content of this method is

always regenerated by the Form Editor

/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jPanel1 = new javaxswingJPanel();

jLabel1 = new javaxswingJLabel();

jLabel2 = new javaxswingJLabel();

jLabel3 = new javaxswingJLabel();

jTextField1 = new javaxswingJTextField();

jPasswordField1 = new javaxswingJPasswordField();

jButton1 = new javaxswingJButton();

jButton2 = new javaxswingJButton();

setDefaultCloseOperation(javaxswingWindowConstantsEXIT_ON_CLOSE);

jLabel1setFont(new javaawtFont("宋体", 0, 18)); // NOI18N

jLabel1setText("Login");

jLabel2setText("Username:");

jLabel3setText("Password:");

jTextField1addActionListener(new javaawteventActionListener() {

public void actionPerformed(javaawteventActionEvent evt) {

jTextField1ActionPerformed(evt);

}

});

jPasswordField1addActionListener(new javaawteventActionListener() {

public void actionPerformed(javaawteventActionEvent evt) {

jPasswordField1ActionPerformed(evt);

}

});

jButton1setText("Login");

jButton1addActionListener(new javaawteventActionListener() {

public void actionPerformed(javaawteventActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

jButton2setText("Reset");

jButton2addActionListener(new javaawteventActionListener() {

public void actionPerformed(javaawteventActionEvent evt) {

jButton2ActionPerformed(evt);

}

});

javaxswingGroupLayout jPanel1Layout = new javaxswingGroupLayout(jPanel1);

jPanel1setLayout(jPanel1Layout);

jPanel1LayoutsetHorizontalGroup(

jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING)

addGroup(jPanel1LayoutcreateSequentialGroup()

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING)

addGroup(jPanel1LayoutcreateSequentialGroup()

addGap(28, 28, 28)

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING, false)

addGroup(jPanel1LayoutcreateSequentialGroup()

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING)

addComponent(jLabel2)

addComponent(jLabel3))

addGap(33, 33, 33)

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentTRAILING, false)

addComponent(jPasswordField1, 0, 0, ShortMAX_VALUE)

addComponent(jTextField1, javaxswingGroupLayoutDEFAULT_SIZE, 108, ShortMAX_VALUE)))

addGroup(jPanel1LayoutcreateSequentialGroup()

addComponent(jButton1)

addPreferredGap(javaxswingLayoutStyleComponentPlacementRELATED, javaxswingGroupLayoutDEFAULT_SIZE, ShortMAX_VALUE)

addComponent(jButton2))))

addGroup(jPanel1LayoutcreateSequentialGroup()

addGap(101, 101, 101)

addComponent(jLabel1)))

addContainerGap(javaxswingGroupLayoutDEFAULT_SIZE, ShortMAX_VALUE))

);

jPanel1LayoutsetVerticalGroup(

jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING)

addGroup(jPanel1LayoutcreateSequentialGroup()

addContainerGap()

addComponent(jLabel1)

addGap(18, 18, 18)

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentBASELINE)

addComponent(jTextField1, javaxswingGroupLayoutPREFERRED_SIZE, javaxswingGroupLayoutDEFAULT_SIZE, javaxswingGroupLayoutPREFERRED_SIZE)

addComponent(jLabel2))

addGap(18, 18, 18)

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentBASELINE)

addComponent(jPasswordField1, javaxswingGroupLayoutPREFERRED_SIZE, javaxswingGroupLayoutDEFAULT_SIZE, javaxswingGroupLayoutPREFERRED_SIZE)

addComponent(jLabel3))

addPreferredGap(javaxswingLayoutStyleComponentPlacementRELATED, 35, ShortMAX_VALUE)

addGroup(jPanel1LayoutcreateParallelGroup(javaxswingGroupLayoutAlignmentBASELINE)

addComponent(jButton1)

addComponent(jButton2)))

);

javaxswingGroupLayout layout = new javaxswingGroupLayout(getContentPane());

getContentPane()setLayout(layout);

layoutsetHorizontalGroup(

layoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING)

addGroup(layoutcreateSequentialGroup()

addContainerGap()

addComponent(jPanel1, javaxswingGroupLayoutPREFERRED_SIZE, javaxswingGroupLayoutDEFAULT_SIZE, javaxswingGroupLayoutPREFERRED_SIZE)

addContainerGap(javaxswingGroupLayoutDEFAULT_SIZE, ShortMAX_VALUE))

);

layoutsetVerticalGroup(

layoutcreateParallelGroup(javaxswingGroupLayoutAlignmentLEADING)

addGroup(javaxswingGroupLayoutAlignmentTRAILING, layoutcreateSequentialGroup()

addComponent(jPanel1, javaxswingGroupLayoutDEFAULT_SIZE, javaxswingGroupLayoutDEFAULT_SIZE, ShortMAX_VALUE)

addContainerGap())

);

pack();

}// </editor-fold>

private void jPasswordField1ActionPerformed(javaawteventActionEvent evt) {

// TODO add your handling code here:

}

private void jTextField1ActionPerformed(javaawteventActionEvent evt) {

// TODO add your handling code here:

}

private void jButton2ActionPerformed(javaawteventActionEvent evt) {

thisjTextField1setText("");

thisjPasswordField1setText("");

}

private void jButton1ActionPerformed(javaawteventActionEvent evt) {

String inputUsername = thisjTextField1getText();

String inputPassword = StringvalueOf(thisjPasswordField1getPassword());

if(inputUsernameequals(username) && inputPasswordequals(password)) {

JOptionPaneshowMessageDialog(this, "Login success!");

} else {

JOptionPaneshowMessageDialog(this, "Login failed!");

}

}

/

@param args the command line arguments

/

public static void main(String args[]) {

javaawtEventQueueinvokeLater(new Runnable() {

public void run() {

JFramesetDefaultLookAndFeelDecorated(true);

Login login = new Login();

loginsetVisible(true);

loginsetLocationRelativeTo(null);

}

});

}

// Variables declaration - do not modify

private javaxswingJButton jButton1;

private javaxswingJButton jButton2;

private javaxswingJLabel jLabel1;

private javaxswingJLabel jLabel2;

private javaxswingJLabel jLabel3;

private javaxswingJPanel jPanel1;

private javaxswingJPasswordField jPasswordField1;

private javaxswingJTextField jTextField1;

// End of variables declaration

}

以上就是关于追加10分,JAVA问题,怎么得到密码框和用户账号框,里面的数据,然后把值赋给变量user和password全部的内容,包括:追加10分,JAVA问题,怎么得到密码框和用户账号框,里面的数据,然后把值赋给变量user和password、java输入密码黑点怎么形成、java中写个密码输入的程序,当输入为空时,就按确认键,d出提示等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10073279.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存