簡體   English   中英

向Applet Java添加圖像

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM