글쎄, JDialog
으로 대기 화면을 만들었지 만 분리되었을 때만 작동합니다. 여기 JDialog에서 GIF가 올바르게 표시되지 않습니다.
/**
*
* @author krisnamourtscf
*/
public class TelaDeProcessamento extends Thread {
private String titulo;
private String mensagem;
private JDialog dialog;
public TelaDeProcessamento(String titulo, String mensagem) {
this.titulo = titulo;
this.mensagem = mensagem;
dialog = new JDialog(new JFrame(), true);
}
public static TelaDeProcessamento iniciaTela(String titulo, String mensagem) {
TelaDeProcessamento tela = new TelaDeProcessamento(titulo, mensagem);
tela.start();
return tela;
}
@Override
public void run() {
try {
dialog.setTitle(titulo);
dialog.getContentPane().setBackground(Color.WHITE);
dialog.setSize(new Dimension(300, 150));
dialog.getContentPane().setLayout(new BorderLayout());
ImageIcon ii = new ImageIcon(getClass().getResource("/imagens/4.gif"));
JLabel imageLabel = new JLabel();
imageLabel.setLocation(70, 0);
imageLabel.setText(" " + mensagem);
imageLabel.setIcon(ii);
dialog.getContentPane().add(imageLabel, java.awt.BorderLayout.CENTER);
dialog.setLocationRelativeTo(null);
dialog.validate();
dialog.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void paraTela() {
dialog.dispose();
}
public static void main(String[] args) {
TelaDeProcessamento tela=TelaDeProcessamento.iniciaTela("Aguarde....", "isso é um teste");
try {
Thread.sleep(5000);
} catch (Exception ex) {
}
tela.paraTela();
}
}
그리고 이것은 결과입니다 : 내가 다른 클래스에서 호출 할 때
,하지만, GIF이 표시되지 않는
JDialog
클래스 예
결과 : 내가 잘못
을 뭐하는 거지?
용의자 이것은 AWT 이벤트 발송 스레드 외부에서 작업을 수행하기 때문입니다. 거의 모든 Swing 및 AWT 메소드는 해당 스레드에서만 실행되어야하며 다른 스레드에서는 실행되지 않아야합니다. 이 규칙을 위반하면 이상하고 예측할 수없는 행동으로 이어질 것입니다. https://docs.oracle.com/javase/tutorial/uiswing/concurrency/를 참조하십시오. – VGR
감사합니다 @ VGR SwingWorker의 문제를 해결했습니다 – Krismorte