实现代码:
import java.awt.*;
import java.awt.event.*;
public class DrawImage extends Frame {
Image img = getToolkit().getImage("1.jpg");
public void paint(Graphics g) {
g.drawImage(img, 0, 0, this);
}
public DrawImage() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Starting TestMyButton...");
DrawImage mainFrame = new DrawImage();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestButton");
mainFrame.setVisible(true);
}
}
运行结果: