Thorsten F.: Bild in ein bestimmtes Panel darstellen

Beitrag lesen

Hi,

hier mal der Code:

public class Test extends Frame
{
     Image bild1;
     public static void main( String[] args )
     {
         Test show = new Test();
     }

public Test()
     {
        bild1 = getToolkit().getImage("test.gif");
        MediaTracker mt = new MediaTracker(this);
        mt.addImage(bild1,0);
        try
        {
            mt.waitForAll();
        }
        catch (InterruptedException e)
        {
            //nothing
        }

JFrame f = new JFrame();
        JPanel mainPanel = new JPanel();
        JPanel menuPanel = new JPanel();

f.getContentPane().setLayout(new BorderLayout));
        f.getContentPane().add( mainPanel, BorderLayout.WEST );
        f.getContentPane().add( menuPanel, BorderLayout.EAST );

menuPanel.setVisible(true);
        mainPanel.setVisible(true);
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        f.setSize( 1000,800 );
        mainPanel.setPreferredSize(new Dimension(800, 800));
        menuPanel.setPreferredSize(new Dimension(200, 800));
        mainPanel.setBackground(Color.white);(Color.lightGray);

f.setTitle("Test");
        f.setVisible( true );
        f.show();
        pack();
    }

public void paint(Graphics g)
    {
        g.drawImage(bild1,40,40,100,100,this);
    }
}

Müsste das Bild jetzt nicht trotzdem an der Pos: 40 40 dargestellt werden?

Grüße,
Thorsten F.