【发布时间】:2014-08-03 21:01:49
【问题描述】:
JButton 只出现在 MouseEnter 我已经尝试了多种方法,但我似乎无法弄清楚如何让我的 JButton 覆盖背景图形。 .有人知道我如何在这个背景上绘画并让我的按钮留在那里吗?我会在这里粘贴代码,但它会有点乱,所以这里有一些 pastebin 链接! :)
我的主班:http://pastebin.com/DvVfCU03
我的 MenuPanel 类:http://pastebin.com/uht8cabX
这是主类的副本,以防万一:
public class Main {
final static JFrame window = new JFrame();
final static ImageIcon imageIconOne = new ImageIcon(getConnectImage());
final static JButton connectB = new JButton(imageIconOne);
public static void main(String[] args) throws IOException {
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setContentPane(new MenuPanel());
window.addKeyListener(new MenuPanel());
window.setMinimumSize(new Dimension(1024,640));
window.pack();
window.setTitle("Realm of Pixels");
window.setVisible(true);
window.addMouseListener(new MouseHandler());
window.setVisible(true);
window.add(connectB);
connectB.setVisible(true);
}
public static Image getConnectImage(){
Image connectImage = null;
try {
connectImage = ImageIO.read(new File("Resources/Buttons/Connect.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connectImage;
}
public static JFrame getWindow() {
return window;
}
}
【问题讨论】:
标签: java swing graphics jframe jbutton