显示图像的代码不适用于其他Java编辑器 [英] Code to display an image won't work with different java editors

查看:106
本文介绍了显示图像的代码不适用于其他Java编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要您的帮助! 我改用netbeans,遇到了一些重大问题. 大约6个小时后,我终于弄清楚了如何使图像显示在netbeans中. 有没有一种方法可以在JGrasp和netbeans中运行的地方编写代码?

I need your help! I am switching to netbeans and have been having some major problems. After about 6 hours I finally figured out how to get the image to show in netbeans. Is there a way to write the code where it will work in JGrasp and netbeans?

netbeans的工作代码是

The working code for netbeans is

menuPic = new javax.swing.JButton();
menuPic.setIcon(new javax.swing.ImageIcon(getClass().getResource("image/w2.png")));

JGrasp的工作代码是

and the working code for JGrasp is

menuPic = new JButton();
ImageIcon bottompic = new ImageIcon("image/w2.png");
JButton menuPic = new JButton(bottompic);

我讨厌JGrasp,但是那是我的老师用来评分的,所以我希望能够用netbeans编写它,并将代码复制并粘贴到JGrasp,这样它就可以工作. 任何帮助将不胜感激!

I hate JGrasp but thats what my teacher uses to grade, so I want to be able to write it in netbeans and copy and paste the code to JGrasp and it be able to work. Any help would be greatly appreciated!!

解决了这个问题,但现在我遇到了另一个问题 好的,但是现在我的JOptionPane图片没有加载到netbeans中 我在JGrasp中使用的代码是

solved this but now i have another problem ok that worked but now my JOptionPane picture isn't loading in netbeans The code i used in JGrasp is

final ImageIcon icon1 = new ImageIcon("image/money.gif");
JOptionPane.showMessageDialog(null, " blah blah", "Text", JOptionPane.INFORMATION_MESSAGE,   icon1);

,如果我想在JOptionPane.showInputDialog中显示图像,是否与在JOptionPane.showMessageDialog中显示图像相同? 谢谢

and if i wanted to show an image in JOptionPane.showInputDialog would it be the same as putting on in JOptionPane.showMessageDialog ? Thanks

推荐答案

只要您的图像文件位于正确的位置(位于保存目录的图像子目录中),"NetBeans"代码就可以在JGrasp中运行类文件.顺便说一下,它不是NetBeans特定的代码;它不是NetBeans特定的代码.只是纯粹的Java代码而已.

The "NetBeans" code will work in JGrasp as long as your image files are located in the right location -- in an image subdirectory off of the directory that holds the class files. By the way, it's not NetBeans-specific code; it's nothing but Java code, pure and simple.

这篇关于显示图像的代码不适用于其他Java编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