×

java登录界面代码

java登录界面代码(用java写一个登陆界面代码)

admin admin 发表于2023-08-31 02:57:25 浏览36 评论0

抢沙发发表评论

本文目录

用java写一个登陆界面代码

概述

具体框架使用jframe,文本框组件:JTextField;密码框组件:JPasswordField;标签组件:JLabel;复选框组件:JCheckBox;单选框组件:JRadioButton;按钮组件JButton。

登录界面:

代码实例

import javax.swing.*;

import java.awt.*;   //导入必要的包

public class denglu extends JFrame{

JTextField jTextField ;  //定义文本框组件

JPasswordField jPasswordField;    //定义密码框组件

JLabel jLabel1,jLabel2;

JPanel jp1,jp2,jp3;

JButton jb1,jb2;     //创建按钮

public denglu(){

jTextField = new JTextField(12);

jPasswordField = new JPasswordField(13);

jLabel1 = new JLabel(“用户名“);

jLabel2 = new JLabel(“密码“);

jb1 = new JButton(“确认“);

jb2 = new JButton(“取消“);

jp1 = new JPanel();

jp2 = new JPanel();

jp3 = new JPanel();

//设置布局

this.setLayout(new GridLayout(3,1));

jp1.add(jLabel1); 

jp1.add(jTextField);//第一块面板添加用户名和文本框 

jp2.add(jLabel2);

jp2.add(jPasswordField);//第二块面板添加密码和密码输入框

jp3.add(jb1);

jp3.add(jb2); //第三块面板添加确认和取消

//        jp3.setLayout(new FlowLayout());    //因为JPanel默认布局方式为FlowLayout,所以可以注销这段代码.

this.add(jp1);

this.add(jp2);

this.add(jp3);  //将三块面板添加到登陆框上面

//设置显示

this.setSize(300, 200);

//this.pack();

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

this.setTitle(“登陆“);

}

public static void main(String args){

new denglu();

}

}

拓展内容

java swing包

Swing 是一个为Java设计的GUI工具包。

Swing是JAVA基础类的一部分。

Swing包括了图形用户界面(GUI)器件如:文本框,按钮,分隔窗格和表。

Swing提供许多比AWT更好的屏幕显示元素。它们用纯Java写成,所以同Java本身一样可以跨平台运行,这一点不像AWT。它们是JFC的一部分。它们支持可更换的面板和主题(各种操作系统默认的特有主题),然而不是真的使用原生平台提供的设备,而是仅仅在表面上模仿它们。这意味着你可以在任意平台上使用JAVA支持的任意面板。轻量级组件的缺点则是执行速度较慢,优点就是可以在所有平台上采用统一的行为。

概念解析:

JFrame – java的GUI程序的基本思路是以JFrame为基础,它是屏幕上window的对象,能够最大化、最小化、关闭。JPanel – Java图形用户界面(GUI)工具包swing中的面板容器类,包含在javax.swing 包中,可以进行嵌套,功能是对窗体中具有相同逻辑功能的组件进行组合,是一种轻量级容器,可以加入到JFrame窗体中。。

JLabel – JLabel 对象可以显示文本、图像或同时显示二者。可以通过设置垂直和水平对齐方式,指定标签显示区中标签内容在何处对齐。默认情况下,标签在其显示区内垂直居中对齐。默认情况下,只显示文本的标签是开始边对齐;而只显示图像的标签则水平居中对齐。

JTextField –一个轻量级组件,它允许单行文本。

JPasswordField – 允许我们输入了一行字像输入框,但隐藏星号(*) 或点创建密码(密码)

JButton – JButton 类的实例。用于创建按钮类似实例中的 “Login“。

