请大家帮忙急急急!求java swing做一个Login panel谢谢! 请大家帮忙急急急!求java swing做一个Login panel有username输入,password输入,Login按钮,下行有输入wrong password or Login success信息显示,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一分不给还求问题,又不是叫你给rmb,给点分都这样,吃白饭的别来 我原来做的登陆页面import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.Frame;import java.awt.Insets;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.util.Date;import java.util.Enumeration;import javax.accessibility.Accessible;import javax.accessibility.AccessibleState;import javax.swing.BorderFactory;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.plaf.FontUIResource;public class Login extends JDialog { //GUI界面声明 JPanel contentPane; JPanel up_jpn=new JPanel(); JPanel down_jpn=new JPanel(); JPanel input_jpn=new JPanel(); JLabel id_jlb=new JLabel(); JTextField id_jtf=new JTextField(); JLabel password_jlb=new JLabel(); JCheckBox autoLogin=new JCheckBox(); JCheckBox udnerLogin=new JCheckBox(); JPasswordField userPassword_jpf=new JPasswordField(); private String id_str="",password_str="",ip_str=""; private char[] userPassword_char_Arr; JButton OK_btn=new JButton(); JButton Cancel_btn=new JButton(); public Login(Frame owner, String title, boolean modal) { super(owner, title, modal);//设置标题 try { setDefaultCloseOperation(DISPOSE_ON_CLOSE); jbInit(); pack(); this.setResizable(false);//设置不可编辑 this.setSize(300,220);//设置大小 } catch (Exception exception) { exception.printStackTrace(); } } public Login() { this(new Frame(), "LOGIN", true); } /** * 界面设计 * @throws Exception */ private void jbInit() throws Exception { contentPane = (JPanel) getContentPane(); contentPane.setLayout(null); up_jpn.setBounds(0,0,285,45); up_jpn.setBorder(BorderFactory.createLineBorder(Color.BLUE)); down_jpn.setLayout(null); down_jpn.setBounds(0,45,285,150); down_jpn.setBorder(BorderFactory.createLineBorder(Color.GREEN)); input_jpn.setBounds(5,5,275,90); input_jpn.setBorder(BorderFactory.createLineBorder(Color.RED)); input_jpn.setLayout(null); id_jlb.setText("帐号:"); id_jlb.setForeground(Color.blue); id_jlb.setBounds(30,15,50,20); id_jtf.setText("sd080826"); id_jtf.setBounds(80,15,120,20); password_jlb.setText("密码:"); password_jlb.setForeground(Color.blue); password_jlb.setBounds(30,40,50,20); userPassword_jpf.setText("123"); userPassword_jpf.setBounds(80,40,120,20); autoLogin.setText("自动登录"); autoLogin.setMargin(new Insets(2, 2, 2, 2)); autoLogin.setFont(new java.awt.Font("Dialog", Font.CENTER_BASELINE,11)); autoLogin.setBounds(45,65,80,15); udnerLogin.setText("隐身登录"); udnerLogin.setFont(new java.awt.Font("Dialog", Font.CENTER_BASELINE,11)); udnerLogin.setBounds(125,65,80,15); OK_btn.setText("确定"); OK_btn.setForeground(Color.blue); OK_btn.setMargin(new Insets(2, 2, 2, 2)); OK_btn.setBounds(60,110,50,20); OK_btn.addActionListener(new Login_OK_btn_actionAdapter(this)); this.getRootPane().setDefaultButton(OK_btn); Cancel_btn.setText("取消"); Cancel_btn.setForeground(Color.blue); Cancel_btn.setMargin(new Insets(2, 2, 2, 2)); Cancel_btn.setBounds(180,110,50,20); Cancel_btn.addActionListener(new Login_Cancel_btn_actionAdapter(this)); input_jpn.add(id_jlb); input_jpn.add(id_jtf); input_jpn.add(password_jlb); input_jpn.add(userPassword_jpf); input_jpn.add(autoLogin); input_jpn.add(udnerLogin); down_jpn.add(OK_btn); down_jpn.add(Cancel_btn); down_jpn.add(input_jpn); contentPane.add(up_jpn); contentPane.add(down_jpn); } /** * 登录事件 * @param e */ public void Login_OK_btn_actionPerformed(ActionEvent e) { id_str=id_jtf.getText().toString().trim(); userPassword_char_Arr=userPassword_jpf.getPassword(); int _password_int_lenth=userPassword_char_Arr.length; password_str=""; for(int _i=0;_i<_password_int_lenth;_i++){ password_str=password_str+userPassword_char_Arr[_i]; } if(id_str==null||id_str.equals("")||password_str==null||password_str.equals("")){ JOptionPane.showMessageDialog(this, "帐号和密码都不能为空!"); }else{ //和服务器或数据库进行通信连接以及连接后的结果的相关处理 } } /** * 取消事件 * @param e */ public void Login_Cancel_btn_actionPerformed(ActionEvent e) { id_str="";//我原来的是主页面根据登陆页面的id来判断是否结束的,你可以自己写退出 this.setVisible(false); } public String getIp_str() { return ip_str; } public void setIp_str(String ip_str) { this.ip_str = ip_str; } public String getId_str() { return id_str; } public void setId_str(String id_str) { this.id_str = id_str; } public String getPassword_str() { return password_str; } public void setPassword_str(String password_str) { this.password_str = password_str; }}class Login_OK_btn_actionAdapter implements ActionListener { private Login adaptee; Login_OK_btn_actionAdapter(Login adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.Login_OK_btn_actionPerformed(e); }}class Login_Cancel_btn_actionAdapter implements ActionListener { private Login adaptee; Login_Cancel_btn_actionAdapter(Login adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.Login_Cancel_btn_actionPerformed(e); }} 如何将Java程序转化成NT系统服务? ResultSet的问题 java类如何随操作系统启动,路过有分(散分)! 又见这个异常:"输入值对于日期格式不够长",实在找不出哪错了 问一下子类父类的问题。谢谢很简单。帮忙回答下。 怎么在JSP页之间用request对象传递java.util.Properties对象? java怎么调用linux下C语言的可执行程序???急等!!!!! cmd不能编译java问题怎么解决? 问一个网络数据报的问题,小菜鸟想了一个下午了。大家请进,谢谢 为什么老是找不到类? 关于实例的作用域问题 关于 Deflater 问题
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;import javax.accessibility.Accessible;
import javax.accessibility.AccessibleState;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;
public class Login extends JDialog {
//GUI界面声明
JPanel contentPane;
JPanel up_jpn=new JPanel();
JPanel down_jpn=new JPanel();
JPanel input_jpn=new JPanel();
JLabel id_jlb=new JLabel();
JTextField id_jtf=new JTextField();
JLabel password_jlb=new JLabel();
JCheckBox autoLogin=new JCheckBox();
JCheckBox udnerLogin=new JCheckBox();
JPasswordField userPassword_jpf=new JPasswordField();
private String id_str="",password_str="",ip_str="";
private char[] userPassword_char_Arr;
JButton OK_btn=new JButton();
JButton Cancel_btn=new JButton(); public Login(Frame owner, String title, boolean modal) {
super(owner, title, modal);//设置标题
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
this.setResizable(false);//设置不可编辑
this.setSize(300,220);//设置大小
} catch (Exception exception) {
exception.printStackTrace();
}
} public Login() {
this(new Frame(), "LOGIN", true);
} /**
* 界面设计
* @throws Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null); up_jpn.setBounds(0,0,285,45);
up_jpn.setBorder(BorderFactory.createLineBorder(Color.BLUE)); down_jpn.setLayout(null);
down_jpn.setBounds(0,45,285,150);
down_jpn.setBorder(BorderFactory.createLineBorder(Color.GREEN));
input_jpn.setBounds(5,5,275,90);
input_jpn.setBorder(BorderFactory.createLineBorder(Color.RED));
input_jpn.setLayout(null);
id_jlb.setText("帐号:");
id_jlb.setForeground(Color.blue);
id_jlb.setBounds(30,15,50,20);
id_jtf.setText("sd080826");
id_jtf.setBounds(80,15,120,20);
password_jlb.setText("密码:");
password_jlb.setForeground(Color.blue);
password_jlb.setBounds(30,40,50,20);
userPassword_jpf.setText("123");
userPassword_jpf.setBounds(80,40,120,20);
autoLogin.setText("自动登录");
autoLogin.setMargin(new Insets(2, 2, 2, 2));
autoLogin.setFont(new java.awt.Font("Dialog", Font.CENTER_BASELINE,11));
autoLogin.setBounds(45,65,80,15);
udnerLogin.setText("隐身登录");
udnerLogin.setFont(new java.awt.Font("Dialog", Font.CENTER_BASELINE,11));
udnerLogin.setBounds(125,65,80,15);
OK_btn.setText("确定");
OK_btn.setForeground(Color.blue);
OK_btn.setMargin(new Insets(2, 2, 2, 2));
OK_btn.setBounds(60,110,50,20);
OK_btn.addActionListener(new Login_OK_btn_actionAdapter(this));
this.getRootPane().setDefaultButton(OK_btn);
Cancel_btn.setText("取消");
Cancel_btn.setForeground(Color.blue);
Cancel_btn.setMargin(new Insets(2, 2, 2, 2));
Cancel_btn.setBounds(180,110,50,20);
Cancel_btn.addActionListener(new Login_Cancel_btn_actionAdapter(this)); input_jpn.add(id_jlb);
input_jpn.add(id_jtf);
input_jpn.add(password_jlb);
input_jpn.add(userPassword_jpf);
input_jpn.add(autoLogin);
input_jpn.add(udnerLogin); down_jpn.add(OK_btn);
down_jpn.add(Cancel_btn);
down_jpn.add(input_jpn);
contentPane.add(up_jpn);
contentPane.add(down_jpn);
}
/**
* 登录事件
* @param e
*/
public void Login_OK_btn_actionPerformed(ActionEvent e) {
id_str=id_jtf.getText().toString().trim();
userPassword_char_Arr=userPassword_jpf.getPassword();
int _password_int_lenth=userPassword_char_Arr.length;
password_str="";
for(int _i=0;_i<_password_int_lenth;_i++){
password_str=password_str+userPassword_char_Arr[_i];
}
if(id_str==null||id_str.equals("")||password_str==null||password_str.equals("")){
JOptionPane.showMessageDialog(this, "帐号和密码都不能为空!");
}else{
//和服务器或数据库进行通信连接以及连接后的结果的相关处理
}
}
/**
* 取消事件
* @param e
*/
public void Login_Cancel_btn_actionPerformed(ActionEvent e) {
id_str="";//我原来的是主页面根据登陆页面的id来判断是否结束的,你可以自己写退出
this.setVisible(false);
} public String getIp_str() {
return ip_str;
} public void setIp_str(String ip_str) {
this.ip_str = ip_str;
} public String getId_str() {
return id_str;
} public void setId_str(String id_str) {
this.id_str = id_str;
} public String getPassword_str() {
return password_str;
} public void setPassword_str(String password_str) {
this.password_str = password_str;
}
}
class Login_OK_btn_actionAdapter implements ActionListener {
private Login adaptee;
Login_OK_btn_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.Login_OK_btn_actionPerformed(e);
}
}
class Login_Cancel_btn_actionAdapter implements ActionListener {
private Login adaptee;
Login_Cancel_btn_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.Login_Cancel_btn_actionPerformed(e);
}
}