import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.*;
import javax.swing.ImageIcon;
import java.awt.Image;
public class PictureBox
{
public JFrame f = new JFrame();
public JButton b = new JButton();
public PictureBox()
{
f.setUndecorated(true);
f.setSize(50, 50);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation((200), (200));
ImageIcon pic = new ImageIcon("pic.png");
Image icon = pic.getImage();
Image real = icon.getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
//For the 50's, put in the actual dimensions you want the picture to be
pic = new ImageIcon(real);
b.setIcon(pic);
f.add(b);
f.setVisible(true);
f.setEnabled(false);
}
public static void main(String[] args)
{
PictureBox pb = new PictureBox();
}
}
这将做简单和简单的设置图像。我不知道你的程序是如何实现的,所以你需要以任何方式进行编辑。
现在至于图片所在的位置,根据IDE(我使用JGrasp),您可能需要将其折叠到与课程相同的文件夹中。这不是丝毫组织的,但它现在很可能有用。
也pic.png是我的图片被称为名称,输入您的图片的名称