-2
package setup;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class frnd_list extends javax.swing.JFrame {
String x=null;

public frnd_list(){
    initComponents();
    DefaultTableModel x=(DefaultTableModel)tbl.getModel();

    try {
    int zx=0;

Class.forName("java.sql.Driver");

Connection c=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/dtb","root","");
Statement s=(Statement) c.createStatement();
String q="select fullname, username from acc ;";

ResultSet rs=s.executeQuery(q);


while (rs.next())
{
    String a1=rs.getString("fullname");
    String a2=rs.getString("username");
String a3=a1+"  ("+a2+")";
zx=zx+1;

x.addRow(new Object[]{a3});}
System.out.print(zx);


}

catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());

} 
    }

    @SuppressWarnings("unchecked")
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbl = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null}
            },
            new String [] {
                "friend List"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbl);

        jButton1.setText("Dashboard");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Profile");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(68, 68, 68))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(0, 14, Short.MAX_VALUE))
        );

        pack();
    }                      

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

this.setVisible(false);
dashboard obj = new dashboard(x);
obj.setVisible(true);
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    this.setVisible(false);
    new profile().setVisible(true);
    }                                        

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frnd_list.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frnd_list.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frnd_list.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frnd_list.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frnd_list().setVisible(true);
            }
        });
    }
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbl;
}

此代码中没有一个错误。但是每次我调试它而不是打开 gui 界面时,它只显示绿色焦点中的下一行“public frnd_list(){”行获得绿色焦点我不知道这意味着什么?

4

4 回答 4

3

可能是因为您在该行创建了一个断点。尝试删除它或尝试运行而不是调试。

于 2012-05-28T09:48:16.927 回答
2

将 Class.forName("java.sql.Driver") 替换为 Class.forName("com.mysql.jdbc.Driver") 并为 MySql Driver 设置类路径。

于 2012-05-28T09:54:42.743 回答
0

使用调试器启动应用程序时,您可以处于单步模式,在源代码中,当前执行的行以绿色突出显示。通常有一个“运行”按钮(右指三角形)。有调试教程;这为这项基本任务提供了更好的见解。

于 2012-05-28T09:53:09.540 回答
0

如果您在 Eclipse 中调试,请尝试按 F6 进行下一步,然后按 F8 运行(直到下一个断点)。

于 2012-05-28T09:53:25.647 回答