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

如何用JAVA编写一个简单用户登陆界面?,第1张

什么都不说了 直接给你代码吧\x0d\x0apackage com.moliying.ui\x0d\x0aimport java.awt.BorderLayout\x0d\x0aimport java.awt.Container\x0d\x0aimport java.awt.FlowLayout\x0d\x0aimport java.awt.List\x0d\x0aimport java.awt.event.ActionEvent\x0d\x0aimport java.awt.event.ActionListener\x0d\x0aimport java.io.BufferedWriter\x0d\x0aimport java.io.FileOutputStream\x0d\x0aimport java.io.OutputStreamWriter\x0d\x0aimport java.util.ArrayList\x0d\x0aimport java.util.Arrays\x0d\x0aimport javax.swing.JButton\x0d\x0aimport javax.swing.JFrame\x0d\x0aimport javax.swing.JLabel\x0d\x0aimport javax.swing.JPanel\x0d\x0aimport javax.swing.JPasswordField\x0d\x0aimport javax.swing.JTextField\x0d\x0apublic class Login {\x0d\x0aprivate JFrame frame = new JFrame("登录")\x0d\x0aprivate Container c = frame.getContentPane()\x0d\x0aprivate JTextField username = new JTextField()\x0d\x0aprivate JPasswordField password = new JPasswordField()\x0d\x0aprivate JButton ok = new JButton("确定")\x0d\x0aprivate JButton cancel = new JButton("取消")\x0d\x0apublic Login() {\x0d\x0aframe.setSize(300, 200)\x0d\x0aframe.setBounds(450, 300, 300, 200)\x0d\x0ac.setLayout(new BorderLayout())\x0d\x0ainitFrame()\x0d\x0aframe.setVisible(true)\x0d\x0a}\x0d\x0aprivate void initFrame() {\x0d\x0a// 顶部\x0d\x0aJPanel titlePanel = new JPanel()\x0d\x0atitlePanel.setLayout(new FlowLayout())\x0d\x0atitlePanel.add(new JLabel("系统管理员登录"))\x0d\x0ac.add(titlePanel, "North")\x0d\x0a// 中部表单\x0d\x0aJPanel fieldPanel = new JPanel()\x0d\x0afieldPanel.setLayout(null)\x0d\x0aJLabel a1 = new JLabel("用户名:")\x0d\x0aa1.setBounds(50, 20, 50, 20)\x0d\x0aJLabel a2 = new JLabel("密 码:")\x0d\x0aa2.setBounds(50, 60, 50, 20)\x0d\x0afieldPanel.add(a1)\x0d\x0afieldPanel.add(a2)\x0d\x0ausername.setBounds(110, 20, 120, 20)\x0d\x0apassword.setBounds(110, 60, 120, 20)\x0d\x0afieldPanel.add(username)\x0d\x0afieldPanel.add(password)\x0d\x0ac.add(fieldPanel, "Center")\x0d\x0a// 底部按钮\x0d\x0aJPanel buttonPanel = new JPanel()\x0d\x0abuttonPanel.setLayout(new FlowLayout())\x0d\x0abuttonPanel.add(ok)\x0d\x0abuttonPanel.add(cancel)\x0d\x0ac.add(buttonPanel, "South")\x0d\x0a\x0d\x0aok.addActionListener(new ActionListener() {\x0d\x0a\x0d\x0a@Override\x0d\x0apublic void actionPerformed(ActionEvent e) {\x0d\x0aSystem.out.println(username.getText().toString())\x0d\x0a}\x0d\x0a})\x0d\x0a\x0d\x0acancel.addActionListener(new ActionListener() {\x0d\x0a\x0d\x0a@Override\x0d\x0apublic void actionPerformed(ActionEvent e) {\x0d\x0aframe.setVisible(false)\x0d\x0a}\x0d\x0a})\x0d\x0a}\x0d\x0apublic static void main(String[] args) {\x0d\x0a//new Login()\x0d\x0a\x0d\x0aString ss = "abbabbbaabbbccba"\x0d\x0a\x0d\x0aSystem.out.println(ss.split("b").length)\x0d\x0a\x0d\x0a}\x0d\x0a}

import javax.swing.*

import java.awt.*

public class Frame extends JFrame {

public static void main(String[] args) {

new Frame()

}

public Frame() throws HeadlessException {

Container contentPanel = this.getContentPane()

JPanel headerPanel = new JPanel()

headerPanel.setLayout(new FlowLayout())

headerPanel.add(new JLabel("欢迎进入学生成绩管理系统"))

JPanel centerPanel = new JPanel()

centerPanel.setLayout(new GridLayout(2, 2))

centerPanel.add(new JLabel("用户名", JLabel.CENTER))

centerPanel.add(new JTextField())

centerPanel.add(new JLabel("密码", JLabel.CENTER))

centerPanel.add(new JTextField())

JPanel footerPanel = new JPanel()

footerPanel.setLayout(new FlowLayout())

footerPanel.add(new JButton("登录"))

footerPanel.add(new JButton("取消"))

contentPanel.add(headerPanel, BorderLayout.NORTH)

contentPanel.add(centerPanel, BorderLayout.CENTER)

contentPanel.add(footerPanel, BorderLayout.SOUTH)

this.setTitle("Login")

this.setBounds(0, 0, 300, 200)

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

this.setVisible(true)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8129174.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存