繁体   English   中英

如何用此代码在JWindow上显示jpeg?

[英]How to display a jpeg on a JWindow in this code?

我尝试在应用程序启动时显示带有欢迎图像的介绍窗口。 一切正常,但是图像不显示。 加载应用程序后,这就是我所看到的

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();
                }
        });
    }

 }
}

代码丢失

getClass().getResource

然后

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

完整示例在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM