this is the GUI class:
package view;
import javax.swing.*;
import controller.RollDiceWindowController;
import model.GameEngineImpl;
import java.awt.FlowLayout;
public class RollDiceWindow extends JPanel{
GameEngineImpl gameengineimpl;
private ImageIcon dice1=new ImageIcon("src/dice1.png");
private ImageIcon dice2=new ImageIcon("src/dice2.png");
private ImageIcon dice3=new ImageIcon("src/dice3.png");
private ImageIcon dice4=new ImageIcon("src/dice4.png");
private ImageIcon dice5=new ImageIcon("src/dice5.png");
private ImageIcon dice6=new ImageIcon("src/dice6.png");
public RollDiceWindow(GameEngineImpl gameengineimpl){
setLayout(new FlowLayout(FlowLayout.LEFT,50,50));
JButton jbtRoll= new JButton("Roll for player");
add(jbtRoll);
jbtRoll.addMouseListener(new RollDiceWindowController(gameengineimpl,this));
add(new JLabel(dice1));
add(new JLabel(dice1));
}
int dice=(int)(Math.random()*6+1);
int dicee=(int)(Math.random()*6+1);
public int getdice(){
return dice;
}
public int getdicee(){
return dicee;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GameEngineImpl gameengineimpl=new GameEngineImpl();
RollDiceWindow frame=new RollDiceWindow(gameengineimpl);
frame.setSize(600, 600);
frame.setVisible(true);
}
}
this is the controller class:
package controller;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import view.MainWindow;
import view.RollDiceWindow;
import model.GameEngineImpl;
import model.SimplePlayer;
import model.interfaces.DicePair;
import model.interfaces.GameEngine;
public class RollDiceWindowController extends JPanel implements MouseListener{
private GameEngine gameengine;
private RollDiceWindow rollDiceWindow;
private ImageIcon dice1=new ImageIcon("src/dice1.png");
private ImageIcon dice2=new ImageIcon("src/dice2.png");
private ImageIcon dice3=new ImageIcon("src/dice3.png");
private ImageIcon dice4=new ImageIcon("src/dice4.png");
private ImageIcon dice5=new ImageIcon("src/dice5.png");
private ImageIcon dice6=new ImageIcon("src/dice6.png");
private JLabel label;
//private int initialDelay=1;
//private int finalDelay=100;
//private int delayIncrement=20;
private SimplePlayer simplePlayer;
MainWindow mainwindow;
public RollDiceWindowController(GameEngine gameengine, RollDiceWindow rollDiceWindow){
this.gameengine=gameengine;
this.rollDiceWindow=rollDiceWindow;
}
@Override
public void mouseClicked(MouseEvent arg0) {
int initialDelay=1;
int finalDelay=100;
int delayIncrement=20;
//simplePlayer=new SimplePlayer("1","jason",200);
//gameengine.rollPlayer(simplePlayer, initialDelay, finalDelay, delayIncrement);
label.add(new JLabel(dice1));
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
My question is in the controller class, I try to add a new label which is a PNG, I tried a couple of ways, but the PNG never shows in the frame.