【发布时间】:2014-06-24 22:59:44
【问题描述】:
我的代码需要帮助。
我在启动我的 Java 应用程序的 SplashScreen 时遇到问题。
扩展JFrame 并调用扩展JDialog 的屏幕登录的主体类(bolaoJFrame)。验证用户后,会创建 SplashScreen 但不会出现。
我究竟做错了什么?
当类主体加载未完成时,SplashScreen 应在验证后显示JProgressBar。
这是主要类的主要方法:
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(bolaoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(bolaoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(bolaoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(bolaoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
bolaoJFrame principal= new bolaoJFrame();
principal.setLocationRelativeTo(null);
login = new loginJDialog(principal, true);
if(newUser==true){
CardLayout cards = (CardLayout)(principal.jpPrincipal.getLayout());
cards.show(principal.jpPrincipal, "cadastro");
}else{
if(Usuario.userCriado==0){
System.exit(0);
}else{
Splash telaSplash =new Splash(null);
telaSplash.setVisible(true);
CardLayout cards = (CardLayout)(principal.jpPrincipal.getLayout());
cards.show(principal.jpPrincipal, "apostas");
principal.jLabel1.setText("Bem vindo " + user.getUsername());
principal.jLabel4.setIcon(new Util().dimencionaImagem(user.getFoto(),80));
HoraDoSistema.start(principal.retomaHora(),principal.lbRelagio);
principal.montaCards();
PanelRanking pr = new PanelRanking(10, 1, user.getUserCod());
principal.jpRanking.add(pr,"1");
if(pr.getPosUser()>0){
principal.lbRankingInfo.setText("Sua posição atual é " + pr.getPosUser() + "º" );
}
if(pr.getPontuacaoUser()>0){
principal.lbPontuacaoInfo.setText("Você fez " + pr.getPontuacaoUser()+ " pontos" );
}
principal.lbNext.requestFocus();
principal.verificaDisponibilidad();
}
}
principal.setVisible(true);
}
});
}
SplashScreen 类:
public Splash(JFrame owner) {
//super(owner);
setLayout(null);
Util.centralizarJanela(this, 521, 335);
inicialize();
}
public void inicialize(){
JLabel fundo = new JLabel();
//fundo.setLocation(new Point(0,0));
fundo.setIcon(new ImageIcon(getClass().getResource("/Principal/splash.png")));
fundo.setSize(521, 315);
add(fundo);
barraDeProgresso= new JProgressBar();
barraDeProgresso.setBackground(Color.red);
barraDeProgresso.setBounds(0, 315, 521, 20);
barraDeProgresso.setStringPainted(true);
add(barraDeProgresso);
}
public void setValorBarraDeProgresso(int progresso){
barraDeProgresso.setValue(progresso);
}
public int getValorBarraDeProgresso(){
return barraDeProgresso.getValue();
}
【问题讨论】:
-
欢迎来到 Stack Overflow!避免使用
null布局。您无法控制影响在不同平台/操作系统上改变其尺寸的组件的尺寸要求/决定的因素
标签: java swing splash-screen