野
野汉
Unregistered / Unconfirmed
GUEST, unregistred user!
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class TestActionEvent2 extends WindowAdapter { //implements ActionListener{(这个加上就编译不了了?不知什么原因啊?)
TextField tf1,tf2;
Panel p1,p2,p3,p4,p5;
Label l1,l2;
Dialog dlg;
Frame f;
String password,password_from;
public void go(){
f = new Frame("登录窗体"
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p5=new Panel();
tf1=new TextField();
tf2=new TextField();
l1=new Label("姓名"
//Font lf1=new Font("Dialog",Font.PLAIN,20);
//l1.setFont(lf1);
l2=new Label("密码"
Font lf2=new Font("Helvetica",Font.PLAIN,20);
l2.setFont(lf2);
tf1.addFocusListener(new java.awt.event.FocusAdapter(){
public void focuslost(FocusEvent e) {
tf1_focuslost(e);}
});(这一段是注册监听器,那参数里写的是什么意思啊?下边四个都是这样啊?)
tf2.addFocusListener(new java.awt.event.FocusAdapter(){
public void focuslost(FocusEvent e) {
tf2_focuslost(e);}
});
Button b1 = new Button("确定"
b1.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e) {
b1_actionPerformed(e);}
});
Button b2 = new Button("退出"
b2.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e) {
b2_actionPerformed(e);}
});
p1.setLayout(new GridLayout(3,2,30,30));
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(b1);
p1.add(b2);
f.add(p1,"Center"
f.add(p2,"East"
f.add(p3,"South"
f.add(p4,"West"
f.add(p5,"North"
f.setSize(300,200);
f.setBackground(Color.white);
f.setLocation(200,500);
f.setVisible(true);
}
public static void main(String args[]) {
TestActionEvent2 sb=new TestActionEvent2();
sb.go();
}
public void b1_actionPerformed(ActionEvent e){ // b1_actionPerformed这段有错吗?为什么不运行TRY里的内容啊?运行出来点击确定按钮没有用啊!直接输出的是CATCH的语句?
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
Connection con = DriverManager.getConnection("jdbcdbc:dog", "", ""
Statement stmt=con.createStatement();
String sql="select * from yh";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next())
if((tf1.getText()).equals(rs.getString("name")){
password_from=rs.getString("password"
if((password).equals(password_from)){
dlg = new Dialog(f,"登录成功",true);
dlg.add("Center",new Label("您已经成功登录!",Label.CENTER));
dlg.setSize(250,100);
//dlg.pack();
dlg.addWindowListener(this);
dlg.setLocation(250,250);
dlg.setVisible(true);
//JOptionPane.showMessageDialog(this,"密码正确!","登录信息",JOptionPane.INFORMATION_MESSAGE);(这句什么意思啊?书上写的为什么运行不了啊?所以我改成上面的了,不知道为什么啊?)
}
else
{
dlg = new Dialog(f,"登录失败",true);
dlg.add("Center",new Label("用户不存在!请确认输入正确",Label.CENTER));
dlg.setSize(250,100);
dlg.addWindowListener(new java.awt.event.WindowAdapter(){
public void windowClosing(WindowEvent e) {
dlg_windowClosing(e);}});
dlg.setLocation(250,250);
dlg.setVisible(true);
//JOptionPane.showMessageDialog(this,"密码和用户名不符,请重新输入密码!","登录信息",JOptionPane.INFORMATION_MESSAGE););
} }
stmt.close();
con.close();}
catch(Exception ex){
System.out.println("连接数据库有问题"
}
}
public void dlg_windowClosing(WindowEvent e){
dlg.setVisible(false);
}
public void b2_actionPerformed(ActionEvent e){
System.exit(0);
}
public void tf1_focuslost(FocusEvent e){
}
public void tf2_focuslost(FocusEvent e){
password=tf2.getText();
}
}
我是一JAVA的初学者,希望各师哥师姐多多帮忙,这是我自己看书,自己编写的,不足之处多多指教,谢谢!
import java.awt.*;
import java.awt.event.*;
public class TestActionEvent2 extends WindowAdapter { //implements ActionListener{(这个加上就编译不了了?不知什么原因啊?)
TextField tf1,tf2;
Panel p1,p2,p3,p4,p5;
Label l1,l2;
Dialog dlg;
Frame f;
String password,password_from;
public void go(){
f = new Frame("登录窗体"
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p5=new Panel();
tf1=new TextField();
tf2=new TextField();
l1=new Label("姓名"
//Font lf1=new Font("Dialog",Font.PLAIN,20);
//l1.setFont(lf1);
l2=new Label("密码"
Font lf2=new Font("Helvetica",Font.PLAIN,20);
l2.setFont(lf2);
tf1.addFocusListener(new java.awt.event.FocusAdapter(){
public void focuslost(FocusEvent e) {
tf1_focuslost(e);}
});(这一段是注册监听器,那参数里写的是什么意思啊?下边四个都是这样啊?)
tf2.addFocusListener(new java.awt.event.FocusAdapter(){
public void focuslost(FocusEvent e) {
tf2_focuslost(e);}
});
Button b1 = new Button("确定"
b1.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e) {
b1_actionPerformed(e);}
});
Button b2 = new Button("退出"
b2.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e) {
b2_actionPerformed(e);}
});
p1.setLayout(new GridLayout(3,2,30,30));
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(b1);
p1.add(b2);
f.add(p1,"Center"
f.add(p2,"East"
f.add(p3,"South"
f.add(p4,"West"
f.add(p5,"North"
f.setSize(300,200);
f.setBackground(Color.white);
f.setLocation(200,500);
f.setVisible(true);
}
public static void main(String args[]) {
TestActionEvent2 sb=new TestActionEvent2();
sb.go();
}
public void b1_actionPerformed(ActionEvent e){ // b1_actionPerformed这段有错吗?为什么不运行TRY里的内容啊?运行出来点击确定按钮没有用啊!直接输出的是CATCH的语句?
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
Connection con = DriverManager.getConnection("jdbcdbc:dog", "", ""
Statement stmt=con.createStatement();
String sql="select * from yh";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next())
if((tf1.getText()).equals(rs.getString("name")){
password_from=rs.getString("password"
if((password).equals(password_from)){
dlg = new Dialog(f,"登录成功",true);
dlg.add("Center",new Label("您已经成功登录!",Label.CENTER));
dlg.setSize(250,100);
//dlg.pack();
dlg.addWindowListener(this);
dlg.setLocation(250,250);
dlg.setVisible(true);
//JOptionPane.showMessageDialog(this,"密码正确!","登录信息",JOptionPane.INFORMATION_MESSAGE);(这句什么意思啊?书上写的为什么运行不了啊?所以我改成上面的了,不知道为什么啊?)
}
else
{
dlg = new Dialog(f,"登录失败",true);
dlg.add("Center",new Label("用户不存在!请确认输入正确",Label.CENTER));
dlg.setSize(250,100);
dlg.addWindowListener(new java.awt.event.WindowAdapter(){
public void windowClosing(WindowEvent e) {
dlg_windowClosing(e);}});
dlg.setLocation(250,250);
dlg.setVisible(true);
//JOptionPane.showMessageDialog(this,"密码和用户名不符,请重新输入密码!","登录信息",JOptionPane.INFORMATION_MESSAGE););
} }
stmt.close();
con.close();}
catch(Exception ex){
System.out.println("连接数据库有问题"
}
}
public void dlg_windowClosing(WindowEvent e){
dlg.setVisible(false);
}
public void b2_actionPerformed(ActionEvent e){
System.exit(0);
}
public void tf1_focuslost(FocusEvent e){
}
public void tf2_focuslost(FocusEvent e){
password=tf2.getText();
}
}
我是一JAVA的初学者,希望各师哥师姐多多帮忙,这是我自己看书,自己编写的,不足之处多多指教,谢谢!