我们刚刚开始使用Java。我们想使用来自互联网的图像并将其作为Jpanel的背景。有人可以帮我们吗?我们尝试使用下面的代码:
public class Achtergrond3 extends JPanel {
private ImageIcon img;
private JLabel label;
public Achtergrond3() {
img = new ImageIcon("res/textures/newbackground.jpg");
label= new JLabel(img);
this.add(label);
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
}
}