Jump to content

View more

Image of the Day

Project built to test Unity's networking
#gamedev #indiedev #screenshotsaturday #indiedevhour #madewithunity https://t.co/vcsky4QFKr
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Getting images from other class into main applet

2: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 Patriarch K   Members   

212
Like
0Likes
Like

Posted 25 December 2012 - 04:47 AM

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) {
}

}




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.