JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請教JTable中可放之資料型態
nick6562





發文: 85
積分: 0
於 2007-09-30 18:37 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請教各位老師,

不好意思~~ 我不知道我問的這個問題該在哪裡發問......

我在 JInternalFrame中放置 JLabel、JTextField、JTable等物件,
也放置了JToolBar, 本想在呼叫JInternalFrame時, 暫時先不呼叫資料庫
中的資料, 而是當我在按下JToolbar中的"查詢"扭時, 才將依txtPo_Num
(JTextField)中我設定的條件將資料庫中的資料讀到JTable中。

於是我宣告Object[][]陣列, 並將值設定成null (設定成"" 也無效,
系統提示不建議), 但是當我啟動JInternalFrame時, 卻出現以下的錯誤訊息!
請各位老師幫幫忙, 是否我哪裡寫錯了?? 謝謝你們

錯誤訊息:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  at javax.swing.JTable$1.getValueAt(Unknown Source)
  at javax.swing.JTable.getValueAt(Unknown Source)
  at javax.swing.JTable.prepareRenderer(Unknown Source)
  at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
  at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
  at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
  at javax.swing.plaf.ComponentUI.update(Unknown Source)
  at javax.swing.JComponent.paintComponent(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JViewport.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JLayeredPane.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JLayeredPane.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JLayeredPane.paint(Unknown Source)
  at javax.swing.JComponent.paintChildren(Unknown Source)
  at javax.swing.JComponent.paint(Unknown Source)
  at javax.swing.JComponent.paintToOffscreen(Unknown Source)
  at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
  at javax.swing.RepaintManager.paint(Unknown Source)
  at javax.swing.JComponent._paintImmediately(Unknown Source)
  at javax.swing.JComponent.paintImmediately(Unknown Source)
  at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
  at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
  at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
  at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
  at java.awt.event.InvocationEvent.dispatch(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import java.util.Arrays;
import java.awt.*;
import java.sql.*;
import java.lang.Class;
 
import ExamineMod.*;
 
public class examineframe extends AbstractAction{
  
  JInternalFrame internalframe, DeacceptCause;
  mainfrm mf;
  JToolBar ex_tb;
  new_data New_Data;
  mod_data Mod_Data;
  save_data Save_Data;
  del_data Del_Data;
  lookup_data Lookup;
  print_data Prn_Data;
  JLabel lblPo_Num, lblSupplier_Id, lblSupplier, lblEmployee_Id, lblEmployee_Name, lblAccredited;
  JTextField txtPo_Num , txtSupplier_Id, txtSupplier, txtEmployee_Id, txtEmployee_Name;
    JComboBox badCause; 
    JToggleButton jbAccept, jbDeaccept;
  //JTable examine_tb = new JTable(new String[][]{{"This", "is","aaa"},{"a","Test","bbb"}},new String[]{"數量","單位EA","抽檢數"});
    JTable examine_tb;
    Connection strcon = null;
  Statement stmt = null;
  String scon = "jdbc:mysql://localhost:3306/iqcs?userUnicode=true&characterEncoding=Big5";
  ResultSet rs = null;
  ResultSetMetaData md = null;
  int i,j,RowNum=0,ColNum;
  //String RowNum;
  Object[] title ;
  Object[][] info;
 
  public examineframe(String text){
    super(text);
  }
  
  public void actionPerformed(ActionEvent e){
    
    if((internalframe == null)||(internalframe.isClosed())){
      internalframe = new JInternalFrame("進料檢驗", true, true, true, true);
      internalframe.setBounds(0,0,800,600);
      //internalframe.pack();
      mf = mainfrm.getMF();
      mf.jdp.add(internalframe);
      Container c = internalframe.getContentPane();
      ex_tb = new JToolBar();
      New_Data = new new_data("新增");
      ex_tb.add(New_Data);
      Mod_Data = new mod_data("修改");
      ex_tb.add(Mod_Data);
      Save_Data = new save_data("儲存");
      ex_tb.add(Save_Data);
      Del_Data = new del_data("刪除",new ImageIcon("images\\Delete.gif"));
      ex_tb.add(Del_Data);
      Lookup = new lookup_data("查詢");
      ex_tb.add(Lookup);
      ex_tb.addSeparator(new Dimension(20,0));
      Prn_Data = new print_data("列印",new ImageIcon("images\\print_0004.gif"));
      ex_tb.add(Prn_Data);
      Container ClientArea = new JPanel(new GridBagLayout());
      GridBagConstraints Cgbc = new GridBagConstraints();
      Cgbc.gridx = 0;
      Cgbc.gridy = 0;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      lblPo_Num = new JLabel("PO號  :");
      ClientArea.add(lblPo_Num,Cgbc);
      Cgbc.gridx = 1;
      Cgbc.gridy = 0;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      txtPo_Num = new JTextField();
      txtPo_Num.setColumns(10);
      ClientArea.add(txtPo_Num,Cgbc);
      Cgbc.gridx = 2;
      Cgbc.gridy = 0;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      lblSupplier_Id = new JLabel("廠商編號");
      ClientArea.add(lblSupplier_Id,Cgbc);
      Cgbc.gridx = 3;
      Cgbc.gridy = 0;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      txtSupplier_Id = new JTextField();
      txtSupplier_Id.setColumns(10);
      txtSupplier_Id.setEnabled(false);
      ClientArea.add(txtSupplier_Id,Cgbc);
      Cgbc.gridx = 4;
      Cgbc.gridy = 0;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      lblSupplier = new JLabel("廠商名稱  :");
      ClientArea.add(lblSupplier,Cgbc);
      Cgbc.gridx = 5;
      Cgbc.gridy = 0;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      txtSupplier = new JTextField();
      txtSupplier.setColumns(10);
      txtSupplier.setEnabled(false);
      ClientArea.add(txtSupplier,Cgbc);
      Cgbc.gridx = 0;
      Cgbc.gridy = 1;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      lblEmployee_Id = new JLabel("檢驗員工編號");
      ClientArea.add(lblEmployee_Id,Cgbc);
      Cgbc.gridx = 1;
      Cgbc.gridy = 1;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      txtEmployee_Id = new JTextField();
      txtEmployee_Id.setColumns(10);
      txtEmployee_Id.setEnabled(false);
      ClientArea.add(txtEmployee_Id,Cgbc);
      Cgbc.gridx = 2;
      Cgbc.gridy = 1;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      lblEmployee_Name = new JLabel("檢驗員工姓名  :");
      ClientArea.add(lblEmployee_Name,Cgbc);
      Cgbc.gridx = 3;
      Cgbc.gridy = 1;
      Cgbc.ipadx = 50;
      Cgbc.ipady = 0;
      txtEmployee_Name = new JTextField();
      txtEmployee_Name.setColumns(10);
      txtEmployee_Name.setEnabled(false);
      ClientArea.add(txtEmployee_Name,Cgbc);
      Cgbc.gridx = 0;
      Cgbc.gridy = 2;
      Cgbc.ipadx = 400;
      Cgbc.ipady = 400;
      Cgbc.gridwidth = 6;
      title = new Object[]{"料號","料品名稱","數量","單位EA","檢驗標準"};
      info = new Object[][]{null,null,null,null,null};
      examine_tb = new JTable(info,title);
      ClientArea.add(new JScrollPane(examine_tb),Cgbc);
      lblAccredited = new JLabel("是否合格?  :");
      jbAccept = new JRadioButton("是");
      jbAccept.setSelected(true);
      jbDeaccept = new JRadioButton("否");       
      FlowLayout fl = new FlowLayout();
      Container RadioPanel = new JPanel(fl);
      ButtonGroup RadioButton = new ButtonGroup();
      RadioButton.add(jbAccept);
      RadioButton.add(jbDeaccept);
      RadioPanel.add(lblAccredited);
      RadioPanel.add(jbAccept);
      RadioPanel.add(jbDeaccept);
      c.add(ex_tb,BorderLayout.NORTH);
      c.add(ClientArea,BorderLayout.CENTER);
      c.add(RadioPanel, BorderLayout.SOUTH);
      internalframe.setVisible(true);
      
      jbDeaccept.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
              DeacceptDialog d = new DeacceptDialog("不合格原因:");
              d.setSize(400, 200);
              mf.jdp.add(d);
              d.setVisible(true);
          }
        });
 
    }  
    
 
  }    
  
  class new_data extends AbstractAction{
    
    public new_data(String str){
      super(str);
    }
    public new_data(String str,Icon icon){
      super(str,icon);
    }
    public void actionPerformed(ActionEvent e){
      System.out.println("New a data!");
    }
  }
 
  class mod_data extends AbstractAction{
    
    public mod_data(String str){
      super(str);
    }
    public mod_data(String str,Icon icon){
      super(str,icon);
    }
    public void actionPerformed(ActionEvent e){
      System.out.println("Modify exist data!");
    }
  }
 
  class save_data extends AbstractAction{
    
    public save_data(String str){
      super(str);
    }
    public save_data(String str,Icon icon){
      super(str,icon);
    }
    public void actionPerformed(ActionEvent e){
      System.out.println("Save current data!");
    }
  }
 
  class del_data extends AbstractAction{
    
    public del_data(String str){
      super(str);
    }
    public del_data(String str,Icon icon){
      super(str,icon);
    }
    public void actionPerformed(ActionEvent e){
      System.out.println("Delete current data!");
    }
  }
 
  class lookup_data extends AbstractAction{
    
    public lookup_data(String str){
      super(str);
    }
    public lookup_data(String str,Icon icon){
      super(str,icon);
    }
    public void actionPerformed(ActionEvent e){
      String sqlStr = "select count(*) from examine";    
      try
      {
        Class.forName("com.mysql.jdbc.Driver");
        strcon = DriverManager.getConnection(scon,"root","!@#$");
        if(strcon != null)
          System.out.println("建立資料庫來源連結成功!!");
        stmt = strcon.createStatement();
        if(stmt != null)
          System.out.println("建立Statement物件成功!!");
        
        rs = stmt.executeQuery(sqlStr);
        rs.next();
        RowNum = rs.getInt(1);
        String stm = txtPo_Num.getText();
        sqlStr = "select e.material_id,m.material_id,material_title,quantity,unit,aql" +
            " from examine e inner join material e on e.material_id = m.material_id where " +
            "po_num= +'" + stm + "'";
        rs = stmt.executeQuery(sqlStr);
        md = rs.getMetaData();
        ColNum = md.getColumnCount();
        //titles = new Object[ColNum];
        for(i=1; i<=ColNum; i++)
           //titles[i-1] = md.getColumnName(i);
           info = new Object[RowNum][];
           i = 3;
           while(rs.next())
           {
          info[i] = new Object[ColNum];
          for(j=1; j<=ColNum; j++)
          {
             info[i][j-1] = rs.getObject(j);
          }
          i++;
                }
    
        
      }
      catch(ClassNotFoundException e1)
      {
        System.out.println("找不到驅動程式類別"+ e1.getMessage());
        System.out.println("連結錯誤! " + scon);
            System.out.println(e1.getMessage());
            if(strcon != null)
            {
              try
              {
                strcon.close();
              }
              catch(SQLException e2)
              {
              }
              return;
            }
        return;
      }
      catch(SQLException e2)
      {
        System.out.println(e2.getMessage());
      }
    }
  }
 
  class print_data extends AbstractAction{
    
    public print_data(String str){
      super(str);
    }
    public print_data(String str,Icon icon){
      super(str,icon);
    }
    public void actionPerformed(ActionEvent e){
      System.out.println("Print current data!");
    }
  }
}
 


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1510 請教JTable中可放之資料型態 nick6562 12117 2007-09-30 18:37
» JWorld@TW »  Java SE 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8