如何用JAVA编写一个简单用户登陆界面?
我想利用JAVA编写一个简单的用户登陆界面,用于信息管理系统的,应该如何着手呢?请高手指教!
搜索更多相关的解决方案:
JAVA 界面 编写 用户 登陆
----------------解决方案--------------------------------------------------------
你是指用Swing写?还有用Jsp写?
----------------解决方案--------------------------------------------------------
简单,简单,
import java.awt.*;
import javax.swing.*;
public class guanli_chaozuo extends JFrame{
public JLabel jusername;
public JLabel jpassword,jpassword_sure;
public JTextField username;
public JPasswordField password,password_sure;
public JButton jb1,jb2;
public void make_GUI(){
jusername=new JLabel("用户名* ");
jpassword=new JLabel("新密码* ");
jpassword_sure=new JLabel("新密码确认*");
jb1=new JButton("确定");
jb2=new JButton("取消");
username=new JTextField(10);
password=new JPasswordField(10);
password_sure=new JPasswordField(10);
Container cp=getContentPane();
JPanel jp=new JPanel();
JPanel jp2 =new JPanel();
jp.setLayout(new GridLayout(4,8,20,10));
jp.add(jusername);jp.add(username);
jp.add(jpassword);jp.add(password);
jp.add(jpassword_sure);jp.add(password_sure);
jp2.add(jb1);
jp2.add(jb2);
cp.add(jp,BorderLayout.CENTER);
cp.add(jp2,BorderLayout.SOUTH);
setSize(300,200);
setVisible(true);
}
public guanli_chaozuo(String s){
super(s);
make_GUI();
}
public void exit(){
this.dispose();
}
}
----------------解决方案--------------------------------------------------------
非数据库的
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class UserFrame extends JFrame {
public UserFrame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
lblName.setText("用户名:");
lblName.setBounds(new Rectangle(26, 52, 60, 32));
btnOK.setBounds(new Rectangle(38, 196, 91, 38));
btnOK.setText("确定");
btnOK.addActionListener(new UserFrame_btnOK_actionAdapter(this));
btnCencal.setBounds(new Rectangle(173, 196, 91, 37));
btnCencal.setText("取消");
btnCencal.addActionListener(new UserFrame_btnCencal_actionAdapter(this));
txtName.setBounds(new Rectangle(126, 52, 111, 31));
txtPWD.setBounds(new Rectangle(126, 135, 110, 31));
lblMessage.setBounds(new Rectangle(83, 92, 165, 28));
this.getContentPane().add(lblName);
this.getContentPane().add(lblPWD);
this.getContentPane().add(btnOK);
this.getContentPane().add(btnCencal);
this.getContentPane().add(txtName);
this.getContentPane().add(txtPWD);
this.getContentPane().add(lblMessage);
lblPWD.setText("密码:");
lblPWD.setBounds(new Rectangle(26, 131, 70, 37));
}
JLabel lblName = new JLabel();
JLabel lblPWD = new JLabel();
JButton btnOK = new JButton();
JButton btnCencal = new JButton();
JTextField txtName = new JTextField();
JTextField txtPWD = new JTextField();
JLabel lblMessage = new JLabel();
public void btnOK_actionPerformed(ActionEvent e) {
String User;
String PWD;
User=txtName.getText();
PWD=txtPWD.getText();
if(User.equals("admin")&&PWD.equals("admin888")){
lblMessage.setText("登陆成功");
AddUserinfo au = new AddUserinfo();
au.setTitle("信息修改器");
au.setBounds(50, 50, 400, 310);
au.setVisible(true);
this.dispose();
}else{
lblMessage.setText("登陆失败");
}
}
public void btnCencal_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class UserFrame_btnCencal_actionAdapter implements ActionListener {
private UserFrame adaptee;
UserFrame_btnCencal_actionAdapter(UserFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnCencal_actionPerformed(e);
}
}
class UserFrame_btnOK_actionAdapter implements ActionListener {
private UserFrame adaptee;
UserFrame_btnOK_actionAdapter(UserFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOK_actionPerformed(e);
}
public static void main(String [] args){
UserFrame uf=new UserFrame();
uf.setBounds(0,0,350,300);
uf.setTitle("登陆器");
uf.setVisible(true);
}
}
----------------解决方案--------------------------------------------------------
用JSP写,而且要连接数据库的!谢谢指教!
----------------解决方案--------------------------------------------------------
int mark; %> request.setCharacterEncoding("GB2312"); Statement stmt=conn.createStatement(); String pass=(request.getParameter("password")).trim(); String name=(request.getParameter("name")).trim(); if(name=="" || name==null){ out.print("用户名不能为空"+" out.println("返回重新登陆"); } else{ String sql="select * from login where name='"+name+"' and password='"+pass+"'" ; ResultSet rs=stmt.executeQuery(sql); if(rs.next()){ int id=rs.getInt("Id"); mark=rs.getInt("mark"); out.println("登陆成功!"+" session.setAttribute("login","ok"); session.setAttribute("name",name); session.setAttribute("id",id); session.setAttribute("mark",mark); out.println("进入首页"); if(mark==1){ %> |
浏览器将在3秒后自动跳转到首页 |
浏览器将在3秒后自动跳转到首页
else{
out.print("登陆失败"+"
"+"
");
out.println("返回重新登陆");
}
}
%>
----------------解决方案--------------------------------------------------------
原帖由 [bold][underline]gtrgtr[/underline][/bold] 于 2007-12-19 18:45 发表 [url=http://bbs.bc-cn.net/redirect.php?goto=findpost&pid=1154541&ptid=193310][/url]
非数据库的
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class UserFrame extends JFrame {
pu ...
我用你这个试一下,结果提示找不到....
----------------解决方案--------------------------------------------------------
4楼这位仁兄,你的代码有一处不能通过编译哎
程序代码:
AddUserinfo au = new AddUserinfo();要不你看看怎么回事
----------------解决方案--------------------------------------------------------