0

アプリケーションの起動時にウェルカム イメージを含む紹介ウィンドウを表示しようとしています。すべて正常に読み込まれますが、画像が表示されません。アプリケーションが読み込まれると、これが表示されます

public class Window extends JWindow
{
  //java.net.URL imgIntro = getClass().getResource("/images/intro.jpg");
  ImageIcon imIntro = new ImageIcon("/images/intro.jpg");


  //java.net.URL imgRegles = getClass().getResource("/images/rules.jpg");
  ImageIcon imRules = new ImageIcon("/images/rules.jpg");

  static Thread t = new Thread();
  static int thread = 0;
  static JButton bouton;
  static int X;
  static int Y;



  public Window( int X, int Y, int type) {

    super();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(X,Y);
    setLocation( (dim.width - X)/2 , (dim.height - Y)/2);
    setVisible(true);
    Container fen = getContentPane();

    if (type == 1 ) bouton = new JButton(imIntro);
    else            bouton = new JButton(imRules);
    bouton.setPreferredSize(new Dimension(X, Y) );
    fen.add( bouton);
    bouton.setVisible( true );

    show();

    if( type == 1 ) {
        try {
            Thread.sleep(1000);
            thread = 1;
        }
        catch( java.lang.InterruptedException ex ) {
            JOptionPane.showMessageDialog(null, "error");
            }
        dispose();

    }

    else {
        bouton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                     dispose();
                }
        });
    }

 }
}
4

1 に答える 1

0

コードが抜けていた

getClass().getResource

それで

ImageIcon imIntro = new ImageIcon(getClass().getResource("/images/Lintro.jpg"));

完全な例はこちら

于 2016-01-22T04:45:46.790 に答える