简体   繁体   English

向Applet Java添加图像

[英]Adding an Image to Applet Java

how can I add the following (car.jpg) image to my code's center. 如何将以下(car.jpg)图片添加到代码中心。 I can not see my picture in the output. 我在输出中看不到我的图片。

public class Welcome extends JApplet implements ActionListener {

JLabel title = new JLabel("hello");
JButton reserve = new JButton("btn 2");
JButton webpage = new JButton("btn 3");

ImageIcon image = new ImageIcon("car.jpg");

JLabel label = new JLabel("PHOTO", image, SwingConstants.CENTER);

public void init() {


    setLayout(null);


    add(title);
    add(reserve);
    add(webpage);
    add(label);


   label.setLocation (1000,1000);
   label.setSize (2500, 2300);
   reserve.addActionListener(this);
   webpage.addActionListener(this);

   title.setLocation(10, 10);
   title.setSize(250, 30);



   reserve.setLocation(50, 70);
   reserve.setSize(250, 50);
   webpage.setLocation(50, 130);
   webpage.setSize(150, 30);

 }
}

Put image file into jar. 将图像文件放入jar。 Then you can load it like this: 然后您可以像这样加载它:

ImageIcon image = new ImageIcon(Welcome.class.getResource ("car.jpg"));

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

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