Free考研资料 - 免费考研论坛

 找回密码
 注册
打印 上一主题 下一主题

java高手帮看一下

[复制链接]
跳转到指定楼层
楼主
sdxuchenrui 发表于 08-6-9 07:15:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*
* Checeout.java
*
* Created on 2008年6月8日, 上午9:30
*/

package keytest;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.util.*;
import javax.swing.*;

/**
*
* @author  Owner
*/
public class Checeout extends javax.swing.JFrame {
    private Object jTable1;
   
   
    /** Creates new form Checeout */
    public Checeout() {
        initComponents();
        set();
    }

    //jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(vector1.toArray()));
    //jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "赵","钱","孙","李","周","吴","郑","王","陈","韩")};
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 348, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 198, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel9.setText("\u8bf7\u9009\u62e9");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jLabel10.setText("\u59d3\u540d");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField8)))
                .addContainerGap(263, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(133, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("tab1", jPanel2);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 382, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 228, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("tab2", jPanel4);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 387, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
        Vector v=this.getTextFieldVector("DoctorName");
        for(int j=0;j<jTable1.getRowCount();j++)
        {   jTable1.setValueAt(null, j, 0);}
            for(int i=0;i<v.size();i++)
            {
             jTable1.setValueAt((String)v.get(i), i, 0);
            }
    }//GEN-LAST:event_jComboBox2ActionPerformed
     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          MainJFrame mainFrane=new MainJFrame();
          mainFrane.setVisible(true);
          setVisible(false);
     }   
     
    public String getTextField(String wantName){
        String ID=(String)jComboBox2.getSelectedItem();
        TableInfo tableInfo=new TableInfo();
        
        String sql1="SELECT * FROM doctor where DoctorName="+ID;
        Vector vector11=new Vector();
         tableInfo.getInformation(sql1,wantName , vector11);
         return vector11.toString();
    }
public Vector getTextFieldVector(String wantName){
        String ID=(String)jComboBox1.getSelectedItem();
        TableInfo tableInfo=new TableInfo();
        
        String sql1="SELECT * FROM doctor where DoctorName="+ID;
        Vector vector11=new Vector();
         tableInfo.getInformation(sql1,wantName , vector11);
         return vector11;
    }
   
     
   
    public void set(){  
  Toolkit toolKit=Toolkit.getDefaultToolkit();  
  Dimension dimension=toolKit.getScreenSize();
  
  int WIDTH=getWidth();
  int HEIGHT=getHeight();
  int x=(dimension.width-WIDTH)/2;
  int y=(dimension.height-HEIGHT)/2;
  setLocation(x, y);
  setResizable(false);
  setTitle("查询:");
  }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Checeout().setVisible(true);
               
            }
        });
    }
   
     // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    // End of variables declaration   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField8;
    // End of variables declaration//GEN-END:variables
   
}


我用编程工具Netbeans编写的,想创建一个下拉按钮
在 ComBox方法下 总提示错误。
private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
        Vector v=this.getTextFieldVector("DoctorName");
        for(int j=0;j<jTable1.getRowCount();j++)
        {   jTable1.setValueAt(null, j, 0);}
            for(int i=0;i<v.size();i++)
            {
             jTable1.setValueAt((String)v.get(i), i, 0);
            }


for(int j=0;j<jTable1.getRowCount();j++)     说getRowCount()找不到符号,不能用于int型。  有jTable的3行 都说有错误

高手们帮忙看一下是怎么回事~~~
沙发
caixianle2000 发表于 08-9-20 21:43:23 | 只看该作者

试试看

我对awt swing这块不是很熟悉.到是没少写b/s的代码.你把 jTable1.getRowCount()打印出来看看是啥结果.看看表示是对象还是int型的数. 如果能打印出int行的数 你再进行下:int temp = jTable1.getRowCount(); for(int j=0;j<temp;j++) 试试看。
板凳
invinciblecry 发表于 08-10-4 22:57:04 | 只看该作者

考研貌似不考Java吧

考研貌似不考Java吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系我们|Free考研资料 ( 苏ICP备05011575号 )

GMT+8, 24-12-26 04:44 , Processed in 0.102063 second(s), 12 queries , Gzip On, Xcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表