Java ImageIcon trying to set up

16 views Asked by At
public class MyPanel extends JPanel implements ActionListener {

        final int PANEL_WIDTH = 500;
    final int PANEL_HEIGHT = 500;

    
    Image BackGroundImage2;
    Image BackGroundImage;
    
    
    int xVelocity = 1;
    int yVelocity = 1;
    int x = 0;
    int y = 0;
    
    
    MyPanel(){
    
        
        this.setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
        this.setBackground(Color.lightGray);//another way to paint background
        BackGroundImage = new ImageIcon("BackGroundImage.jpg").getImage();
        
    }
    
    public void paint (Graphics g) {
        super.paint(g); //another way to paint background
        Graphics2D g2d = (Graphics2D ) g; 
        g2d.drawImage(BackGroundImage2, x, y, null);
        
        
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        
    }
    
}

Trying to set up an image that will cover MyPanel under the JMenu bar. Please see the code above.

And it still doesn't show the image. This paints the color of the Panel, and does everything I want but the image painted. Please advise.

0

There are 0 answers