package test;import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
public class _trade extends JFrame{ /**
 * @数据显不出来,不过第160行的addData()方法的确把数据传到了,可能是第162行的调用方法有误吧
 */即第180行的addRow()方法有问题

private JLabel L_member;
private JTextField T_member;
private JButton B_record;

private JLabel L_mebName;
private JLabel L_mebCount;
private JLabel L_mebCash;
private String member_name;
private String member_count;
private int member_cash;
private JLabel L_account;
private int count,income,cash;
//
private JPanel P_up_1;
private JLabel L_production;
private JTextField T_production;
private JLabel L_quantity;
private JTextField T_quantity;
private JButton B_revocation;
private JPanel P_up_2;
private JPanel P_up;

private JTable T_prorecord;//表格
private JScrollPane P_middle;

private JButton B_Prorecord;
private JButton B_menber;
private JButton B_save;
private JLabel L_count;
private JLabel L_income;
private JLabel L_recash;
private JPanel P_down_1;
private JPanel P_down_2;
private JPanel P_down;
public t_model model; _trade(){
setLayout(null);                            //JFrame窗体不使用布局器 
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
//panel_up
Container con=getContentPane();
P_up_1=new JPanel();
P_up_2=new JPanel();
L_member=new JLabel("会员卡号");
L_member.setFont(new Font("幼圆",Font.BOLD,24));
T_member=new JTextField(15);
B_record=new JButton("查看记录    (F8)");
//
L_mebName=new JLabel("               姓名"+member_name+"               积分"+member_count+"               余额"+member_cash);
L_mebName.setFont(new Font("幼圆",Font.BOLD,16));
//
P_up_1.add(L_member);
P_up_1.add(T_member);
P_up_1.add(B_record);
P_up_1.add(L_mebName);
P_up_1.setSize(780,65);
P_up_1.setLocation(30,60);
con.add(P_up_1);
L_production=new JLabel("商品编号");
L_production.setFont(new Font("幼圆",Font.BOLD,24));
T_production=new JTextField(15);
T_production.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e) {
SQLTime sqlquery=new SQLTime();
Vector Count;
try{
String pro=T_production.getText();
/*Vector*/Count=sqlquery.proInfo(pro);//该方法返回一条字符串,商品表的信息字符串
Count.get(0);Count.get(1);Count.get(2);//获得对应的字段值                                                                                                                                                                                      // v.add("序号");v.add("编号");v.add("名称");v.add("单价");v.add("会员价");v.add("数量");v.add("数量");
System.out.println(Count.get(0));                                                                                    
System.out.println(Count.get(1));
System.out.println(Count.get(2));
addData((String)Count.get(0),(String)Count.get(1),(String)Count.get(2));
}catch(SQLException ec){
ec.getMessage();
}finally{
}
}
});
L_quantity=new JLabel("数量");
L_quantity.setFont(new Font("幼圆",Font.BOLD,24));
T_quantity=new JTextField(15);
B_revocation=new JButton("撤销    (F9)");
//P_up_2.setBackground(Color.CYAN);
P_up_2.add(L_production);
P_up_2.add(T_production);
P_up_2.add(L_quantity);
P_up_2.add(T_quantity);
P_up_2.add(B_revocation);
P_up_2.setSize(780,50);
P_up_2.setLocation(30,125);
con.add(P_up_2); model=new t_model(20);//模型
T_prorecord=new JTable(model);//表格
P_middle=new JScrollPane(T_prorecord);//滚动面板
P_middle.setSize(940,310);
P_middle.setLocation(30,175);
con.add(P_middle);

//panel_down
P_down_1=new JPanel();
P_down_2=new JPanel();

B_Prorecord=new JButton("帮助     (F12)");
B_menber=new JButton("申请会员     (F11)");
B_save=new JButton("保存记录       (F10)");
P_down_1.add(B_Prorecord);
P_down_1.add(B_menber);
P_down_1.add(B_save);
P_down_1.setSize(780,35);
P_down_1.setLocation(30,485);
con.add(P_down_1);
L_count=new JLabel("合计"+count+"      "+"实收"+income+"      "+"找赎"+cash);
L_count.setFont(new Font("幼圆",Font.BOLD,42));
L_income=new JLabel("实收");
L_income.setFont(new Font("幼圆",Font.BOLD,42));
L_recash=new JLabel("找赎");
L_recash.setFont(new Font("幼圆",Font.BOLD,42));
P_down_2.add(L_count);
P_down_2.setSize(780,60);
P_down_2.setLocation(30,520);
con.add(P_down_2);
//**************事件
this.addKeyListener(new KeyAdapter(){
public void keyReleased(KeyEvent e){
//F12
//F11
//F10
//F9
//F8
}
});
setTitle("会员登录");
setVisible(true);
setSize(1000,600);
setResizable(false);
setBackground(Color.gray);

}

    void addData(String first,String second,String third) {  
     System.out.println(first+second+third);
     model.addRow(first,second,third);//应该是这行的方法有错
     T_prorecord.updateUI();
}

public static void main(String[] args) {
// TODO Auto-generated method stub
_trade trade=new _trade();
}}class t_model extends AbstractTableModel{                                                                                                   
String[] colName={"序号","商品编号","商品名称","单价","会员价","数量","小计"};
Vector content;
t_model(int count){
content=new Vector(count);
}
//增添行数据的操作
public void addRow(String code,String name,String price){
Vector v=new Vector(7);
v.add(0,new Integer(content.size()));
v.add(1,code);
v.add(2,name);
v.add(3,price);
v.add(4,null);
v.add(5,null);
v.add(6,null);
content.add(v);
}
/**
 * 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {// 是否可以编辑
if (columnIndex == 0) {
return false;
}
return true;
}  /**
 * 使修改的内容生效
*/
public void setValueAt(Object value, int row, int col) {// 获得某单元格的值
((Vector) content.get(row)).remove(col);
((Vector) content.get(row)).add(col, value);
this.fireTableCellUpdated(row, col);



public int getRowCount(){
return content.size();
}
public int getColumnCount(){
return colName.length;
}
public String getColumnName(int col){
return colName[col];
}
public Object getValueAt(int row,int col){
return ((Vector)content.get(row)).get(col);
}
/**
 * 返回数据类型
 */
public Class getColumnClass(int col) {
return getValueAt(0, col).getClass();
}
}