People on the Internet!
I am working on a food program for school.
// not relevant information, only for lulz: // The school offered a game, I did not;) this is a game // http://sotallytober.com/games/verbal/mexican/
Anyway, I drew the image in JPanel using the following code (this is a class that extends JPanel)
public class iconPanel extends JPanel {
ImageIcon image;
Image pic;
public iconPanel(String startScreenImage) {
image = new ImageIcon(startScreenImage);
pic = image.getImage();
this.setBackground(new Color(0, true));
}
@Override
public void paintComponent(Graphics g) {
g.drawImage (pic, 0, 0, getWidth (), getHeight (), this);
}
Now in my other class, where I have the layout and all the components, I declare my JPanels on top as follows:
private JPanel pnDrinkPlayerBW;
Then, in a method of the same class called MakeComponents, I installed JPanel for:
pnDrinkPlayerBW = new iconPanel("img/glass.jpg");
pnDrinkPlayerBW.setPreferredSize(new Dimension(183,61));
Panel, , makeLayout() ( , , , , )
, , glass.jpg , , beerGlass0.png, actionlistener actionEvents() :
pnDrinkPlayerBW = new iconPanel("img/beerGlass.png");
pnDrinkPlayerBW.setPreferredSize(new Dimension(183,61));
pnDrinkPlayerBW.repaint();
, :
public SpelScreen(){
makeComponents();
makeLayout();
actionEvents();
}
, SpelScreen iconPanel , spelscreen.
Java, , :)
!