Refresh in jframe automatically

Asked

Viewed 700 times

0

I will start a project where I will do the control of queues in java, normal queues even, as if you arrive at the bank and see on the screen your name.

I’ll give a summary of the project to be clearer.

I have 10 computers, each one belongs to one person, these people request something simultaneously. In another jframe it will display who requested it first, it will display the name of the person and the time that the person requested, as soon as it is answered the name of the person is removed from the queue, for example:

Solicitante | Tempo que fez a solicitação
João        | 2:45
Roberto     | 1:58
Olivia      | 0:50
Pedro       | 0:15

But I need to display this in real time, IE, will present the requested time in real time and also as soon as someone queue or exit will also happen in real time

I need a way to give a refresh on the jframe that will perform this display automatically, whether every 2 seconds, or 3... anyway

I need to accomplish this in JAVA

Does anyone know any way I can program this refresh or any way to do it automatically?

  • What have you done? Add the code to the question. It’s very likely that what you need is an Observer.

  • Good morning, I will start the project in the afternoon, but I do not know how to develop this part of refresh, I thought to use the java timer.

  • It’s important that you start first, because then we’ll have a point where we can help you. Explaining this would make the answer too broad.

  • I thought about doing something like this Timer timer = new Timer(0, new Actionlistener() { @Override public void actionPerformed(Actionevent e) { updateRecords(); } }); timer.setDelay()3000; // timer.start();

  • Which I didn’t even tell you, the answer would still be wide, because you have nowhere to go. I believe there are several ways to do this, but if you have already added something you have tried to do, then it is easier to answer.

1 answer

0

This will depend on the component you use to display the information. Whenever there is a new request just update the component you are using, when removing the request then refresh again, you should never refresh the entire jframe, just in the component that the information should be updated. Start to do your project, each graphic component has a way to update the information, when unable to ask a new question stating what you are using.

Example: a JList you use the method fireContentsChanged(...), already in a JTable you use the method fireTableDataChanged().

You do not need a timer that updates in a certain time interval. If you know the moment the event occurs then just implement the update of the components.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.