[英]Loading Image in Java using JFrame
so i have a very basic java application, there is a panel and inside that is a button. 所以我有一个非常基本的Java应用程序,有一个面板,里面是一个按钮。 When a user clicks the button, i want a picture to come up in another panel in the same form.
当用户单击按钮时,我希望图片以相同的形式出现在另一个面板中。
I searched up ways to load images from web/from my folder and this is the code i've come up with:- 我搜索了从Web /文件夹中加载图像的方法,这是我想出的代码:-
private void buttonActionPerformed(java.awt.event.ActionEvent evt)
{
ImageIcon icon = new ImageIcon("URL-of-the-image");
panel2.setIcon(icon);
}
~~what panel 2 looks like~~ ~~面板2看起来像什么~~
where am i going wrong? 我要去哪里错了? it says that the method "setIcon()" is causing a problem but i don't know any other method to do this job.
它说方法“ setIcon()”引起了问题,但是我不知道有其他方法可以完成这项工作。 Please Guide!
请指导!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.