1
When I change the screen, there is always a small delay from one screen to another and it is annoying. You see clearly that one screen closes to open another. you know that java symbol you get when you open an application?
So when I open one screen it appears, when I open another, it disappears and appears.
What I really wanted was for the transition between screens not to be "noticeable".
I’m using the Dispose() method to close one screen and open another, I can’t say for sure, but I think with setVisible(false) it is the same way.
There is a solution to this?
package visao;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
public class TelaInicialUm extends JFrame {
private JPanel contentPane;
private JButton btnOutraTela;
public TelaInicialUm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnOutraTela = new JButton("outra tela");
btnOutraTela.setBounds(135, 67, 148, 93);
contentPane.add(btnOutraTela);
setLocationRelativeTo(null);
}
public JButton getBtnOutraTela() {
return btnOutraTela;
}
}
package;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
public class TelaDois extends JFrame {
private JPanel contentPane;
private JButton btnTelaTres;
public TelaDois() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnTelaTres = new JButton("Tela tres");
btnTelaTres.setBounds(200, 136, 89, 23);
contentPane.add(btnTelaTres);
setLocationRelativeTo(null);
}
public JButton getBtnTelaTres() {
return btnTelaTres;
}
}
package control;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import visao.TelaDois;
import visao.TelaInicialUm;
public class ControleTelaInicialUm implements ActionListener{
private TelaInicialUm tiu;
public ControleTelaInicialUm(TelaInicialUm tiu) {
this.tiu = tiu;
this.tiu.getBtnOutraTela().addActionListener(this);
tiu.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==tiu.getBtnOutraTela()){
this.tiu.dispose();
new ControleTelaDois(new TelaDois());
}
}
}
package control;
import visao.TelaDois;
public class ControleTelaDois {
private TelaDois td;
public ControleTelaDois(TelaDois td) {
this.td = td;
td.setVisible(true);
}
}
package control;
import visao.TelaInicialUm;
public class MainTelas {
public static void main(String[] args) {
new ControleTelaInicialUm(new TelaInicialUm());
}
}
Need to close one window to open another? Usually desktop applications have multiple windows.
– Pablo Almeida
close, close no! I need to hide a window to show another
– Manuela carneiro
A modal window does not solve?
– Pablo Almeida
i don’t know what a modal window is. the application is all done, it would change a lot, my code is in mvc
– Manuela carneiro
If your application is in MVC, then it makes no difference what kind of visualization you choose, right? Modal is a window that sits above the other, preventing interaction with the bottom.
– Pablo Almeida
Please present a [mcve] so that we can simulate the problem. Without seeing, it becomes complicated to suggest something.
– user28595
I put an example, too bad it doesn’t go so much to see this change from one to another, because the screen doesn’t have much image, so the exchange is smooth. but my application is built on this model there, the difference is that there are many components on the screen
– Manuela carneiro
Gifs showing the transition are appreciated
– Jefferson Quesado
I can’t do it! but imagine that when I close a screen, instead of the other already appear quickly, you realize clearly that the previous closed and evc is waiting for the other to open
– Manuela carneiro