Mình không bt rõ cái này có thể làm dc ko @@ Nhưng mình sẽ đưa cho bạn tham khảo code Auto_Update từ Text file sử dụng Thread, bạn có thể tham khảo :
PHP:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import static java.lang.Thread.sleep;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Auto_Update extends javax.swing.JFrame {
public Auto_Update() throws FileNotFoundException, IOException
{
initComponents();
FileInputStream fi = new FileInputStream(new File("Input.txt"));
Scanner scan = new Scanner(fi);
Text.setText(scan.nextLine().substring(1));
fi.close();
scan.close();
new Thread()
{
public void run()
{
while (true)
{
Update();
}
}
}.start();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Text = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
Text.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
Text.setText("jLabel1");
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(14, 14, 14)
.addComponent(Text, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(Text, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
public static void main(String args[]) {
Set_Look_And_Feel();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new Auto_Update().setVisible(true);
} catch (FileNotFoundException ex) {
Logger.getLogger(Auto_Update.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Auto_Update.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
public void Update()
{
try {
sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(Auto_Update.class.getName()).log(Level.SEVERE, null, ex);
}
FileInputStream fi = null;
try {
fi = new FileInputStream(new File("Input.txt"));
} catch (FileNotFoundException ex) {
Logger.getLogger(Auto_Update.class.getName()).log(Level.SEVERE, null, ex);
}
Scanner scan = new Scanner(fi);
String input = scan.nextLine().substring(1);
if(!Text.getText().equals(input));
{
Text.setText(input);
}
try {
fi.close();
} catch (IOException ex) {
Logger.getLogger(Auto_Update.class.getName()).log(Level.SEVERE, null, ex);
}
scan.close();
}
public static void Set_Look_And_Feel()
{
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Auto_Update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Auto_Update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Auto_Update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Auto_Update.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
// Variables declaration - do not modify
private javax.swing.JLabel Text;
// End of variables declaration
}
Đây là Demo :
P/s : Toàn bộ các lệnh để Update dc để ở trong void Update(), bạn hãy tùy chỉnh lại với code của bạn