找到你要的答案

Q:Java JTable or JInternal Frame auto reload/Refresh

Q:java JTable或jinternal框架自动重载/刷新

why JTable data updated when JInternalframe closed and then opened again

 public void viewTabelMejaBayar(String mejahe){
    //mejahe = textNomeja.getText();
    try {
        konek = Koneksi.getKoneksi();
        state = konek.createStatement();

String query = "select * from tbtrans where stdpr='1' AND stkasir='0' AND nomeja='"+mejahe+"' ";

ResultSet result= state.executeQuery(query);

         while(result.next()){

            Kasir p = new Kasir();

            p.setNokey(result.getString("nokey"));//1
            p.setNovisitor(result.getString("novisitor")); //2
            p.setNomeja(result.getInt("nomeja")); //3
            p.setNoantri(result.getInt("noantri"));//4
            p.setAddedpeg(result.getString("addedpeg"));//5
            p.setKdmc(result.getInt("kdmc"));//6
            p.setMncafe(result.getString("mncafe"));//7
            p.setKatmenu(result.getString("katmenu"));//8

            p.setQty(result.getDouble("qty"));//9
            p.setHrg(result.getDouble("hrg"));//10
            p.setSubtotal(result.getDouble("subtotal"));//11
            p.setWorder(result.getString("worder"));//12
            p.setStord(result.getInt("stord"));//13
            p.setWsaji(result.getString("wsaji"));//14
            p.setStdpr(result.getInt("stdpr"));//15
            p.setStkasir(result.getInt("stkasir"));//16
            p.setPegkasir(result.getString("pegkasir"));//17 


            tableModelkas.add(p);
            //tableModelkas.fireTableDataChanged();
            //tableModelkas.fireTableChanged(null);

          }

     }
     catch(Exception e){
        e.printStackTrace();

     } 
    //Pramusaji p = new Pramusaji();

}







bt.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent t) {

                    String str = t.getActionCommand();
                    int action = Integer.parseInt(str); 

                    int count = 0;
                    count = count +1;

                    switch (action){
                    case 1:
                        //if (e ==0){

            viewTabelMejaBayar("1");    //<---Data shown in the table 
            TotalBayare(); bt.setBackground(Color.GREEN);
            textNomeja.setText("1"); 
            textBayar.requestFocus();



                        }
                        else{

                            if((count>0)&&(count<2)){

                    /*      }
                        *   if (count >=2){

                        *  bt.setEnabled(false);
                            * }
                            * bt.setBackground(Color.CYAN);
                        }
                     */
                        repaint();
                        //ResetviewTabelMejaBayar();

                        break;

为什么数据更新时,jinternalframe JTable关闭,然后再次打开

 public void viewTabelMejaBayar(String mejahe){
    //mejahe = textNomeja.getText();
    try {
        konek = Koneksi.getKoneksi();
        state = konek.createStatement();

查询字符串=“SELECT * FROM tbtrans哪里stdpr = 1”和stkasir = '0'和nomeja =“”+“”+ mejahe;

ResultSet结果=状态。executeQuery(查询);

         while(result.next()){

            Kasir p = new Kasir();

            p.setNokey(result.getString("nokey"));//1
            p.setNovisitor(result.getString("novisitor")); //2
            p.setNomeja(result.getInt("nomeja")); //3
            p.setNoantri(result.getInt("noantri"));//4
            p.setAddedpeg(result.getString("addedpeg"));//5
            p.setKdmc(result.getInt("kdmc"));//6
            p.setMncafe(result.getString("mncafe"));//7
            p.setKatmenu(result.getString("katmenu"));//8

            p.setQty(result.getDouble("qty"));//9
            p.setHrg(result.getDouble("hrg"));//10
            p.setSubtotal(result.getDouble("subtotal"));//11
            p.setWorder(result.getString("worder"));//12
            p.setStord(result.getInt("stord"));//13
            p.setWsaji(result.getString("wsaji"));//14
            p.setStdpr(result.getInt("stdpr"));//15
            p.setStkasir(result.getInt("stkasir"));//16
            p.setPegkasir(result.getString("pegkasir"));//17 


            tableModelkas.add(p);
            //tableModelkas.fireTableDataChanged();
            //tableModelkas.fireTableChanged(null);

          }

     }
     catch(Exception e){
        e.printStackTrace();

     } 
    //Pramusaji p = new Pramusaji();

}







bt.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent t) {

                    String str = t.getActionCommand();
                    int action = Integer.parseInt(str); 

                    int count = 0;
                    count = count +1;

                    switch (action){
                    case 1:
                        //if (e ==0){

            viewTabelMejaBayar("1");    //<---Data shown in the table 
            TotalBayare(); bt.setBackground(Color.GREEN);
            textNomeja.setText("1"); 
            textBayar.requestFocus();



                        }
                        else{

                            if((count>0)&&(count<2)){

                    /*      }
                        *   if (count >=2){

                        *  bt.setEnabled(false);
                            * }
                            * bt.setBackground(Color.CYAN);
                        }
                     */
                        repaint();
                        //ResetviewTabelMejaBayar();

                        break;
java  swing  jtable