swing retrieve data from mysql db to textfield

后端 未结 2 1246
傲寒
傲寒 2021-01-26 07:12

i have column in mysql table have 100 record ,i want show values from table inside textfield ( every 3 second show record from 0 - 99). this is my code :

Connect         


        
相关标签:
2条回答
  • 2021-01-26 07:21

    Use Thread.sleep(milliseconds)

    while(rs.next()){
        String value = rs.getString("expert1");
        textField1.setText(value);        
        try {
              Thread.sleep(3000);
        } catch(Exception e) {}
    }
    

    You can use Thread for parallel process.

    0 讨论(0)
  • 2021-01-26 07:44

    Please read How To Use Swing Timer and The Event Dispatch Thread.

    Use then javax.swing.Timer to re-read the data from database and set the content on the JTextField the way you need it.

    Timer timer = new Timer(3000, new ActionListener() {
    
        @Override
         public void actionPerformed(ActionEvent e) {
             .... // retrieve data and prepare the textField content
             textField.setContent(...);
         }          
    });
    
    timer.start();
    
    0 讨论(0)
提交回复
热议问题