Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.TimeUnit;
- final class Window {
- private final JFrame frame;
- private final JLabel fileTextLbl;
- public Window() {
- frame = new JFrame();
- frame.setSize(800, 600);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setLayout(new FlowLayout());
- fileTextLbl = new JLabel("hallo");
- frame.add(fileTextLbl);
- readFile();
- }
- public void show() {
- frame.setVisible(true);
- }
- private void readFile() {
- ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
- executor.scheduleAtFixedRate(() -> {
- try (BufferedReader br = Files.newBufferedReader(Paths.get("test.txt"))) {
- fileTextLbl.setText(br.readLine());
- } catch(IOException ioe) {}
- }, 0, 3, TimeUnit.SECONDS);
- }
- }
- public class Start {
- public static void main(String[] args) {
- new Window().show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement