[英]Adding an Image to Applet Java
如何将以下(car.jpg)图片添加到代码中心。 我在输出中看不到我的图片。
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);
}
}
将图像文件放入jar。 然后您可以像这样加载它:
ImageIcon image = new ImageIcon(Welcome.class.getResource ("car.jpg"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.