Java - 我的绘画程序需要一个带有图像子菜单的菜单栏 - 怎么办?
所以我有这个程序,有点像油漆,它可以让你绘制形状和线条,但我的任务是添加一个菜单栏,其中包含子菜单“文件->”。关于,当单击“关于”部分时。它应该拉出一个面板或框架或带有我已经制作的图像的东西。
然而它不起作用,而且我以前从未真正处理过图像。我所拥有的只是谷歌搜索,但失败了。我知道该方法是从令人愉快的 system.out.println 调用的,并且打开了一个框,但没有图片!〜任何帮助都会非常好。
if (e.getActionCommand().equals("About"))
{
System.out.println("stfu");
JFrame about = new JFrame("About");
about.setSize(300, 300);
BufferedImage img = null;
try{
img = ImageIO.read(new File("C:/Users/TehRobot/Desktop/Logo.png"));
}catch (IOException e1)
{
}
SO I have this program that is kind of like paint, it lets you draw shapes and lines, but my assignment is to add a menu bar with a sub menu File-> About, when Click on the about section. It should pull up a panel or a frame or a something that has a image which I have already made.
However it's not working and I have never actually dealt with images before. All I have is from a Google search and that failed. I know the method is being called from the delightful system.out.println, and a box opens up but there is no picture!~ any help would be very nice.
if (e.getActionCommand().equals("About"))
{
System.out.println("stfu");
JFrame about = new JFrame("About");
about.setSize(300, 300);
BufferedImage img = null;
try{
img = ImageIO.read(new File("C:/Users/TehRobot/Desktop/Logo.png"));
}catch (IOException e1)
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要...
setIcon(...)
setIcon(...) 将 ImageIcon 放入 JLabel代码>方法。所有这一切应该只需要几行代码,仅此而已。
You'll want to ...
setIcon(...)
method.In all this should just take a few lines of code, that's all.