Jump to content
  • Advertisement
Sign in to follow this  
Patriarch K

Getting images from other class into main applet

This topic is 2125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This may be a very easy problem, but I'm very confused at the moment. I have these two class files and I want to be able to display the image. It works perfectly if I have everything in the main class (the paintComponent) and so, but I want this to work. How can I do?


public class Main extends JApplet {

Game g = new Game();

public void Init(){
add(g);
g.setVisible(true);
}
}


public class Game extends JPanel implements ActionListener{

ImageIcon backgroundIcon = new ImageIcon(this.getClass().getResource("background3.png"));
Image background = backgroundIcon.getImage();

Game(){
setFocusable(true);
repaint();
setSize(1024,768);
setVisible(true);
setFocusable(true);
repaint();
}

@Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(background, 0, 0, null);
}

@Override
public void actionPerformed(ActionEvent arg0) {
}

}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!