java图形用户界面登录注册_java语言图形用户登录界面代码

本文提供了一个使用Java实现的登录界面代码实例,包括输入框、按钮和验证码功能。用户输入用户名、密码并验证验证码后,可以进行登录操作。代码详细展示了如何创建图形用户界面并处理事件。
摘要由CSDN通过智能技术生成

本文实例为大家分享了java登录界面的具体实现代码,供大家参考,具体内容如下

1. Login.java

package wzb;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Panel;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyEvent;

import java.util.Random;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class Login extends JFrame implements ActionLwww.cppcns.comistener {

String userName;

String password;

String captcha;

public static String randomcaptcha;

public JLabel logoLabel, userNameLabel, passwordLabel, captchaLabel;

public JTextField userNameInput, captchaInput;

public JPasswordField passwordInput;

public JButton login, logout,change;

public Panel panel;

public Login() {

setTitle("µÇ¼½çÃæ");

setSize(400, 300);

setLocationRelativeTo(null);

init();

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_Owww.cppcns.comN_CLOSE);

setResizable(false);

}

public void init() {

setLayout(null);

// logoLabel= new JLabel();

// logoLabel.setIcon(new ImageIcon("E:\\eclipse\\student3\\welcome.gif"));

logoLabel = new JLabel(new ImageIcon("welcome.gif"));

logoLabel.setBounds(125, 10, 150, 70);

add(logoLabel);

userNameLabel = new JLabel("ÓûÃû:");

userNameLabel.setBounds(90, 90, 60, 40);

add(userNameLabel);

userNameInput = new JTextField();

userNameInput.setBounds(150, 100, 150, 20);

add(userNameInput);

passwordLabel = new JLabel("ÃÜ¡¡Âë:");

passwordLabel.setBounds(90, 120, 60, 40);

add(passwordLabel);

passwordInput = new JPasswordField();

passwordInput.setBounds(150, 130, 150, 20);

add(passwordInput);

captchaLabel = new JLabel("ÑÖÂë:");

captchaLabel.setBounds(90, 150, 60, 40);

add(captchaLabel);

captchaInput = new JTextField();

captchaInput.setBounds(150, 160, 70, 20);

add(captchaInput);

panel = new PanelDemo();

panel.setBounds(220, 160, 80, 20);

add(panel);

change = new JButton("»»Ò»»»");

change.setBounds(300, 160, 80, 20);

change.setContentAreaFilled(false);

change.setBorderPainted(false);

add(change);

login = new JButton("µÇ¼£L£©", new ImageIcon("login.gif"));

login.setBounds(70, 200, 120, 30);

login.setMnemonic(KeyEvent.VK_L);

add(login);

logout = new JButton("Í˳ö£X£©", new ImageIcon("exit.gif"));

logout.setBounds(210, 200, 120, 30);

logout.setMnemonic(KeyEvent.VK_X);

add(logout);

userNameInput.addActionListener(this);

passwordInput.addActionListener(this);

captchaInput.addActionListener(this);

login.addActionListener(this);

logout.addActionListener(this);

change.addActionListener(this);

}

public void actionPerformewww.cppcns.comd(ActionEvent e) {

userName = userNameInput.getText();

password = new String(passwordInput.getPassword());

captcha = captchaInput.getTtGfTvZext();

if (e.getSource() == change) {

panel.repaint();

}

if (e.getSource() == login) {

if ((userName.equals("w")) && (password.equals("w"))) {

if (captcha.equals(randomcaptcha)) {

JOptionPane.showMessageDialog(this, "»¶Ó­µÇ½!");

} else {

JOptionPane.showMessageDialog(this, "ÑÖÂë´Î!");

panel.repaint();

}

} else {

JOptionPane.showMessageDialog(this, "ÓûÃû»ÃÜÂë´Î!");

}

}

if (e.getSource() == logout) {

JOptionPane.showMessageDialog(this, "»¶Ó­Ï´ÎÔÙÀ´£¡");

//System.exit(0);

dispose();

}

}

public static void main(String[] args) {

new Login();

}

}

class PanelDemo extends Panel {

public void paint(Graphics g) {

int width = 80;

int height = 20;

g.setColor(Color.LIGHT_GRAY);

g.fillRect(0, 0, width, height);

g.setColor(Color.BLACK);

g.drawRect(0, 0, width, height);

Random rd = new Random();

for (int i = 0; i < 100; i++) {

int x = rd.next

2. 捕获.PNG

8054d94b8fb6932ea8168ea0e919ee27.png

以上就是本文的全部内容,希望对大家学习java程序设计有所帮助。

本文标题: java语言图形用户登录界面代码

本文地址: http://www.cppcns.com/ruanjian/java/153826.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值