【请教】如何用JAVA SWING 做用户登录 如何用SWING 做用户登录,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 取得textField的数据再去和数据库比较就可以了上学期做的一个课程设计http://www.zhongzhiit.com/UserFiles/Image/Snap2.jpghttp://www.zhongzhiit.com/UserFiles/Image/Snap1.jpg //LoginDialogDemo.javaimport java.awt.*;import javax.swing.*;import java.awt.event.*;public class LoginDialogDemo extends JFrame { JButton button = new JButton("Click Me"); JPanel panel = new JPanel(new FlowLayout()); public LoginDialogDemo() { final JFrame frame = this; this.getContentPane().add(panel,BorderLayout.SOUTH); panel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showLoginDialog(frame); } }); this.setSize(300,200); this.setTitle("显示登陆对话框"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.show(); } void showLoginDialog(JFrame frame){ JPanel p = new JPanel(new GridLayout(0,1)); JTextField tfUserName = new JTextField(); JPasswordField tfPassword = new JPasswordField(); p.add(new JLabel("Username: ")); p.add(tfUserName); p.add(new JLabel("Password: ")); p.add(tfPassword); if (JOptionPane.showConfirmDialog(frame // may want to pass your application frame here ,p ,"Login" ,JOptionPane.OK_CANCEL_OPTION ,JOptionPane.PLAIN_MESSAGE ) == JOptionPane.OK_OPTION) { System.out.println("User Name:"+tfUserName.getText()); System.out.println("Password:" + new String(tfPassword.getPassword())); } } public static void main(String[] args) { LoginDialogDemo frame = new LoginDialogDemo(); }} 什么菜问题.都问了.如果你是手写还可以谅解.如果用IDE的话.就不应该问这个了. 很简单的问题!网上DEMO一大堆! SWT 如何获取窗口切换事件 date转Timestamp出现的问题 redhat E4上如何设置tomcat4.1自动启动? java 的 BufferedReader 问题 如何添加一个在swing的frame按下esc的退出事件 java newbie 这样可以正常赋值吗? 关于java的学习 请教一个Java和数据库的问题 安装IDEA时出现“can not load jvm.dll,请重装jvm或更换” 新手的问题,很简单的,麻烦各位高手指点!:) ★★求SWT/JFace中文教程★★ 晕死,Date获取的系统时间和真实时间为什么会相差8小时
上学期做的一个课程设计
http://www.zhongzhiit.com/UserFiles/Image/Snap2.jpg
http://www.zhongzhiit.com/UserFiles/Image/Snap1.jpg
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class LoginDialogDemo extends JFrame {
JButton button = new JButton("Click Me");
JPanel panel = new JPanel(new FlowLayout()); public LoginDialogDemo() {
final JFrame frame = this;
this.getContentPane().add(panel,BorderLayout.SOUTH);
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showLoginDialog(frame);
}
});
this.setSize(300,200);
this.setTitle("显示登陆对话框");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show();
} void showLoginDialog(JFrame frame){
JPanel p = new JPanel(new GridLayout(0,1));
JTextField tfUserName = new JTextField();
JPasswordField tfPassword = new JPasswordField();
p.add(new JLabel("Username: "));
p.add(tfUserName);
p.add(new JLabel("Password: "));
p.add(tfPassword);
if (JOptionPane.showConfirmDialog(frame // may want to pass your application frame here
,p
,"Login"
,JOptionPane.OK_CANCEL_OPTION
,JOptionPane.PLAIN_MESSAGE
) == JOptionPane.OK_OPTION) {
System.out.println("User Name:"+tfUserName.getText());
System.out.println("Password:" + new String(tfPassword.getPassword()));
}
} public static void main(String[] args) {
LoginDialogDemo frame = new LoginDialogDemo();
}
}