请问如何在Jpanel上用Graphics.drawImage()显示本地磁盘上的图象?谢谢
------解决方案--------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends Frame
{
public Test()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
}
public static void main(String args[])
{
Test mainFrame = new Test();
JPanel jpanel=new JPanel();
Image img = mainFrame.getToolkit().getImage( "c:\\bag.png ");
mainFrame.add(jpanel);
mainFrame.setSize(400, 400);
mainFrame.setTitle( "DrawImage ");
mainFrame.setVisible(true);
Graphics g = jpanel.getGraphics();
while (!g.drawImage(img, 100, 100, mainFrame));
System.out.println( "Start Drawing! ");
}
}