java应用软件开发之多物料管理系统--登录界面设计
程序员文章站
2024-01-20 17:30:04
此系列将记录本人从开始到结束做物料管理系统的过程 登录界面的设计 此博客将实现如下界面: 当用户名或密码没输入时将显示相应的提示信息,采用java swing实现 代码: ......
此系列将记录本人从开始到结束做物料管理系统的过程
登录界面的设计
此博客将实现如下界面:
当用户名或密码没输入时将显示相应的提示信息,采用java swing实现
代码:
import java.awt.eventqueue; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.joptionpane; import java.awt.font; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jtextfield; import javax.swing.jpasswordfield; import javax.swing.buttongroup; import javax.swing.jbutton; import javax.swing.jradiobutton; import java.awt.color; public class login { private jframe frame; private jtextfield textfield; private jpasswordfield passwordfield; public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { login window = new login(); window.frame.setlocationrelativeto(null); window.frame.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } public login() { initialize(); } private void initialize() { frame = new jframe(); frame.settitle("\u7269\u6599\u7ba1\u7406\u7cfb\u7edf"); frame.setbounds(100, 100, 360, 260); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.getcontentpane().setlayout(null); jlabel usernamelabel = new jlabel("\u7528\u6237\u540d\uff1a"); usernamelabel.setfont(new font("宋体", font.plain, 14)); usernamelabel.setbounds(90, 66, 72, 28); frame.getcontentpane().add(usernamelabel); jlabel passwordlabel = new jlabel("\u5bc6 \u7801\uff1a"); passwordlabel.setfont(new font("宋体", font.plain, 14)); passwordlabel.setbounds(90, 104, 72, 33); frame.getcontentpane().add(passwordlabel); textfield = new jtextfield(); textfield.setforeground(color.black); textfield.setbounds(147, 70, 110, 21); frame.getcontentpane().add(textfield); textfield.setcolumns(10); textfield.addactionlistener(new action()); passwordfield = new jpasswordfield(); passwordfield.setbounds(147, 110, 110, 21); frame.getcontentpane().add(passwordfield); passwordfield.addactionlistener(new action()); jbutton loginbutton = new jbutton("\u767b\u5f55"); loginbutton.setbounds(90, 157, 72, 23); frame.getcontentpane().add(loginbutton); loginbutton.addactionlistener(new action()); buttongroup group = new buttongroup(); jradiobutton button1 = new jradiobutton("\u7ba1\u7406\u54581"); button1.setbounds(64, 18, 72, 23); frame.getcontentpane().add(button1); group.add(button1); jradiobutton button2 = new jradiobutton("\u7ba1\u7406\u54582"); button2.setbounds(138, 18, 72, 23); frame.getcontentpane().add(button2); group.add(button2); jradiobutton button3 = new jradiobutton("\u7ba1\u7406\u54582"); button3.setbounds(210, 18, 80, 23); frame.getcontentpane().add(button3); group.add(button3); jlabel label = new jlabel(""); label.setbounds(267, 73, 54, 15); frame.getcontentpane().add(label); jlabel label_1 = new jlabel(""); label_1.setbounds(267, 113, 54, 15); frame.getcontentpane().add(label_1); } class action implements actionlistener{ @suppresswarnings("deprecation") public void actionperformed(actionevent e) { string buttonname = e.getactioncommand(); if(buttonname.equals("登录")) { if(textfield.gettext().isempty()) { joptionpane.showmessagedialog(null, "账号不能为空"); }else if(passwordfield.gettext().isempty()) { joptionpane.showmessagedialog(null, "密码不能为空"); } } } } }
上一篇: js--兼容写法
下一篇: [De1CTF 2019]SSRF Me