似乎是用继承自JComponent的getGraphics()方法,可否这样用?
在一个panel的subclass中加如下代码:
getGraphics().drawImage(......);

解决方案 »

  1.   

    Image globe;
        Toolkit tk = Toolkit.getDefaultToolkit();
            globe = tk.getImage("Globe.gif");
            try
            {
                MediaTracker mt = new MediaTracker(this);
                mt.addImage(globe,0);
                mt.waitForID(0);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            Insets insets = getInsets();
            Dimension scrnsz = tk.getScreenSize();
            Dimension globesz = new Dimension(globe.getWidth(this),globe.getHeight(this));        setBounds((scrnsz.width / 2) - (globesz.width / 2),
                      (scrnsz.height / 2) - (globesz.height / 2),
                      globesz.width + insets.left + insets.right,
                      globesz.height + insets.top + insets.bottom);