用JAVA编写一个用户或注册登录界面请哪位高手能够写下具体的代码,谢谢

  1. 效果图

  2. 代码

  3. 《!DOCTYPE html》《html》 《head》 《meta charset=“UTF-8“》 《title》先锋图书馆管理系统-登录《/title》 《style》 *{ margin: 0; padding: 0; list-style: none; } #top{ width: 1000px; height: 95px; margin: 0 auto; margin-top: 25px; } #top_top{ width: 1000px; height: 65px; background: deepskyblue; } #top_top_left{ width: 300px; height: 65px; float: left; } #top_top_left》label{ width: 200px; height: 65px; color: white; float: right; } #top_top_left》#a2{ padding-left: 10px; padding-top: 20px; font-size: 16px; } #top_bottom{ width: 1000px; height: 30px; } #top_bottom_left{ width: 340px; height: 30px; line-height: 30px; font-size: 12px; background: skyblue; color: white; text-indent: 2em; float: left; } #top_bottom_right{ width: 660px; height: 30px; line-height: 30px; font-size: 12px; color: blueviolet; text-align: center; float: right; background: lightskyblue; } #content{ width: 1000px; height: 600px; margin: 0 auto; background:#587FBA; } #content》#text{ width: 1000px; height: 50px; line-height: 50px; padding-top: 100px; font-size: 36px; font-family:“楷体“; font-weight: bold; text-align: center; } #content》#login{ width: 480px; height: 210px; margin-top: 20px; margin-left: 260px; background: #85A0CB; } #content》#login》img{ float: left; } #content》#login》#select{ width: 305px; height: 210px; float: right; } #content》#login》#select》div{ width: 230; height: 30px; margin-left: 30px; } #content》#login》#select》#d1{ margin-top:30px; margin-bottom: 3px; } #content》#login》#select》p{ font-size: 14px; margin-left: 95px; } #bottom{ width: 1000px; height: 35px; line-height: 35px; margin: 0 auto; background: deepskyblue; text-align: center; color: white; } 《/style》 《/head》 《body》 《div id=“top“》 《div id=“top_top“》 《div id=“top_top_left“》 《img src=“img/test/a13.png“ width=“78px“ height=“65px“》《label id=“a2“》先锋图书馆系统管理平台《/label》 《/div》 《/div》 《div id=“top_bottom“》 《div id=“top_bottom_left“》当前位置 : 首页 》 系统管理 》 登录《/div》 《div id=“top_bottom_right“》当前时间 : 《label id=“lable“》《/label》《/div》 《/div》 《/div》 《div id=“content“》 《div id=“text“》欢迎登录先锋图书馆管理系统《/div》 《div id=“login“》 《img src=“img/test/a14.png“  width=“175px“ height=“210px“/》 《form id=“select“》 《div id=“d1“》用户名: 《input type=“text“ /》《/div》 《div》密      码: 《input type=“password“ /》《/div》 《p》 《input type=“radio“ name=“user“ value=“read“/》读者 《input type=“radio“ name=“user“ value=“admin“/》管理员 《/p》《br/》 《p》 《input type=“button“ value=“确定“ style=“width: 50px;“ onclick=“put()“/》 《input type=“reset“ value=“重置“ style=“width: 50px;“/》 《/p》 《/form》 《/div》 《/div》 《div id=“bottom“》欣欣科技有限公司版权所有《/div》 《/body》 《script type=“text/javascript“ src=“JQuery/jquery.js“》《/script》 《script type=“text/javascript“ src=“js/GetCurrentTime.js“》《/script》 《script》     //验证用户名和密码      function put(){     var d = $(“#select》div》input“);//获取用户名和密码     var name = d.value;     var pass = d.value;     var user = null;     var r = document.getElementsByName(“user“);//获取用户类型     for(i=0;i《r.length;i++){     if(r.value;     }     }     //console.log(name + “,“ +pass + “,“ +user);//输出测试     if(user==null){     window.alert(“请选择用户类型!“);     }else if(user==“admin“ && name!=“admin“){     window.alter(“用户名错误!“);     }else if(user==“admin“ && name==“admin“ && pass!=“123456“){     window.alert(“密码错误!“);     }else if(name==“admin“ && pass==“123456“ && user==“admin“){     window.location.href=“work_02_welcome.html“;//在js中在本页面中打开新链接     }else{     window.alert(“用户名错误“);     }     } 《/script》《/html》

如何用JAVA编写一个简单用户登陆界面

什么都不说了 直接给你代码吧package com.moliying.ui;import java.awt.BorderLayout;import java.awt.Container;import java.awt.FlowLayout;import java.awt.List;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedWriter;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.util.ArrayList;import java.util.Arrays;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Login { private JFrame frame = new JFrame(“登录“); private Container c = frame.getContentPane(); private JTextField username = new JTextField(); private JPasswordField password = new JPasswordField(); private JButton ok = new JButton(“确定“); private JButton cancel = new JButton(“取消“); public Login() { frame.setSize(300, 200); frame.setBounds(450, 300, 300, 200); c.setLayout(new BorderLayout()); initFrame(); frame.setVisible(true); } private void initFrame() { // 顶部 JPanel titlePanel = new JPanel(); titlePanel.setLayout(new FlowLayout()); titlePanel.add(new JLabel(“系统管理员登录“)); c.add(titlePanel, “North“); // 中部表单 JPanel fieldPanel = new JPanel(); fieldPanel.setLayout(null); JLabel a1 = new JLabel(“用户名:“); a1.setBounds(50, 20, 50, 20); JLabel a2 = new JLabel(“密 码:“); a2.setBounds(50, 60, 50, 20); fieldPanel.add(a1); fieldPanel.add(a2); username.setBounds(110, 20, 120, 20); password.setBounds(110, 60, 120, 20); fieldPanel.add(username); fieldPanel.add(password); c.add(fieldPanel, “Center“); // 底部按钮 JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); buttonPanel.add(ok); buttonPanel.add(cancel); c.add(buttonPanel, “South“); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(username.getText().toString()); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setVisible(false); } }); } public static void main(String args) {// new Login(); String ss = “abbabbbaabbbccba“; System.out.println(ss.split(“b“).length);}}

java编写登录界面若用户名是aaaaa密码是888888则输出成功否则输出登录失败

可以自行参考下面的代码,自行编写:public static void main(String args){Scanner input=new Scanner(System.in);System.out.println(“用户名:“);String username=input.next();System.out.println(“密码:“);String password=input.next();if(username=’aaaaa’&&password=’888888’);{System.out.println(“登录成功!“);}else{System.out.println(“登录失败!“);}}