Code666 (代码贴、代码片段)
创建
最近
趋势
关于
[Java] 登录界面 →→→→→
进入此内容的聊天室
来自 , 2020-04-21, 写在 Java, 查看 146 次.
URL
http://www.code666.cn/view/64f1f27b
下载便签
或
查看源码
—
扩张便签
来填满整个浏览器
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.Font
;
import
java.awt.Graphics
;
import
java.awt.Toolkit
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
javax.swing.*
;
import
java.awt.*
;
public
class
DengLu
extends
JFrame
{
private
JFrame
jf
;
//学号的JPanel Font font1 = new Font("songti",Font.BOLD,20); Font font2 = new Font("songti",Font.BOLD,15); private JLabel lUserId=new JLabel("账 号:"); private JTextField tUserId=new JTextField(10);//密码的JPanel private JLabel lpassword=new JLabel("密 码:"); private JPasswordField tpassword=new JPasswordField(10);//身份的JPanel private JRadioButton student,teacher,administrator;//定义学生,老师,管理员单选按钮 private ButtonGroup group;//定义存放单选按钮的组 private JPanel positionPanel=new JPanel();//验证码的JPanel private JLabel yzm1=new JLabel("验证码:"); private JTextField yzm=new JTextField("666"); private JButton an=new JButton("看不懂,换一张"); private JLabel yzm2=new JLabel("输入验证码:"); private JTextField mm=new JTextField(10);//按钮的JPanel private JButton bLogin=new JButton("登录"); private JButton register=new JButton("注册"); private JButton bCancel=new JButton("返回"); //设置运行时窗口的大小 Dimension faceSize=new Dimension(300,210);//获得屏幕的大小 Dimension screenSize=Toolkit.getDefaultToolkit ().getScreenSize(); public DengLu(){//设置JFrame的名称 setTitle("基于TCP/IP协议的QQ聊天系统"); //定义学生,老师,管理员 student=new JRadioButton("学生"); student.setFont(font2); teacher=new JRadioButton("教师"); teacher.setFont(font2); administrator=new JRadioButton("管理员"); administrator.setFont(font2); group=new ButtonGroup(); group.add(student); group.add(teacher); group.add(administrator); getContentPane().setLayout(new BorderLayout(0, 0)); JPanel panel = new ImagePanel(); getContentPane().add(panel); panel.setLayout(null);// 昵称 lUserId.setFont(font1); panel.add(lUserId); lUserId.setBounds(30, 30, 100, 30); panel.add(tUserId); tUserId.setBounds(150, 30, 100, 30);//密码 lpassword.setFont(font1); panel.add(lpassword); lpassword.setBounds(30, 80, 100, 30); panel.add(tpassword); tpassword.setBounds(150, 80, 100, 30);//按钮 panel.add(bLogin); bLogin.setBounds(15, 140, 90, 30); panel.add(register); register.setBounds(105, 140, 90, 30); panel.add(bCancel); bCancel.setBounds(195, 140, 90, 30);//登录按钮的监听器 bLogin.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String userId=tUserId.getText(); String password=String.valueOf(tpassword.getPassword()); String a=mm.getText(); String b=yzm.getText();//开启数据接收的线程 // if(a.equals(b)){ if(userId.trim().equals("")||userId==null||password.trim().equals("")||password==null){ JOptionPane.showMessageDialog(jf,"用户名或密码不能为空!","提示",JOptionPane.WARNING_MESSAGE); }else{ if(userId.equals("xcy")&&password.equals("123456")){ JOptionPane.showMessageDialog(jf,"登录成功!","提示",JOptionPane.WARNING_MESSAGE); //new ZhuCeJieMian().init(); jf.setVisible(false); }else{ loginFailure(); } } } });//注册 register.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ new ZhuCe(); jf.setVisible(false); } });//返回按钮的监听器 bCancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ //System.exit(0); // tUserId.setText(""); // tpassword.setText(""); new CaiDan(); } }); Toolkit tk=Toolkit.getDefaultToolkit(); Image image=tk.getImage("2.jpg"); setIconImage(image); pack();//设置JFame运行的大小 setSize(faceSize);//设置JFrame运行时的位置 setLocation((int) (screenSize.width-faceSize.getWidth())/2,(int) (screenSize.height-faceSize.getHeight())/2);//设置JFrame不可最大化 setResizable(false);//设置JFrame单击X时结束程序 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置JFrame可见 setVisible(true); } public void loginFailure(){ JOptionPane.showMessageDialog(jf,"用户名或密码输入不正确!","提示",JOptionPane.WARNING_MESSAGE); } class ImagePanel extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); ImageIcon icon = new ImageIcon("3.jpg"); Color c = new Color(0,0,25); bLogin.setOpaque(false);//设置透明背影 bLogin.setBackground(c); register.setOpaque(false);//设置透明背影 register.setBackground(c); bCancel.setOpaque(false);//设置透明背影 bCancel.setBackground(c); tUserId.setOpaque(false);//设置透明背影 tUserId.setBackground(c); tpassword.setOpaque(false);//设置透明背影 tpassword.setBackground(c); if(icon.getImage()!=null){ int width=getWidth(); int height=getHeight(); g.drawImage(icon.getImage(), 0, 0, width,height,this); } } } public static void main(String[] args)throws Exception{ new DengLu(); }}
回复 "登录界面"
这儿你可以回复上面这条便签
作者
你的名字是?
标题
给你的便签一个标题。
语言
你的便签是以
Plain Text
HTML5
CSS
JavaScript
PHP
Python
Ruby
Lua
Bash
Erlang
Go
C
C++
Diff-output
LaTeX
SQL
XML
-----------------
4CS
MOS 6502
MOS 6502 Kick Assembler
MOS 6502 TASM/64TASS
Motorola 68000 Devpac Assembler
ABAP
Actionscript
ActionScript3
Ada
AIMMS
ALGOL 68
Apache
AppleScript
Apt sources.list
ARM Assembler
x86 Assembler
asymptote
ASP
autoconf
Autohotkey
AutoIT
AviSynth
Awk
BASCOM AVR
Basic4GL
BBCode
Brainfuck
BibTeX
BlitzBasic
BNF (Backus-Naur form)
Boo
C (for LoadRunner)
C for Macs
C with WiAPI
CAD DCL (Dialog Control Language)
AutoCAD/IntelliCAD Lisp
CFDG
ColdFusion
ChaiScript
Chapel
CIL (Common Intermediate Language)
Clojure
CMake
COBOL
CoffeeScript
C++ with WinAPI
C#
Cuesheet
D
Dart
DCS
DCL
DCPU/16 Assembly
Delphi (Object Pascal)
DIV
DOS
dot
E
ECMAScript
Eiffel
Email (mbox/eml/RFC format)
Enerscript
Euphoria
EZT
Formula One
Falcon
fo
Fortran
FreeBasic
FreeSWITCH
F#
GAMBAS
GDB
Genero
Genie
GNU Gettext .po/.pot
glSlang
GML
Gnuplot script
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML 4.01 strict
Icon
Unoidl
INI
Inno Script
INTERCAL
Io
ISPF Panel
J
Java
Java 5
Job Control Language
jQuery 1.3
KLone with C
KLone with C++
Kotlin
Liberty BASIC
LDIF
Generic Lisp
LLVM
Locomotive Basic (Amstrad CPC series)
Logcat
Logtalk
LOLcode
@Formula/@Command
LotusScript
Lightwave Script
Linden Scripting
Motorola 68000 Assembler
MagikSF
Make
MapBasic
Matlab M-file
mIRC Scripting
MMIX Assembler
Modula-2
Modula-3
Microchip Assembler
MXML
MySQL
Nagios
NetRexx
newLISP
nginx
Nimrod
Nullsoft Scriptable Install System
Oberon-2
Objective-C
Objeck Programming Language
OCaml (Objective Caml)
GNU Octave M-file
OpenOffice.org Basic
ooRexx
Oracle 11i
Oracle 8
Delphi Prism (Oxygene)
Oz
ParaSail
PARI/GP
Pascal
PCRE
Per (forms)
Perl
Perl 6
OpenBSD packet filter
PIC16 Assembler
Pike
Pixel Bender 1.0
PL/I
Oracle 9.2 PL/SQL
PostgreSQL
Postscript
Povray
PowerBuilder (PowerScript)
PowerShell
ProFTPd
Progress
Prolog
Property
ProvideX
PureBasic
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
Racket
Ruby (with Ruby on Rails Framework)
RBS Script
Rebol
Microsoft Registry Editor
Rexx
robots.txt
RPM Spec
R
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty template
SPARK
SPARQL
StandardML
StoneScript
SystemVerilog IEEE 1800-2009(draft8)
TCL/iTCL
Tera Term Macro
thinBasic
T-SQL
TypoScript
Unicon
UnrealScript
UPC
Urbi
Vala
Visual Basic
VB.NET
VBScript
Vedit macro language
Verilog
VHDL
Vim scripting
Visual FoxPro
Visual Prolog
Whitespace
Whois response (RPSL format)
WinBatch
XBasic
xorg.conf
Axapta/Dynamics Ax X++
YAML
ZiLOG Z80 Assembler
ZXBasic
你的便签
在这儿输入便签内容
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.Graphics;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import java.awt.*;public class DengLu extends JFrame{ private JFrame jf; //学号的JPanel Font font1 = new Font("songti",Font.BOLD,20); Font font2 = new Font("songti",Font.BOLD,15); private JLabel lUserId=new JLabel("账 号:"); private JTextField tUserId=new JTextField(10);//密码的JPanel private JLabel lpassword=new JLabel("密 码:"); private JPasswordField tpassword=new JPasswordField(10);//身份的JPanel private JRadioButton student,teacher,administrator;//定义学生,老师,管理员单选按钮 private ButtonGroup group;//定义存放单选按钮的组 private JPanel positionPanel=new JPanel();//验证码的JPanel private JLabel yzm1=new JLabel("验证码:"); private JTextField yzm=new JTextField("666"); private JButton an=new JButton("看不懂,换一张"); private JLabel yzm2=new JLabel("输入验证码:"); private JTextField mm=new JTextField(10);//按钮的JPanel private JButton bLogin=new JButton("登录"); private JButton register=new JButton("注册"); private JButton bCancel=new JButton("返回"); //设置运行时窗口的大小 Dimension faceSize=new Dimension(300,210);//获得屏幕的大小 Dimension screenSize=Toolkit.getDefaultToolkit ().getScreenSize(); public DengLu(){//设置JFrame的名称 setTitle("基于TCP/IP协议的QQ聊天系统"); //定义学生,老师,管理员 student=new JRadioButton("学生"); student.setFont(font2); teacher=new JRadioButton("教师"); teacher.setFont(font2); administrator=new JRadioButton("管理员"); administrator.setFont(font2); group=new ButtonGroup(); group.add(student); group.add(teacher); group.add(administrator); getContentPane().setLayout(new BorderLayout(0, 0)); JPanel panel = new ImagePanel(); getContentPane().add(panel); panel.setLayout(null);// 昵称 lUserId.setFont(font1); panel.add(lUserId); lUserId.setBounds(30, 30, 100, 30); panel.add(tUserId); tUserId.setBounds(150, 30, 100, 30);//密码 lpassword.setFont(font1); panel.add(lpassword); lpassword.setBounds(30, 80, 100, 30); panel.add(tpassword); tpassword.setBounds(150, 80, 100, 30);//按钮 panel.add(bLogin); bLogin.setBounds(15, 140, 90, 30); panel.add(register); register.setBounds(105, 140, 90, 30); panel.add(bCancel); bCancel.setBounds(195, 140, 90, 30);//登录按钮的监听器 bLogin.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String userId=tUserId.getText(); String password=String.valueOf(tpassword.getPassword()); String a=mm.getText(); String b=yzm.getText();//开启数据接收的线程 // if(a.equals(b)){ if(userId.trim().equals("")||userId==null||password.trim().equals("")||password==null){ JOptionPane.showMessageDialog(jf,"用户名或密码不能为空!","提示",JOptionPane.WARNING_MESSAGE); }else{ if(userId.equals("xcy")&&password.equals("123456")){ JOptionPane.showMessageDialog(jf,"登录成功!","提示",JOptionPane.WARNING_MESSAGE); //new ZhuCeJieMian().init(); jf.setVisible(false); }else{ loginFailure(); } } } });//注册 register.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ new ZhuCe(); jf.setVisible(false); } });//返回按钮的监听器 bCancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ //System.exit(0); // tUserId.setText(""); // tpassword.setText(""); new CaiDan(); } }); Toolkit tk=Toolkit.getDefaultToolkit(); Image image=tk.getImage("2.jpg"); setIconImage(image); pack();//设置JFame运行的大小 setSize(faceSize);//设置JFrame运行时的位置 setLocation((int) (screenSize.width-faceSize.getWidth())/2,(int) (screenSize.height-faceSize.getHeight())/2);//设置JFrame不可最大化 setResizable(false);//设置JFrame单击X时结束程序 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置JFrame可见 setVisible(true); } public void loginFailure(){ JOptionPane.showMessageDialog(jf,"用户名或密码输入不正确!","提示",JOptionPane.WARNING_MESSAGE); } class ImagePanel extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); ImageIcon icon = new ImageIcon("3.jpg"); Color c = new Color(0,0,25); bLogin.setOpaque(false);//设置透明背影 bLogin.setBackground(c); register.setOpaque(false);//设置透明背影 register.setBackground(c); bCancel.setOpaque(false);//设置透明背影 bCancel.setBackground(c); tUserId.setOpaque(false);//设置透明背影 tUserId.setBackground(c); tpassword.setOpaque(false);//设置透明背影 tpassword.setBackground(c); if(icon.getImage()!=null){ int width=getWidth(); int height=getHeight(); g.drawImage(icon.getImage(), 0, 0, width,height,this); } } } public static void main(String[] args)throws Exception{ new DengLu(); }}
创建短链接
创建一个较短的URL,连接到这个便签
私人
私人便签不会显示在最近列表中
保存期限
我们应该什么时候删除这张便签?
阅后即焚
五分钟
一小时
一天
一周
一月
一年
永久保留
防滥用
键入这些字符
创建