用JAVA制作一个登陆界面,按登陆的话,如果密码错误,则在控制台上显示登陆失败,反之,则显示登陆成功
关注:68 答案:3 mip版
解决时间 2021-01-31 10:22
提问者非莪莫属
2021-01-30 19:21
请大家尽快做出答案 ,谢谢
最佳答案
二级知识专家那年仲夏
2021-01-30 20:21
不用数据库验证阿?
%>
if(flag){
%>
登录成功
}else{
%>
登录失败
}
%>
你递交到数据库,验证后,把flag用request.setAttribue();传递过来就行了.成功就让flag=ture;
错误就让flag为false.当然.方法多的是.
全部回答
1楼等待、埖开
2021-01-30 21:42
你有点2吧,在控制台上显示的话,用户能知道吗?!!!自己学习一下吧,jsp最基本的功能了,这个还不会你还学什么jsp啊!!
2楼嘴硬欠吻
2021-01-30 20:55
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class loginWindow extends javax.swing.JFrame {
private JPanel jPanel1;
private JButton bntLogin;
private JButton bntCannel;
private JPasswordField pwd;
private JTextField username;
private JLabel jLabel1;
private JLabel jLabel2;
public static void main(String[] args) {
loginWindow inst = new loginWindow();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public loginWindow() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(null);
{
jLabel1 = new JLabel();
jPanel1.add(jLabel1);
jLabel1.setText("用户名:");
jLabel1.setBounds(50, 30, 75, 25);
}
{
username = new JTextField("admin");
jPanel1.add(username);
username.setBounds(110, 30, 140, 25);
}
{
jLabel2 = new JLabel();
jPanel1.add(jLabel2);
jLabel2.setText("密 码:");
jLabel2.setBounds(50, 75, 55, 15);
}
{
pwd = new JPasswordField();
jPanel1.add(pwd);
pwd.setBounds(110, 70, 140, 25);
}
{
JButton btnLogin = new JButton();
jPanel1.add(btnLogin);
btnLogin.setText("登陆(L)");
btnLogin.setBounds(40, 120, 80, 30);
btnLogin.addMouseListener(new MouseAdapter() {
@SuppressWarnings("deprecation")
public void mouseClicked(MouseEvent e) {
if (username.getText().equals("admin")
&& pwd.getText().equals("123")) {
JOptionPane.showMessageDialog(loginWindow.this,
"登录成功");
} else {
JOptionPane.showMessageDialog(loginWindow.this,
"密码错误");
}
}
});
JButton btnCancel = new JButton();
jPanel1.add(btnCancel);
btnCancel.setText("退出(Q)");
btnCancel.setBounds(180, 120, 80, 30);
btnCancel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int i=JOptionPane.showConfirmDialog(loginWindow.this, "确定退出?");
if (i==0){
System.exit(0);}
}
});
}
}
pack();
setSize(300, 215);
setResizable(false);
setTitle("登陆窗口");
} catch (Exception e) {
e.printStackTrace();
}
}
}
我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
→点此我要举报以上信息!←
推荐资讯
大家都在看