有我就能赢 2015-05-06 01:32 采纳率: 100%
浏览 2709
已采纳

下面的java程序运行时为什么没有结果

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) {
    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){
lianxi2 m=new lianxi2();
m.setVisible(true);
}
}
}

}}

程序运行之后什么都没有出现

  • 写回答

1条回答 默认 最新

  • danielinbiti 2015-05-06 01:39
    关注
     public static void main(String[] args) {
        liaotian lt = new liaotian();//没有new jframe的对象呢,所以看不见界面
        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();
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多ip服务器站群如何搭建l2tp服务器
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗
  • ¥15 Sharepoint JS开发 付费技术指导
  • ¥15 输入程序运行仿真后,烟雾值不实时检测,变成固定值
  • ¥20 数据排序,可选择排序方向
  • ¥15 修改一下代码,考虑进程到达时间不同的情况
  • ¥15 帮我看看这是个啥题,带解题过程和结果,条件如下FCF = 290471.33 g1 = 15% r = 8% g2 = 4% n = 5
  • ¥15 edem模拟颗粒不显示或者生成失败