当我点击登陆按钮的时候,就会跳转到聊天界面。但是我的java程序还是没有办法实现这个功能,帮我改一下
packagesql;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing...
package sql;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class liaotian extends JFrame implements ActionListener{
JPanel jpanel1;
TextArea textArea1;
TextField textField3;
JButton jButton1;
liaotian(){
this.setTitle("对话");
this.setSize(600,600);
this.setVisible(true);
jpanel1=new JPanel();
textArea1=new TextArea(15,15);
jButton1=new JButton("发送");
textField3=new TextField(10);
jpanel1.add(textArea1);
jpanel1.add(jButton1);jpanel1.add(textField3);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton1){
textArea1.setText(textField3.getText());
textField3.setText("");
}}}
public class lianxi2 extends JFrame implements ActionListener{
JPanel jpanel;
Label label1;
TextField textField1;
Label label2;
TextField textField2;
JButton jButton;
static String col11,col12;
public lianxi2(){
super("登陆");
jpanel=new JPanel();
this.setVisible(true);
this.setSize(600,600);
label1=new Label("账号");
textField1=new TextField(15);
label2=new Label("密码");
textField2=new TextField(15);
jButton=new JButton("登陆");
jpanel.add(label1); jpanel.add(textField1);
jpanel.add(label2); jpanel.add(textField2);
jpanel.add(jButton);
this.add(jpanel);
}
public static void main(String[] args) {
lianxi2 lt = new lianxi2();
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载数据库驱动
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;Database=denglu","sa","123456");//链接数据库
Statement statement=conn.createStatement();
ResultSet rs = statement.executeQuery("select * from denglu ");
while(rs.next()){
col11= rs.getString("zhanghao");
col12 = rs.getString("mima");
}
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
if(textField1.getText()==col11){
if(textField2.getText()==col12){
liaotian m=new liaotian();
m.setVisible(true);
}
}
}
}} 展开
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class liaotian extends JFrame implements ActionListener{
JPanel jpanel1;
TextArea textArea1;
TextField textField3;
JButton jButton1;
liaotian(){
this.setTitle("对话");
this.setSize(600,600);
this.setVisible(true);
jpanel1=new JPanel();
textArea1=new TextArea(15,15);
jButton1=new JButton("发送");
textField3=new TextField(10);
jpanel1.add(textArea1);
jpanel1.add(jButton1);jpanel1.add(textField3);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton1){
textArea1.setText(textField3.getText());
textField3.setText("");
}}}
public class lianxi2 extends JFrame implements ActionListener{
JPanel jpanel;
Label label1;
TextField textField1;
Label label2;
TextField textField2;
JButton jButton;
static String col11,col12;
public lianxi2(){
super("登陆");
jpanel=new JPanel();
this.setVisible(true);
this.setSize(600,600);
label1=new Label("账号");
textField1=new TextField(15);
label2=new Label("密码");
textField2=new TextField(15);
jButton=new JButton("登陆");
jpanel.add(label1); jpanel.add(textField1);
jpanel.add(label2); jpanel.add(textField2);
jpanel.add(jButton);
this.add(jpanel);
}
public static void main(String[] args) {
lianxi2 lt = new lianxi2();
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载数据库驱动
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;Database=denglu","sa","123456");//链接数据库
Statement statement=conn.createStatement();
ResultSet rs = statement.executeQuery("select * from denglu ");
while(rs.next()){
col11= rs.getString("zhanghao");
col12 = rs.getString("mima");
}
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
if(textField1.getText()==col11){
if(textField2.getText()==col12){
liaotian m=new liaotian();
m.setVisible(true);
}
}
}
}} 展开
展开全部
public Testc(){
super("登陆");
jpanel=new JPanel();
this.setVisible(true);
this.setSize(600,600);
label1=new Label("账号");
textField1=new TextField(15);
label2=new Label("密码");
textField2=new TextField(15);
jButton=new JButton("登陆");
jpanel.add(label1); jpanel.add(textField1);
jpanel.add(label2); jpanel.add(textField2);
jpanel.add(jButton);
this.add(jpanel);
jButton.addActionListener(this); //给jbutton加上监听
}
上面的也要修改一下
liaotian(){
this.setTitle("对话");
this.setSize(600,600);
this.setVisible(true);
jpanel1=new JPanel();
textArea1=new TextArea(15,15);
jButton1=new JButton("发送");
textField3=new TextField(10);
jpanel1.add(textArea1);
jpanel1.add(jButton1);jpanel1.add(textField3);
this.add(jpanel1);
}
追问
我运行程序发现当点击登陆按钮的时候,还是没办法跳转到聊天界面。你是运行一下程序
追答
你肯定是用户名密码没有校验成功。。你这么写用户名密码取的是数据库最后一条数据,你用最后一个用户名密码试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询