资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java登录界面代码退出 java登录界面代码退出了

java登录页面,当登录失败超过3次程序退出

你那代码也太难看了,以前写的简单供你参考

成都创新互联公司云计算的互联网服务提供商,拥有超过13年的服务器租用、乐山服务器托管、云服务器、雅安服务器托管、网站系统开发经验,已先后获得国家工业和信息化部颁发的互联网数据中心业务许可证。专业提供云主机、雅安服务器托管主机域名、VPS主机、云服务器、香港云服务器、免备案服务器等。

import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class Logon {

private JFrame f = new JFrame("Logon");

private JTextField username = new JTextField(10);

private JPasswordField password = new JPasswordField(10);

private JLabel user = new JLabel("User");

private JLabel pwd = new JLabel("Password");

private JButton logon = new JButton("Logon on");

private int count = 0;

public Logon(){

JPanel p = new JPanel();

p.setLayout(new GridLayout(2, 2));

p.add(user);

p.add(username);

p.add(pwd);

p.add(password);

f.add(p, BorderLayout.NORTH);

f.add(logon, BorderLayout.SOUTH);

logon.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent e) {

if(count 3){

if(username.getText().trim().equals("") || password.getText().trim().equals("")){

JOptionPane.showMessageDialog(null, "Password/Username is blank. Please input!");

return;

}

if(username.getText().equals("admin") password.getText().equals("abc123")){

JOptionPane.showMessageDialog(null, "Logon on success");

}else{

username.setText("");

password.setText("");

JOptionPane.showMessageDialog(null, "Username/password incorrect. Please try again");

count++;

}

}else{

JOptionPane.showMessageDialog(null, "You have tried 3 times. Program exit!");

System.exit(0);

}

}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mousePressed(MouseEvent e) {}

public void mouseReleased(MouseEvent e) {}

});

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

f.setBounds(200, 200, 400, 400);

f.pack();

}

public static void main(String[] args) {

new Logon();

}

}

java 中 有1.注册 2.登录 3.退出功能 我输入一 就实现注册然后返回 选择2就能登录 提供以下代码

不要复杂化,代码要简单化,需求是什么就写什么。参考如下:

//用于保存用户帐户信息的数组

Scanner scanner = new Scanner(System.in);

String[] user = new String[2]; 

while (true) {

//银行主界面

System.out.println("------------------------------欢迎来到银行------------------------------");

System.out.println("请选择编号:\n1:注册\n2:登录\n3退出");

int num = scanner.nextInt();

switch (num) {

case 1:

//注册

System.out.println("请输入您的账户名:");

String name = scanner.next();

user[0] = name;

System.out.println("请输入您的密码:");

String password = scanner.next();

user[1] = password;

System.out.println("注册成功!");

//返回主界面

break;

case 2:

while (true) {

//登录

System.out.println("请输入您的帐户名:");

String userName = scanner.next();

System.out.println("请输入您的密码:");

String userPwd = scanner.next();

//判断输入的用户名是否在数组中存在(判断该用户是否注册)

if(user[0].equals(userName)user[1].equals(userPwd)){

System.out.println("-----------登录成功,请选择您要办理的业务------------");

break;

}else{

System.out.println("-----------用户名或密码错误,请重新输入------------");//返回到登录界面

continue;

}

}

break;

case 3:

//退出系统 程序结束

System.out.println("退出成功,欢迎再次使用");

System.exit(0);

break;

default:

break;

}

}

实现界面登陆,退出功能的java代码怎么写?

CS结构系统的退出如下:public void init() {

this.setTitle("用户登录界面");

this.add(createCenterPane());

this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);

this.setSize(new Dimension(450, 335));

this.setLocationRelativeTo(null);

// this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",

"系统提示:", JOptionPane.YES_NO_OPTION);

if (choose == JOptionPane.YES_OPTION) {

System.exit(1);

}

}

});

}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!

实现 界面登陆 退出 功能的java代码杂写

CS结构系统的退出如下:public void init() {

this.setTitle("用户登录界面");

this.add(createCenterPane());

this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);

this.setSize(new Dimension(450, 335));

this.setLocationRelativeTo(null);

// this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",

"系统提示:", JOptionPane.YES_NO_OPTION);

if (choose == JOptionPane.YES_OPTION) {

System.exit(1);

}

}

});

}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!


分享题目:java登录界面代码退出 java登录界面代码退出了
分享路径:http://cdkjz.cn/article/ddjhgis.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220