java swing 登陆界面美化_java swing 编写的登录界面

这篇博客介绍了如何利用Java Swing库来构建一个吸引人的登录界面。内容包括设置窗口大小、位置,添加组件如用户名和密码输入框,登录和重置按钮,以及背景图片。字体和颜色的选择也增强了界面的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.awt.*;

import javax.swing.*;

class Deng{

public JFrame jf = new JFrame("地址工具集成界面");

public Container con = jf.getContentPane() ;

public Toolkit toolkit = Toolkit.getDefaultToolkit() ;

public Dimension sc = toolkit.getScreenSize() ;

public JLabel name1 = new JLabel("用户名") ;

public JLabel pass1 = new JLabel("密码") ;

public JTextField textName = new JTextField() ;

public JPasswordField textPs = new JPasswordField() ;

public JButton button1 = new JButton("登陆") ;

public JButton button2 = new JButton("重置") ;

public Font font1 = new Font("宋体",1,14) ;

public Font font2 = new Font("宋体",0,12) ;

public Deng()

{

con.setLayout(null) ;

jf.setSize(sc.width/3,sc.height*10/25) ;

jf.setLocation(sc.width/3,sc.height/4) ;

jf.setResizable(false) ;

ImageIcon im = new ImageIcon("") ; //登录按钮背景

jf.setIconImage(im.getImage()) ;

name1.setLocation(80,30) ;

name1.setSize(100, 100) ;

name1.setFont(font1) ;

name1.setForeground(Color.black) ;

pass1.setLocation(80,90) ;

pass1.setSize(100,100) ;

pass1.setForeground(Color.black) ;

pass1.setFont(font1) ;

textName.setSize(140, 20) ;

textName.setLocation(170, 70) ;

textPs.setSize(140, 20) ;

textPs.setLocation(170, 130) ;

textPs.setEchoChar('*') ;

button1.setSize(90,25) ;

button1.setLocation(80,180 ) ;

button1.setIcon(im) ;

button1.setFont(font2) ;

button2.setSize(90,25) ;

button2.setLocation(220, 180) ;

button2.setIcon(im) ;

button2.setFont(font2) ;

ImageIcon bgim = new ImageIcon("image/1354001650808.jpg")

;//背景图案

JLabel bg = new JLabel(bgim) ;

Container laycon = jf.getLayeredPane();

bg.setSize(jf.getSize().width,jf.getSize().height) ;

bgim.setImage(bgim.getImage().getScaledInstance(bg.getSize().width,bg.getSize().height,Image.SCALE_DEFAULT));

laycon.add(bg,new Integer(Integer.MIN_VALUE));

con.add(name1) ;

con.add(pass1) ;

con.add(textName) ;

con.add(textPs) ;

con.add(button1) ;

con.add(button2) ;

con.setBackground(Color.black) ;

con.add(bg) ;

jf.setResizable(false) ;

jf.setVisible(true) ;

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String args[])

{

new Deng() ;

}

}

Java Swing是一个用于构建图形用户界面(GUI)的工具包,可以帮助你构建客户端登录页面。以下是一个简单的实现示例: ``` import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LoginPage { private JFrame frame; private JTextField userField; private JPasswordField passwordField; public LoginPage() { initialize(); } private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JLabel userLabel = new JLabel("用户名:"); userLabel.setBounds(74, 80, 54, 15); frame.getContentPane().add(userLabel); userField = new JTextField(); userField.setBounds(138, 77, 166, 21); frame.getContentPane().add(userField); userField.setColumns(10); JLabel passwordLabel = new JLabel("密码:"); passwordLabel.setBounds(74, 132, 54, 15); frame.getContentPane().add(passwordLabel); passwordField = new JPasswordField(); passwordField.setBounds(138, 129, 166, 21); frame.getContentPane().add(passwordField); JButton loginButton = new JButton("登录"); loginButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String username = userField.getText(); char[] password = passwordField.getPassword(); // TODO: 进行用户名密码验证 } }); loginButton.setBounds(138, 185, 93, 23); frame.getContentPane().add(loginButton); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { LoginPage window = new LoginPage(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } } ``` 这是一个简单的示例,其中包括了用户名和密码输入框,以及登录按钮。您可以通
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值