When I change the screen, there is always a delay from one screen to another and this is annoying. You see clearly that one screen closes to open another. do you know that java symbol that stays when you open an application?
Then when I open a screen it appears, when I open another, it disappears and appears.
What I really wanted was that the transition between screens was not "noticeable."
I'm using the dispose () method to close a screen and open another, I do not say for sure, but I think with setVisible (false) it stays the same.
Is there a solution for 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 view;
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());
}
}