2
這是一個類項目,我需要顯示多個圖像,但它只打印出最後一個label.setIcon。我該怎麼辦?如何在JLabel上顯示多個圖像
package Rectangle;
import java.awt.*;
import javax.swing.*;
public class Rectangle extends JFrame {
public Rectangle(String arg) {
JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
ImageIcon icon = new ImageIcon(this.getClass().getResource("1676858-livingforest2011.jpg"));
ImageIcon icon1 = new ImageIcon(this.getClass().getResource("20496aa0.gif"));
ImageIcon icon2 = new ImageIcon(this.getClass().getResource("akuma-ragingdemon-yes.gif"));
JLabel label = new JLabel();
label.setIcon(icon2);
label.setIcon(icon1);
label.setIcon(icon);
panel.add(label);
this.getContentPane().add(panel);
}
public static void main(String[] args) {
Rectangle forestFrame = new Rectangle(args.length == 0 ? null : args[3]);
forestFrame.setSize(1698,770);
forestFrame.setVisible(true);
forestFrame.setVisible(true);
}
}
另外我想知道如何改變圖標2和3的位置? – EddJack
您可以藉助['LyoutManager'](http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html)進行管理。嘗試例如'BorderLayout'。 – alex2410