1
我有一条道路的背景图像,我使用ImageIcon在JFrame上显示道路。我想在某个(x,y)位置放置一辆汽车在该背景图像的顶部。如何在java中放置图像彼此顶部
我试过使用另一个ImageIcon并且当我运行该程序时背景没有出现,但是汽车没有。
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Gui extends JFrame {
private ImageIcon northcar = new ImageIcon("src/north.gif");
private ImageIcon usIcon = new ImageIcon("src/trafficLight.jpg");
public Gui() {
add(new JLabel(usIcon)); // background image does not appear after the i added the northcar label
add(new JLabel(northcar)); // this picture can be seen
}
public static void main(String[] args) {
Gui frame = new Gui();
frame.setTitle("TestImageIcon");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 650, 650);
frame.setVisible(true);
}
}
我听说过使用画布,但没有任何线索。有任何想法吗 ?
非常感谢
作品魅力m8 – Haxed 2010-06-18 06:24:11