为什么它不画照片Jpanel

时间:2018-08-10 16:38:56

标签: java jframe

我想在相框上画一张照片,但是它不起作用,我找不到我的错误,请帮忙

import javax.swing.*;
import java.awt.*;
public class b1 extends JPanel {

    Image img;

    public b1() {
        setFocusable(true);
        ImageIcon u = new ImageIcon("C:/Benutzer/Julius/eclipse-workspace/JumpnRun/rsc/b1.jpg");
        img = u.getImage();


    }

    public void paint(Graphics g) {
        super.paintComponent(g);

        Graphics2D f2 = (Graphics2D) g;

        f2.drawImage(img, 0, 0, null);
    }
}

0 个答案:

没有答案