【发布时间】:2014-07-03 03:58:26
【问题描述】:
我知道这个问题已经被问过很多次了,但我觉得它没有得到正确的回答。
我想在 java gui 中使用图像作为背景
我尝试了以下方法:
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
public class worldGUI extends JFrame implements ActionListener
{
private ImageIcon world = new ImageIcon("C://Users/Hans/Documents/world/map.png");
private JLabel map = new JLabel(world);
private JButton borders = new JButton("Borders");
public worldGUI()
{
setTitle("Welcome to the World");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,500);
setLocation(100,100);
setVisible(true);
borders.addActionListener(this);
map.add(borders);
setVisible(true);
}
}
我是java新手,请耐心等待
【问题讨论】:
-
"...but I feel it has not been properly answered."--难以置信。 100 多个答案中,哪个没有正确回答? -
您到底需要什么?解释它是如何工作的?有什么错误吗?
-
这个问题似乎是题外话,因为它提出了一个常见问题,该问题有许多有据可查的答案,并且没有提供这些解决方案不起作用的充分理由