如何在此代码中的 JWindow 上显示 jpeg?
How to display a jpeg on a JWindow in this code?
我试图在我的应用程序启动时显示介绍 window 和欢迎图像。一切都加载得很好,但图像不显示。加载应用程序时,这就是我 see.
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"));
完整示例Here
我试图在我的应用程序启动时显示介绍 window 和欢迎图像。一切都加载得很好,但图像不显示。加载应用程序时,这就是我 see.
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"));
完整示例Here