Java 登录窗口源代码
- 格式:pdf
- 大小:240.96 KB
- 文档页数:9
java用户登录界面的代码以下是一个简单的Java用户登录界面的代码示例,其中包括了GUI界面设计和用户验证的代码:```javaimport javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JPasswordField;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class LoginWindow extends JFrame implements ActionListener {private JLabel usernameLabel, passwordLabel;private JTextField usernameTextField;private JPasswordField passwordField;private JButton loginButton;public LoginWindow() {setTitle("用户登录");setSize(400, 200);setLocationRelativeTo(null);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);usernameLabel = new JLabel("用户名:");passwordLabel = new JLabel("密码:");usernameTextField = new JTextField();passwordField = new JPasswordField();loginButton = new JButton("登录");loginButton.addActionListener(this);setLayout(null);usernameLabel.setBounds(50, 30, 80, 25);passwordLabel.setBounds(50, 70, 80, 25);usernameTextField.setBounds(130, 30, 200, 25);passwordField.setBounds(130, 70, 200, 25);loginButton.setBounds(150, 120, 100, 25);add(usernameLabel);add(passwordLabel);add(usernameTextField);add(passwordField);add(loginButton);setVisible(true);}public void actionPerformed(ActionEvent e) {String username = usernameTextField.getText();String password = newString(passwordField.getPassword());if (isValidUser(username, password)) {System.out.println("用户登录成功!");// 在这里可以跳转到下一个界面} else {System.out.println("用户名或密码错误!");}}private boolean isValidUser(String username, String password) {// 在这里实现用户验证的代码// 比如查询数据库是否有该用户并且密码是否匹配等等// 如果验证成功则返回true,否则返回falsereturn false;}public static void main(String[] args) {new LoginWindow();}}```该代码创建了一个窗口界面,包括“用户名”和“密码”两个文本框,以及一个“登录”按钮。
在网上找了许多,都是不能用的了,本地登陆还好,放到网站就显示:警告:系统检查到您可能通过不安全的网站登录,请您登录后立即修改密码!但是老板着急让完成。
就接着百度。
终于搞定。
代码共有两部分:一、登陆页面:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/1999/REC-html401-19991224/loose.dtd"><HTML xmlns="/1999/xhtml"><HEAD><TITLE>中药方大全</TITLE><META content="text/html; charset=gbk" http-equiv=Content-Type><SCRIPT type=text/javascript src="config.js"></SCRIPT></HEAD><BODY ><FORM id=gomail class=c_form onSubmit="return checktype(this);"method=post name=gomail action=JavaScript:><INPUT type=hidden name=url><INPUT type=hidden name=username> <INPUT type=hidden name=type> <INPUTtype=hidden name=password> <INPUT type=hidden name=domain> <INPUTvalue=/inset.html type=hidden name=.done> <INPUTtype=hidden name=user> <INPUT type=hidden name=pass> <INPUT value=truetype=hidden name=enterVip> <INPUT type=hidden name=UserName> <INPUTtype=hidden name=Password> <INPUT type=hidden name=u> <INPUT type=hiddenname=psw> <INPUT type=hidden name=login> <INPUT type=hiddenname=LoginName> <INPUT type=hidden name=usr> <INPUT type=hidden name=func> <INPUT type=hidden name=login_name> <INPUT type=hiddenname=login_password> <INPUT type=hidden name=BackURL> <INPUTvalue=/mail?ui=html&zy=l type=hiddenname=continue> <INPUT type=hidden name=Email> <INPUT type=hiddenname=email> <INPUT type=hidden name=domainname> <INPUT value=falsetype=hidden name=firstlogin> <INPUT type=hidden name=starttime> <INPUTtype=hidden name=p2> <INPUT type=hidden name=passwd> <INPUT type=hiddenname=id> <INPUT type=hidden name=m> <INPUT type=hidden name=mpass> <INPUT type=hidden name=loginid> <INPUT type=hidden name=appid> <INPUTtype=hidden name=ru> <INPUT type=hidden name=eru> <INPUT type=hiddenname=fl> <INPUT type=hidden name=ct> <INPUT type=hidden name=vr> <INPUTtype=hidden name=sg> <INPUT type=hidden name=vwriter> <INPUT type=hiddenname=vpassword> <INPUT type=hidden name=passport_51_user> <INPUTtype=hidden name=passport_51_password> <INPUT type=hidden name=gourl><INPUT type=hidden name=Passwd> <INPUT value=cn type=hidden name=.intl><INPUT type=hidden name=origURL> <INPUT type=hidden name=formName> <INPUT type=hidden name=method> <INPUT value=true type=hidden name=isplogin><UL><LI><LABEL for=mail_user_ican123>帐号</LABEL> <INPUT id=mail_user_ican123class=int size=25 type=text name=uName> </LI><LI><LABEL for=mail_ail_server_ican123>邮箱</LABEL> <SELECTid=mail_server_ican123 class=select onchange=shortcut() name=domains><OPTION selected value=selected>--请选择--</OPTION> <OPTIONvalue=163> 网易</OPTION> <OPTION value=126></OPTION><OPTION value=sohu> 搜狐</OPTION> <OPTION value=sina>新浪</OPTION> <OPTION value=tom></OPTION> <OPTIONvalue=yahoo></OPTION> <OPTIONvalue=yahoocn></OPTION> <OPTION value=21cn></OPTION><OPTION value=eyou> 亿邮</OPTION> <OPTIONvalue=vipsina></OPTION> <OPTIONvalue=vip163></OPTION> <OPTION value=263></OPTION><OPTION value=yeah></OPTION> <OPTIONvalue=selected>以下请在弹出页登陆↓</OPTION> <OPTIONvalue=gmail></OPTION> <OPTION value=qq></OPTION><OPTION value=188></OPTION> <OPTION value=139></OPTION><OPTION value=sogou></OPTION> <OPTIONvalue=hotmail></OPTION> <OPTIONvalue=kaixin001>开心网</OPTION> <OPTIONvalue=selected>--社交网及其他--</OPTION> <OPTION value=baidu>百度账号</OPTION><OPTION value=renren>人人网</OPTION> <OPTION value=tianya>天涯社区</OPTION><OPTION value=51> 博客</OPTION> <OPTION value=cren>ChinaRen校友录</OPTION></SELECT> </LI><LI><LABEL for=mail_passwd_ican123>密码</LABEL> <INPUTid=mail_passwd_ican123 class=int size=15 type=password name=uPw> <INPUT id=mail_submit_ican123 class=btn value="登录" type=submit name=btn_my></LI></UL></FORM></BODY></HTML>二、相应的js代码(config.js)var ua=erAgent.toLowerCase();var isIE=ua.indexOf("msie")>-1;var isFF=ua.indexOf("firefox")>-1;function regE(c,b,a){if(window.attachEvent){c.attachEvent(b,a)}else {c.addEventListener(b.replace(/^on/,""),a,true)}}function $(a){return document.getElementById(a)}function os(a){return $(a).style}function ResumeError(){return true}window.onerror=ResumeError;// JavaScript Document/*var gm=document.gomail;var vDomain=gm.domains;var vName=gm.uName;var vPw=gm.uPw;*/function checktype(obj){if(obj.domains.value=="selected"){alert("您没有选择邮箱");obj.domains.focus();return false}if(obj.uName.value==""){alert("您没有填写用户名");obj.uName.focus();return false}if(obj.uPw.value==""){alert("您没有填写密码");obj.uPw.focus();return false}if(obj.domains.value=="163"||obj.domains.value=="126"||obj.domains.value=="yeah"){checkwangyi(obj);}else{clickMail(obj);}obj.uPw.value="";return ;this.location.reload();}function clickMail(obj){obj.target="_blank"switch(obj.domains.value){case "188":obj.action="/servlet/coremail/login?language=0&style=1"er.value=obj.uName.valueobj.pass.value=obj.uPw.valuebreakcase "vip163":obj.action="https:///logon.m?language=-1&style=-1" ername.value=obj.uName.valueobj.password.value=obj.uPw.valuebreakcase "netease":obj.action="/cgi/login?verifycookie=1&language=0" ername.value=obj.uName.valueobj.password.value=obj.uPw.valuebreakcase "sohu":obj.action="/login.jsp"obj.url.value=""erName.value=obj.uName.valueobj.Password.value=obj.uPw.valueobj.id.value=obj.uName.valueername.value=obj.uName.valueobj.password.value=obj.uPw.valueobj.m.value=obj.uName.valueobj.passwd.value=obj.uPw.valueobj.mpass.value=obj.uPw.valueobj.loginid.value=obj.uName.value+"@"obj.fl.value="1"obj.vr.value="1|1"obj.appid.value="1000"obj.ru.value="/servlet/LoginServlet"obj.eru.value="/login.jsp"obj.ct.value="1173080990"obj.sg.value="5082635c77272088ae7241ccdf7cf062"breakcase "yahoo":obj.action="https:///config/login"obj.login.value=obj.uName.valueobj.passwd.value=obj.uPw.valuebreakcase "yahoocn":obj.action="https:///config/login"obj.login.value=obj.uName.value+"@"obj.passwd.value=obj.uPw.valuebreakcase "tom":obj.action="/cgi/163/login_pro.cgi"er.value=obj.uName.valueobj.pass.value=obj.uPw.valuebreakcase "21cn":obj.action="/maillogin.jsp"obj.LoginName.value=obj.uName.valueobj.passwd.value=obj.uPw.valueobj.domainname.value=""erName.value=obj.uName.value+'@'breakcase "china":obj.action="/coremail/fcg/login"er.value=obj.uName.valueobj.pass.value=obj.uPw.valueobj.domainname.value=""//obj.passwd.value=obj.uPw.valuebreakcase "mailchina":obj.action="/extend/gb/NULL/NULL/NULL/SignIn.gen" obj.LoginName.value=obj.uName.valueobj.passwd.value=obj.uPw.valuebreakcase "citiz":obj.action="/default/login_billing.jsp"ername.value=obj.uName.value+"@"obj.password.value=obj.uPw.valuebreakcase "56":var gUrsHost=["m113","m48","m49"];obj.action="http://"+gUrsHost[((new Date()).getSeconds())%3]+"/mail/mail.56" ername.value=obj.uName.valueobj.password.value=obj.uPw.valuebreakcase "Xinhuanet":obj.action="/login.jsp"ername.value=obj.uName.valueobj.password.value=obj.uPw.valueobj.domainname.value=''breakcase "sina":obj.action="/cgi-bin/login.cgi"obj.u.value=obj.uName.valueobj.psw.value=obj.uPw.valuebreakcase "eyou":obj.action="/mail_login.php"obj.LoginName.value=obj.uName.valueobj.Password.value=obj.uPw.valuebreakcase "263":obj.action="/xmweb"r.value=obj.uName.valueobj.pass.value=obj.uPw.valueobj.domain.value=""obj.func.value="login"breakcase "qq":obj.action="/cgi-bin/login"obj.u.value=obj.uName.valueobj.p.value=obj.uPw.valueobj.starttime.value=(new Date()).valueOf()breakcase "vipsina":obj.action="/cgi-bin/login.php"obj.domain.value=''obj.u.value=obj.uName.valueobj.psw.value=obj.uPw.valuebreak;case "cren":obj.action="/login.jsp"obj.loginid.value=obj.uName.value+"@"obj.passwd.value=obj.uPw.valueobj.fl.value="1"obj.vr.value="1|1"obj.appid.value="1005"obj.ru.value="/urs/setcookie.jsp?burl=/" obj.ct.value="1174378209"obj.sg.value="84ff7b2e1d8f3dc46c6d17bb83fe72bd"breakcase "tianya":obj.action="/user/loginsubmit.asp"obj.vwriter.value=obj.uName.valueobj.vpassword.value=obj.uPw.valuebreakcase "51":obj.action="/login.5p"obj.passport_51_user.value=obj.uName.valueobj.passport_51_password.value=obj.uPw.valueobj.gourl.value="http%3A%2F%%2Fwebim%2Findex.php"breakcase "renren":obj.action="/Login.do"obj.email.value=obj.uName.valueobj.password.value=obj.uPw.valuebreakcase "baidu":obj.action="https:///?login"ername.value=obj.uName.valueobj.password.value=obj.uPw.valueobj.u.value="/index.php?tn=fm991_pg"break}obj.uPw.value = ""SetmailCookie('m',obj.domains.selectedIndex,5184000,'/')//obj.uPw.value = ""return true}function checkwangyi(obj){obj.target="_parent"var url="";var lname=obj.uName.value;var lpass=obj.uPw.value;var lindex=obj.domains.selectedIndex;if(lindex==1)url="/logins.jsp?type=1&url=/coremail/fcg/ntesdoor2?&u sername="+lname+"&password="+lpass;if(lindex==2)url="/logins.jsp?type=1&url=/cgi/ntesdoor?&usernam e="+lname+"@"+"&password="+lpass;if(lindex==13)url="/logins.jsp?type=1&url=/cgi/ntesdoor?&usernam e="+lname+"@"+"&password="+lpass;openWin(url);// else obj.submit();return true;}function shortcut(){var gm=document.gomail;var vDomain=gm.domains,vName=gm.uName,vPw=gm.uPw;if(vDomain.value=="qq")window.open("");else if(vDomain.value=="hotmail")window.open("/");else if(vDomain.value=="sogou")window.open("/");else if(vDomain.value=="139")window.open("/");else if(vDomain.value=="gmail")window.open("/");else if(vDomain.value=="188")window.open("/");else if(vDomain.value=="kaixin001")window.open("/");setCookies();}function setCookies(){var gm=document.m;var vDomain=gm.domains,vName=gm.uName;if(vDomain.value!="qq"&&vDomain.value!="hotmail"&&vDomain.value!="sogou"&&vDo main.value!="139"&&vDomain.value!="gmail"&&vDomain.value!="188"&&vDomain.value!=" kaixin001"){setmailCookie('mailType',vDomain.selectedIndex.toString ());if(vName.value)setmailCookie('username',vName.value.toString ());}else {var mailType=getCookie('mailType')?getCookie('mailType'):0;for(var i=0;i<vDomain.options.length;i++){if(i!=parseInt(mailType)){vDomain.options[i].removeAttribute("selected");}else {vDomain.options[mailType].setAttribute("selected","true");}}}}function openWin(url){window.open(url);}function SetmailCookie(n,v,t,dm){}三、测试页面/test/pingtou/mail.htm联系QQ:110102296。
java学生管理系统大作业代码Java学生管理系统是一个基于Java语言开发的学生信息管理系统,用于方便学校教务人员进行学生信息的管理和查询。
以下是该系统的代码实现。
1. 登录界面代码实现该界面是用户登录的入口,用户需要输入用户名和密码才能进入系统。
```javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;public class Login extends JFrame implements ActionListener {JLabel lb1, lb2, lb3;JTextField txtName;JPasswordField txtPwd;JButton btnOK, btnCancel;String userName = "admin";// 默认用户名String password = "123456";// 默认密码public Login() {setTitle("学生信息管理系统登录");// 设置窗体标题setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置窗体关闭方式setSize(350, 200);// 设置窗体大小setLocationRelativeTo(null);// 设置居中显示setLayout(new BorderLayout());JPanel pNorth = new JPanel();lb1 = new JLabel("欢迎使用学生信息管理系统", JLabel.CENTER); lb1.setFont(new Font("微软雅黑", Font.BOLD, 20));pNorth.add(lb1);add(pNorth, BorderLayout.NORTH);JPanel pCenter = new JPanel();pCenter.setLayout(new GridLayout(3, 2));lb2 = new JLabel("用户名:", JLabel.RIGHT);pCenter.add(lb2);txtName = new JTextField(20);pCenter.add(txtName);lb3 = new JLabel("密码:", JLabel.RIGHT);pCenter.add(lb3);txtPwd = new JPasswordField(20);txtPwd.setEchoChar('*');// 设置密码框的回显字符pCenter.add(txtPwd);btnOK = new JButton("登录");pCenter.add(btnOK);btnCancel = new JButton("取消");pCenter.add(btnCancel);add(pCenter, BorderLayout.CENTER);btnOK.addActionListener(this);btnCancel.addActionListener(this);setVisible(true);// 显示窗体}public void actionPerformed(ActionEvent e) {if (e.getSource() == btnOK) {String name = txtName.getText();// 获取用户名String password = new String(txtPwd.getPassword());// 获取密码 if (name.equals(userName) && password.equals(password)) {setVisible(false);new MainFrame();} else {JOptionPane.showMessageDialog(Login.this, "用户名或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);}} else if (e.getSource() == btnCancel) {txtName.setText("");txtPwd.setText("");}}public static void main(String[] args) {new Login();}}```2. 主界面代码实现该界面是系统的主界面,包含了菜单栏、工具栏和表格显示区域。
java实现简单QQ登录界⾯本⽂实例为⼤家分享了java实现简单QQ登录界⾯的具体代码,供⼤家参考,具体内容如下java在图形界⾯,不是太强项,但不是不可以做,它的开源是very nice!实现代码如下(想实现完美的界⾯,可能要更多coding的⽀持):package com.ts.x.swing;import java.awt.Color;import java.awt.Container;import java.awt.Cursor;import java.awt.Font;import java.awt.Image;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JRootPane;import javax.swing.JTextField;public class QQ extends JFrame{private static final long serialVersionUID = -6788045638380819221L;//⽤户名private JTextField ulName;//密码private JPasswordField ulPasswd;//⼩容器private JLabel j1;private JLabel j2;private JLabel j3;private JLabel j4;//⼩按钮private JButton b1;private JButton b2;private JButton b3;//复选框private JCheckBox c1;private JCheckBox c2;//列表框private JComboBox<String> cb1;/*** 初始化QQ登录页⾯* */public QQ(){//设置登录窗⼝标题this.setTitle("QQ登录");//去掉窗⼝的装饰(边框)// this.setUndecorated(true);//采⽤指定的窗⼝装饰风格this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);//窗体组件初始化init();this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置布局为绝对定位this.setLayout(null);this.setBounds(0, 0, 355, 265);//设置窗体的图标Image img0 = new ImageIcon("D:/logo.png").getImage();this.setIconImage(img0);//窗体⼤⼩不能改变this.setResizable(false);//居中显⽰this.setLocationRelativeTo(null);//窗体显⽰this.setVisible(true);}/*** 窗体组件初始化* */public void init(){//创建⼀个容器,其中的图⽚⼤⼩和setBounds第三、四个参数要基本⼀致(需要⾃⼰计算裁剪) Container container = this.getContentPane();j1 = new JLabel();//设置背景⾊Image img1 = new ImageIcon("D:/bgimg.png").getImage();j1.setIcon(new ImageIcon(img1));j1.setBounds(0, 0, 355, 265);//qq头像设定j2 = new JLabel();Image img2 = new ImageIcon("D:/hdimg.png").getImage();j2.setIcon(new ImageIcon(img2));j2.setBounds(40, 95, 50, 53);//⽤户名输⼊框ulName = new JTextField();ulName.setBounds(100, 100, 150, 20);//注册账号j3 = new JLabel("注册账号");j3.setBounds(260, 100, 70, 20);//密码输⼊框ulPasswd = new JPasswordField();ulPasswd.setBounds(100, 130, 150, 20);//找回密码j4= new JLabel("找回密码");j4.setBounds(260, 130, 70, 20);//记住密码c1 = new JCheckBox("记住密码");c1.setBounds(105, 155, 80, 15);//⾃动登陆c2 = new JCheckBox("⾃动登陆");c2.setBounds(185, 155, 80, 15);//⽤户登陆状态选择cb1 = new JComboBox<String>();cb1.addItem("在线");cb1.addItem("隐⾝");cb1.addItem("离开");cb1.setBounds(40, 150, 55, 20);//登陆按钮b1 = new JButton("登录");//设置字体和颜⾊和⼿形指针b1.setFont(new Font("宋体", Font.PLAIN, 12));b1.setForeground(Color.RED);b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));b1.setBounds(280, 200, 65, 20);//给按钮添加b1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String cmd = e.getActionCommand();if("登录".equals(cmd)){String username = ulName.getText();String userpassword = ulPasswd.getText();if(username.equals("tskk") && userpassword.equals("123456")){JOptionPane.showConfirmDialog(null, "登录成功");}else{JOptionPane.showConfirmDialog(null, "登录失败");}}}});//多账号b2 = new JButton("多账号");b2.setBounds(5, 200, 75, 20);//设置b3 = new JButton("设置");b3.setBounds(100, 200, 65, 20);//所有组件⽤容器装载j1.add(j2);j1.add(j3);j1.add(j4);j1.add(c1);j1.add(c2);j1.add(cb1);j1.add(b1);j1.add(b2);j1.add(b3);container.add(j1);container.add(ulName);container.add(ulPasswd);}public static void main(String[] args) {new QQ();}}运⾏结果界⾯为:以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
javaweb课程设计源码参考JavaWeb课程设计源码参考一、引言JavaWeb课程设计是计算机科学与技术专业的一门重要课程。
在这门课程中,学生需要掌握JavaWeb开发的基本知识和技能,并通过实践来加深对所学知识的理解。
本文将为大家提供一些JavaWeb课程设计的源码参考,帮助学生更好地完成课程设计。
二、登录页面登录页面是JavaWeb课程设计中常见的一个功能模块。
下面是一个简单的登录页面源码参考:```java<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %><!DOCTYPE html><html><head><title>登录页面</title></head><body><form action="login" method="post"><label for="username">用户名:</label><input type="text" id="username" name="username"><br><br><label for="password">密码:</label><input type="password" id="password" name="password"><br><br><input type="submit" value="登录"></form></body></html>```三、登录功能实现登录功能是JavaWeb课程设计中的核心功能之一。
java action:LoginForm form=(LoginForm)actionForm;ActionMessages errors = new ActionMessages();System.out.println(";form.getAction()=";+form.getAction());if (";login";.equals(form.getAction())) {System.out.println(";----------------login--------------";);AuthCodeCookie authCodeCookie = new AuthCodeCookie(request,response);if (!authCodeCookie.getAuthCode().equals(form.getAuthCode())) {//验证码不正确errors.add(";error.login.authcode";, new ActionMessage(";error.login.authcode";));this.saveErrors(request, errors);return mapping.getInputForward();}User user = this.getUserService().get(form.getUserId());if(user==null){errors.add(";er";, new ActionMessage(";er";));this.saveErrors(request, errors);return mapping.getInputForward();}Util util = new Util();if(!util.hash(form.getPassword()).equals(user.getPassword())){errors.add(";error.login.password";, new ActionMessage(";error.login.password";));this.saveErrors(request, errors);return mapping.getInputForward();}// 一旦登录成功,创建sessionHttpSession session = request.getSession();UserSession userSession = new UserSession();userSession.setUser(user);session.setAttribute(ER_SESSION_KEY, userSession);//把UserSession传递到下个页面// 并且修改用户登录时间,登录次数+1user.setLastLoginDate(Util.getCurrentDate(";yyyyMMdd hhmmss";));user.setLoginTimes(Integer.valueOf(user.getLoginTimes().intValue()+1));this.getUserService().update(user);System.out.println(";----------------------------------------------------";) ;// // 获取用户对应的系统应用菜单List allModuleList = this.getModuleService().getModuleTree(Integer.parseInt(user.getMenuLevel()));//0代表根菜单// List allModuleList = this.getModuleService().getModuleTree(1);//0代表主菜单// System.out.println(";allModuleList.size=";+allModuleList.size()); // for(int i=0;i<;allModuleList.size();i++){//System.out.println(";";+((Module)allModuleList.get(i)).getModuleName());// }Iterator menu = allModuleList.iterator();Vector parentV = new Vector();Vector childV = new Vector();Module m;while (menu.hasNext()) {m = (Module) menu.next();if(user.getPermission().indexOf(";[";+m.getId()+";]";)!=-1){if (m.getParentId().intValue() == 0) {parentV.add(m);} else {childV.add(m);}}}request.getSession().setAttribute(";parentVector";, parentV);request.getSession().setAttribute(";childVector";, childV);System.out.println(";初始化完毕";);return mapping.findForward(";userPanel";);}jsp:<;%@ page contentType=";text/html;charset=UTF-8";%>;<;%@ taglib uri=";/WEB-INF/struts-bean.tld"; prefix=";bean";%>;<;%@ taglib uri=";/WEB-INF/struts-html.tld"; prefix=";html";%>;<;%@ taglib uri=";/WEB-INF/struts-logic.tld"; prefix=";logic";%>;<;jsp:useBean id=";user_session"; scope=";session";type=";erSession"; />;<;%er user = null;if (user_session != null)user = user_session.getUser();//根据权限获得菜单,这里权限用Telephone替代一下先String str = user.getTelephone();%>;<;html>;<;head>;<;meta http-equiv=";Content-Type"; content=";text/html; charset=UTF-8";>;<;title>;LEFT<;/title>;<;link rel=";stylesheet"; href=";css/style.css"; type=";text/css";>;<;script language=";JavaScript";>;<;!--function doExit(){if (confirm(";您确定要退出帐单门户系统吗?";)){window.open(";login.portal?action=logout";,";_parent";,";";);}}//-->;<;/script>;<;script language=";JavaScript";>;var w=200;function closenavi() {w-=200;if (w>;-10) {window.parent.testframeset.cols = ''+w+',*';repeat=setTimeout(";closenavi()";,10);}else {clearTimeout(repeat);w=200;}}function loginOutPage() {document.forms[1].SIGN_OFF.click();}function initIt(){divCount = document.all.tags(";DIV";);for (i=0; i<;divCount.length; i++) {obj = divCount(i);if (obj.className == ";child"; || obj.className == ";child1";) obj.style.display = ";none";;}}function expandIt(el) {obj = eval(";page"; + el);obj2 = eval(";main"; + el);if (obj.style.display == ";none";) {obj.style.display = ";block";;}else {obj.style.display = ";none";;}}onload = initIt;var judge=0;function expandall(o) {if (judge==0) {divCount2 = document.all.tags(";DIV";);for (i=0; i<;divCount2.length; i++) {obj2 = divCount2(i);if (obj2.className == ";child"; || obj.className == ";child1"; || obj2.style.display == ";none";){obj2.style.display = ";block";;}if (obj2.className == ";menu";){//obj2.all.tags('img')[0].src='images/treeimg/tminus.gif';obj2.all.tags('img')[0].src='images/openfolder1.gif';}}judge=1;o.src='images/icon-closeall.gif';o.alt='全部折叠';}else {divCount2 = document.all.tags(";DIV";);for (i=0; i<;divCount2.length; i++) {obj2 = divCount2(i);if (obj2.className == ";child"; || obj.className == ";child1"; || obj2.style.display == ";block";){obj2.style.display = ";none";;}if (obj2.className == ";menu";){obj2.all.tags('img')[0].src='images/folder1.gif';}}judge=0;o.src='images/icon-expandall.gif';o.alt='全部展开';}}function quit(form) {window.close()}function loginOutPage() {document.forms[0].SIGN_OFF.click();}<;/script>;<;/head>;<;body bgcolor=";#D8DADA"; class=";bodyTop";>;<;center>;<;table width=";161"; border=";0"; cellspacing=";0"; cellpadding=";0";>;<;tr>;<;td>;<;table style=";margin-top: 10px; margin-bottom: 10px"; width=";138";border=";0"; align=";center"; cellpadding=";0"; cellspacing=";0";>;<;tr>;<;td>;<;img src=";images/001.jpg"; width=";138"; height=";6";>;<;/td>;<;/tr>;<;tr>;<;td class=";msBack";>;<;table width=";130"; border=";0"; align=";center"; cellpadding=";3";cellspacing=";0";>;<;tr>;<;td width=";19";>;<;img src=";images/em44.gif"; width=";19"; height=";19";>;<;/td>;<;td class=";message";>;您有新的帐单信息<;/td>;<;/tr>;<;tr>;<;td>;<;img src=";images/em44.gif"; width=";19"; height=";19";>;<;/td>;<;td class=";message";>;您有新的支付信息<;/td>;<;/tr>;<;/table>;<;/td>;<;/tr>;<;tr>;<;td>;<;img src=";images/002.jpg"; width=";138"; height=";6";>;<;/td>;<;/tr>;<;/table>;<;/td>;<;/tr>;<;/table>;<;logic:iterate id=";module"; name=";parentVector";type=";com.worthtech.billportal.bean.Module";indexId=";index";>;<;%int i = ((ng.Integer) pageContext.findAttribute(";index";)).intValue();%>;<;div id=<;%=";main"; + i%>; class=";title";onClick=";expandIt(<;%=";"; + i%>;); return false";>;<;%if(str.indexOf(";[";+module.getId()+";]";)!=-1){%>;<;table class=";TableLeftTop"; style=";margin-top: 10px"; width=";138";border=";0"; cellspacing=";0"; cellpadding=";4";>;<;tr>;<;td background=";images/LeftMenuBack.jpg";>;<;div align=";center";>;<;%=module.getModuleName()%>;<;/div>;<;/td>;<;/tr>;<;/table>;<;%}%>;<;/div>;<;div id=<;%=";page"; + i%>; class=";child";>;<;table class=";TableLeftView"; width=";170"; border=";0"; cellspacing=";0";cellpadding=";0";>;<;logic:iterate id=";childModule"; name=";childVector";type=";com.worthtech.billportal.bean.Module";>;<;%if(str.indexOf(";[";+childModule.getId()+";]";)!=-1&;&;childModule.getParent ID().intValue()==module.getId().intValue()){%>;<;tr>;<;td width=";44";>;<;div align=";right";>;<;img src=";images/t.gif"; width=";19"; height=";20";>;<;/div>;<;/td>;<;td width=";161";>;<;a href=<;%=childModule.getActionURL()%>; target=";mainFrame";>;<;%=childModule.getModuleName()%>;<;/a>;<;/td>;<;/tr>;<;%}%>;<;/logic:iterate>;<;/table>;<;/div>;<;/logic:iterate>;<;table style=";margin-top: 10px"; width=";161"; border=";0";cellspacing=";0"; cellpadding=";2";>;<;tr>;<;td>;<;table width=";141"; border=";0"; align=";center"; cellpadding=";2";cellspacing=";0";>;<;tr>;<;td>;<;div align=";center";>;<;a href=";#"; onclick=";doExit();";>;<;imgsrc=";images/ico01.gif";width=";65"; height=";15"; border=";0";class=";MouseOver";>; <;/a>;<;/div>;<;/td>;<;td>;<;div align=";center";>;<;ahref=";user.portal?action=password";target=";mainFrame";>;<;imgclass=";MouseOver";src=";images/ico02.gif";width=";65"; height=";15"; border=";0";>;<;/a>;<;/div>;<;/td>;<;/tr>;<;/table>;<;/td>;<;/tr>;<;/table>;<;/center>;<;/body>;<;/html>;。
Java登录窗口源代码第1步:完成登陆框概述首先导入所需要的类分别为:JFrame,Dimension,Toolkik.创建JFrame对象,调用Jframe中的方法设置登录框的大小、在屏幕中显示的位置以及设置窗体的可视性等等。
利用Toolkit类中的方法获得屏幕的大小,这样可以让登录框在任何的分辨率下有同样的效果。
利用Dimetion对象存储屏幕大小数据。
以下是程序代码import java.awt.Dimension;import java.awt.Toolkit;import javax.swing.JFrame;class Deng{public JFrame jf=new JFrame("酒店管理系统");public Toolkit toolkit=Toolkit.getDefaultToolkit(); public Dimension sc=toolkit.getScreenSize(); 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);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}public class Denglu{public static void main(String args[]){new Deng();}}程序运行结果:图1:程序运行结果第二步:在等陆框中添加组建概述先导入所需组建的类Container、JLabel|、JTextField、JPasswordField、JButton。
用Container 获得面板。
将面板的布局管理器设为空,使用绝对定位的方法添加组建。
利用JLabel类创建两个标签非别存放“用户名”和“密码”,利用JTextField和JPasswordField分别创建文本框对象和密码框对象。
利用方法setSize()和setLocation()设置合适的大小和位置。
以下是修改后的程序代码:import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPasswordField;import javax.swing.JTextField;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 Deng(){con.setLayout(null);jf.setSize(sc.width/3,sc.height*10/25);jf.setLocation(sc.width/3,sc.height/4);con.setLayout(null);jf.setSize(sc.width/3,sc.height*10/25);jf.setLocation(sc.width/3,sc.height/4);jf.setResizable(false);name1.setLocation(80,30);name1.setSize(100,100);name1.setForeground(Color.white);pass1.setLocation(80,90);pass1.setSize(100,100);pass1.setForeground(Color.white);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);button2.setSize(90,25);button2.setLocation(220,180);con.add(name1);con.add(pass1);con.add(textName);con.add(textPs);con.add(button1);con.add(button2);con.setBackground(Color.black);jf.setResizable(false);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}public class Denglu{public static void main(String args[]){new Deng();}}是程序运行结果图2:程序运行结果第三步:登录框的美化概述导入所需要的类设置字体的类Font,图像类Image和ImageIcon。
创建Font对象设置字体的显示,利用Image、ImageIcon修改,添加图片一下是程序代码import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.Toolkit;import java.awt.Image;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPasswordField;import javax.swing.JTextField;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);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("image/ye.gif");jf.setIconImage(im.getImage());name1.setLocation(80,30);name1.setSize(100,100);name1.setFont(font1);name1.setForeground(Color.white);pass1.setLocation(80,90);pass1.setSize(100,100);pass1.setForeground(Color.white);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/yeye.jpg");JLabel bg=new JLabel(bgim);Container laycon=jf.getLayeredPane();bg.setSize(jf.getSize().width,jf.getSize().height);bgim.setImage(bgim.getImage().getScaledInstance(bg.get Size().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 class Denglu{public static void main(String args[]){new Deng();}}程序运行结果图3:程序运行结果。