java awt如何添加图片到rame 要可运行的代码,就写一个frame然后加一个图片就行了,不要用swing……谢谢

2025-01-05 07:48:31
推荐回答(1个)
回答1:

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

public class Img extends Frame{

private Image img;
public Img() {

String title = "dragon.jpg";
img = Toolkit.getDefaultToolkit().getImage(title);
setVisible(true);
}
@Override
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Img();
}

}