Help with Swing. I come to you in time of great need, any help will be highly appreciated.
I have created a table game in java for a university project and now I must implement a graphical interface, we must use swing to do so.
The problem that I am facing here is that I am unable to run the actual game by simply adding a button and an action listener, the class that will actually run the game is the following,
package diagrammedeclasse;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import com.modeliosoft.modelio.javadesigner.annotations.objid;
import diagrammedeclasse.IdentityCard.Identity;
import diagrammedeclasse.RumourCard.rumour;
@objid ("ca5d80b7-7525-40a8-a35d-128867e0e079")
public class Player {
@objid ("db1ec2ea-ed45-4583-9835-29b566ac98e2")
private String name;
@objid ("956f1599-fada-4103-a41b-f39627d18dbe")
private boolean isRevealed;
@objid ("e023eaba-f6ba-4605-8d0e-7e7725d2cf0a")
private int points;
@objid ("88132cbd-f82b-4fa7-a075-3a43ad07ffdc")
private boolean isWitch;
@objid ("45b3c8e0-4313-4afe-9ed9-8df5132322e9")
private boolean isVillager;
private boolean isHuman;
@objid ("fc187775-6ca3-4edb-a506-34fca14f59c0")
private static int nombrejoueurs = 0;
@objid ("f46be522-129a-43fb-b28f-ba42f46f4441")
private int nbrebots;
@objid ("d6656a4b-fc5f-4853-a503-892451396129")
private static List<Player> players = new ArrayList<Player>();
@objid ("09677697-75f5-4d0a-82af-16cb5ceb0e9f")
private Strategy strategy;
@objid ("733c2266-b1c2-46ed-ba09-cc9e5bc263a9")
private Partie partie;
@objid ("cf286f41-1aa5-4779-b094-b5f5b65bd2fe")
private ArrayList<RumourCard> main;
@objid ("21a4aa0a-ee12-4ad4-95b2-666a28109172")
private ArrayList<RumourCard> carteJouee;
@objid ("680477cf-5eee-4b60-9e4c-09e960c34158")
public IdentityCard identityCard;
private Player dernierjoueur;
private int id;
@objid ("49d924b4-d22c-42e6-b847-c388472720e5")
public Player(String nom) {
this.id=++Player.nombrejoueurs;
this.carteJouee= new ArrayList<RumourCard>();
this.name = nom;
this.points=0;
this.main=new ArrayList<RumourCard>();
this.isVillager=false;
this.isWitch=false;
this.isHuman=true;
this.isRevealed=false;
this.identityCard=new IdentityCard(Identity.VILLAGER);
this.partie=null;
this.dernierjoueur=null;
this.addPlayer(this);
System.out.println("le joueur "+nom+" a ete cree");
System.out.println("le joueur numero "+this.id);
}
public void addPlayer(Player p1) {
Player.players.add(p1);
}
@objid ("bdef45fb-f512-412d-885a-36f4efe39d4a")
public void ajouterBot() {
System.out.println(Player.nombrejoueurs);
int nbjou = Player.nombrejoueurs;
Scanner sc= new Scanner(System.in);
System.out.println("Nombre de bots :");
for(int i=0;i<=6-nbjou;i++) {
System.out.println(i);}
nbrebots = sc.nextInt();
int nbretotal = nbrebots + nbjou;
if(nbretotal<3) {nbrebots=3-nbjou;}
System.out.println("On ajoute " +nbrebots+" bots");
Player.nombrejoueurs+=nbrebots;
}
//pour name (get;set)
@objid ("17536045-28a2-433f-9afa-fdd0734154f8")
public String getName() {
return name;
}
@objid ("3c175d47-6b75-429b-85f3-438939129a8b")
public void setName(String value) {
this.name = value;
}
//pour points (get;set)
@objid ("c4617fa5-0e1b-4af3-8e83-af1d947e7381")
public int getPoints() {
return this.points;
}
public int getId() {
return this.id;
}
@objid ("b13f6fa2-3d52-4bb1-92dd-58993b0f1b3b")
public Player choisirjoueur() {
Scanner sc= new Scanner(System.in);
System.out.println("Choisissez un joueur :");
int k=0;
for(Player playe : this.partie.player) {
if(playe.equals(this)) k++;
else {
System.out.println(k+1 +" : "+ playe.getName());
k++;
}
}
int selection = sc.nextInt();
Player p1= partie.player.get(selection-1);
System.out.println("joueur choisisser :"+p1.getName());
return p1;
}
public Player choisirjoueuraccuser() {
Scanner sc= new Scanner(System.in);
System.out.println("Choisissez un joueur :");
int k=0;
for(Player playe : this.partie.player) {
if(playe.equals(this) || playe.isRevealed)k++;
else {
System.out.println(k+1 +" : "+ playe.getName());
k++;
}
}
int selection = sc.nextInt();
Player p1= partie.player.get(selection-1);
System.out.println("joueur choisisser :"+p1.getName());
return p1;
}
public Player choisirjoueurautre() {
Player playerx=null;
Scanner sc= new Scanner(System.in);
System.out.println("Choisissez un joueur :");
int k=0;
for(Player playe : this.partie.player) {
if(playe.equals(getdernierJoueur()) || playe.equals(this) || playe.isRevealed)k++;
else {
System.out.println(k+1 +" : "+ playe.getName());
k++;
}
}
int selection = sc.nextInt();
System.out.println("joueur choisisser :"+ this.partie.player.get(selection-1).getName());
playerx= this.partie.player.get(selection-1);
return playerx;
}
@objid ("25e6de92-3f5b-4843-8179-8c02f40b390b")
public void chooseUsername() {
Scanner sc= new Scanner(System.in);
System.out.println("Choose a username :");
String nom = sc.nextLine();
this.setName(nom);
}
//methode pour choisir l'identite
@objid ("c09b5791-ad90-4c49-b968-e838b203f08e")
public void choisirIdentite() {
int selection;
Scanner input = new Scanner(System.in);
System.out.println(this.getName()+" Choose from these choices");
System.out.println("1 - Witch");
System.out.println("2 - Villager");
selection = input.nextInt();
if(selection==1) {
this.setIdentite(Identity.WITCH);
}
if(selection==2) {
this.setIdentite(Identity.VILLAGER);
}
}
//pour identityCard (get,set)
@objid ("64524bab-e797-4b2c-8838-7826a384cf65")
public void setIdentite(Identity newIdentity) {
identityCard.setIdentity(newIdentity);
}
@objid ("551eee99-17db-4dcf-bbb3-0e927c9eabd8")
public Identity getIdentite() {
return identityCard.getIdentity();
}
//methode pour reveler l'identite
@objid ("638fdbf0-7639-40ab-9d5a-78f330080882")
public void reveleridentite() {
this.isRevealed = true;
if (this.isWitch()) {
Player p1=this;
System.out.println(p1.getIdentite());
this.partie.joueurHorsPartie(p1);
}
else {
System.out.println(this.getIdentite());
}
}
public void reveleridentitesecretly() {
System.out.println(this.getIdentite());
}
public boolean revealedasVillager() {
if(this.isRevealed() && this.isVillager()) return true;
else return false;
}
public void prenercarteJouee() {
if(this.carteJouee.isEmpty()) {
System.out.println(this.getName()+" Ce joueur n'a pas des cartes jouer");
}
else {
Scanner sc= new Scanner(System.in);
System.out.println("Choisissez une carte des cartes jouees :");
int i=0;
Iterator<RumourCard> it = this.carteJouee.iterator();
while(it.hasNext()) {
System.out.println(i+1+" : "+it.next());
i++;
}
int selection = sc.nextInt();
System.out.println("Card jouee :"+this.carteJouee.get(selection-1));
this.main.add(this.carteJouee.get(selection-1));
this.carteJouee.remove(selection-1);
System.out.println("Cette carte a ete ajoute a ton main");
}
}
public void prendrandomcartede(Player p1) {
if(p1.main.size()==0) {
System.out.println(p1.getName()+" n'a plus des cartes dans son main ");
}
else {
Random random = new Random();
int selection = random.nextInt(p1.main.size())+1;
System.out.println("Choisissez une carte de :"+p1.getName());
this.main.add(p1.main.get(selection-1));
p1.main.remove(selection-1);
}
}
@objid ("259b6cfd-b9c7-4e13-a815-36617fc647e3")
public void prenerDiscardCard() {
if(this.partie.getDiscardCards().size()==0)
{
System.out.println("Il n'y a pas des discards cards");
}
else {
Scanner sc= new Scanner(System.in);
System.out.println("Choisissez une carte de Discard Card :");
int i=0;
Iterator<RumourCard> it = this.partie.getDiscardCards().iterator();
while(it.hasNext()) {
System.out.println(i+1+" : "+it.next());
i++;
}
int selection = sc.nextInt();
this.main.add(this.partie.getDiscardCards().get(selection-1));
System.out.println("Cette carte a ete ajoute a ton main :"+this.partie.getDiscardCards().get(selection-1));
this.partie.getDiscardCards().remove(this.partie.getDiscardCards().get(selection-1));
}
}
@objid ("77cc019a-c10d-47e9-9e07-2c550955ac23")
public void ajouterDiscardCard() {
if(this.main.isEmpty()) {
System.out.println(this.getName()+" a aucune carte dans son main");
}else {
Scanner sc= new Scanner(System.in);
System.out.println("Choisissez une carte de ton main :");
int i=0;
Iterator<RumourCard> it = this.main.iterator();
while(it.hasNext()) {
System.out.println(i+1+" : "+it.next());
i++;
}
int selection = sc.nextInt();
System.out.println("Discard card :"+this.main.get(selection-1));
this.partie.getDiscardCards().add(this.main.get(selection-1));
this.main.remove(this.main.get(selection-1));
}
}
public void ajouterDiscardCard(RumourCard c1) {
System.out.println("Discard card :"+c1.getRumourCard());
this.partie.getDiscardCards().add(c1);
this.main.remove(c1);
}
@objid ("c8fab12b-fd4d-400f-8999-022e719faf24")
public void jouerCarte() {
Player player1=this;
int count=0;
System.out.println("Choisissez une carte de ton main :");
Iterator<RumourCard> it = this.main.iterator();
int i =0 ;
while(it.hasNext()) {
RumourCard hey = it.next();
if(!hey.jouablehunt(hey.getRumourCard(),player1)) count ++;
System.out.println(i+1+" : "+hey);
i++;
}
if(count==main.size()) {
System.out.println(player1.getName()+" a aucune carte qui peut etre jouer maintenant");
System.out.println("il doit accuser un joueur");
player1.accuse();
}
else {
Scanner sc= new Scanner(System.in);
int selection = sc.nextInt();
System.out.println("Card jouee :"+this.main.get(selection-1));
RumourCard rm = this.main.get(selection-1);
if(rm.jouablehunt(rm.getRumourCard(),player1))
{
this.carteJouee.add(rm);
this.main.remove(rm);
rm.useHunt( player1,rm.getRumourCard());
}
else
{
System.out.println("Cette carte ne peut pas etre jouer maintenant");
System.out.println("Choisir une autre carte de nouveau");
player1.jouerCarte();
}
}
}
public void jouerCarteaccuser() {
Player player1=this;
int count=0;
System.out.println("Choisissez une carte de ton main :");
int i=0;
Iterator<RumourCard> it = this.main.iterator();
while(it.hasNext()) {
RumourCard hey = it.next();
if(!hey.jouablewitch(hey.getRumourCard(),player1)) count ++;
System.out.println(i+1+" : "+hey);
i++;
}
if(count==main.size()) {
System.out.println(player1.getName()+" a aucune carte qui peut etre jouer maintenant");
System.out.println("il doit reveler son identite");
player1.revelerIdentiteAfterAccusation(player1.getdernierJoueur());
}
else {
Scanner sc= new Scanner(System.in);
int selection = sc.nextInt();
System.out.println("Card jouee :"+this.main.get(selection-1));
RumourCard rm = this.main.get(selection-1);
if(rm.jouablewitch(rm.getRumourCard(),player1))
{
this.carteJouee.add(rm);
this.main.remove(rm);
rm.useWitch(player1,rm.getRumourCard());
}
else
{
System.out.println("Cette carte ne peut pas etre jouer maintenant");
System.out.println("Choisir une autre carte de nouveau");
player1.jouerCarte();
}
}
}
//pour isRevealed (get)
@objid ("f1371808-24e7-4ce0-8b41-861cee45b646")
public boolean isRevealed() {
return this.isRevealed;
}
public void setisRevealed( boolean c1) {
this.isRevealed=c1;
}
//pour isWitch (get)
@objid ("e5581073-0e3a-49d9-9a1f-290bbc480a37")
public boolean isWitch() {
return this.getIdentite() == Identity.WITCH;
}
public boolean isHuman() {
return this.isHuman;
}
public void setHuman(boolean isHuman) {
this.isHuman = isHuman;
}
//for isVillager (get)
@objid ("0b3c7a19-052a-4490-8b36-101d73759ddc")
public boolean isVillager() {
return this.getIdentite() ==Identity.VILLAGER;
}
//for main (get)
@objid ("ca60f750-7879-4e5a-935f-933431e37748")
public ArrayList<RumourCard> getMain() {
return this.main;
}
//for carteJouee (get)
@objid ("95bb5134-0dcd-4c28-8171-0c57a80eb878")
public ArrayList<RumourCard> getcarteJouee() {
return this.carteJouee;
}
//Methode pour ajouter des points
@objid ("a264915c-9783-4165-b5f7-af5db30bf382")
public void addPoints(int points) {
this.points += points;
System.out.println(this.getName()+" a gagner "+points+" points");
}
public void subPoints(int points) {
this.points -= points;
System.out.println(this.getName()+" a perdu "+points+" points");
}
public Partie getPartie() {
return this.partie;
}
public void setPartie(Partie partie) {
this.partie=partie;
}
public ArrayList<RumourCard> getDiscardedCards() {
return this.partie.getDiscardCards();
}
@objid ("4fc9c966-d181-4d8c-a7d1-29e726f50c63")
public void revelerIdentiteAfterAccusation(Player accuser) {
Player p1 = this;
this.reveleridentite();
if (p1.isWitch()) {
accuser.addPoints(1);
accuser.jouer();
} else {
p1.jouer();
}
}
public void accuse() {
this.dernierJoueurs(this);
joueraccuser(this);
}
public void accuseautre() {
joueraccuserautre(this);
}
public void joueraccuserautre(Player accuser) {
int k=0;
for(Player playe : partie.player) {
if(playe.equals(getdernierJoueur()) || playe.equals(accuser) || playe.isRevealed);
else {
k++;
}
}
if(k==0) {
System.out.println("C'est pas possible ");
accuser.jouerCarte();
}
else {
Player acc = accuser.choisirjoueurautre();
if(acc.isHuman) {
if(acc.main.size()==0) {
System.out.println("Tu n'as plus des cartes Rumour");
System.out.println("Tu doit reveler ton identite");
acc.revelerIdentiteAfterAccusation(accuser);
}
else {
Scanner sc= new Scanner(System.in);
System.out.println("Joueur ACCUSE "+acc.getName()+" 1 si tu veux jouer une carte WITCH ou 2 si tu veux reveler ton identite");
System.out.println(1+" : Jouer carte avec effet Witch");
System.out.println(2+" : Reveler identite");
int selection = sc.nextInt();
if(selection==1) {acc.jouerCarteaccuser(); }
if(selection==2) {acc.revelerIdentiteAfterAccusation(accuser);}
}
}else {
Bots bot = (Bots)acc;
bot.accuseautre(accuser, acc);
}
}
}
@objid ("58706d4b-9e70-4ce5-9720-b5da656527d5")
public void joueraccuser(Player accuser) {
Player acc = accuser.choisirjoueuraccuser();
if(acc.isHuman) {
if(acc.main.size()==0) {
System.out.println("Tu n'as plus des cartes Rumour");
System.out.println("Tu doit reveler ton identite");
acc.revelerIdentiteAfterAccusation(accuser);
}
else {
Scanner sc= new Scanner(System.in);
System.out.println("Joueur ACCUSE "+acc.getName()+" 1 si tu veux jouer une carte WITCH ou 2 si tu veux reveler ton identite");
System.out.println(1+" : Jouer carte avec effet Witch");
System.out.println(2+" : Reveler identite");
int selection = sc.nextInt();
if(selection==1) {acc.jouerCarteaccuser(); }
if(selection==2) {acc.revelerIdentiteAfterAccusation(accuser);}
}
}
else {
Bots bot = (Bots)acc;
bot.accuse(accuser, acc);
}
}
@objid ("d24ef235-c674-4527-b040-c6f9a23b73e0")
public void ajouterCarte(RumourCard card) {
this.main.add(card);
}
public void jouer() {
if(this.partie.partieTermier()) {
System.out.println("Partie terminer");
this.partie.afficherscore();
}
else {
this.dernierJoueurs(this);
System.out.println("C'est le tour de "+this.getName());
if(this.main.size()==0) {
System.out.println("Tu n'as plus des cartes Rumour");
System.out.println("Tu doit accuser un autre joueur");
this.accuse();
}
else {
Scanner sc= new Scanner(System.in);
System.out.println("Choisisser 1 pour jouer une carte avec un effet hunt ou 2 pour accuser un autre joueur");
System.out.println(1+" : Jouer carte avec effet Hunt");
System.out.println(2+" : Accuser un autre joueur");
int selection = sc.nextInt();
if(selection==1) {this.jouerCarte(); }
if(selection==2) {this.accuse();}
}
}
}
public String toString() {
return "" +name;
}
public String printPlayerCards() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(name + " has the following cards:\n");
for (RumourCard card : main) {
stringBuilder.append(card + "\n");
}
return stringBuilder.toString();
}
public void dernierJoueurs(Player p1) {
for(Player plx : players) {
plx.dernierjoueur=p1;
}
}
public Player getdernierJoueur() {
return dernierjoueur;
}
public static void main(String[] args) {
Partie game = new Partie();
Bots marc = new Bots("marc");
Bots taha = new Bots("taha");
Bots grg = new Bots("grg");
Bots elissa = new Bots("elissa");
Bots salim = new Bots("salim");
while(!game.jeuterminer())
{
game.initialiser();
game.ajouterJoueur(marc);
game.ajouterJoueur(elissa);
game.ajouterJoueur(grg);
game.ajouterJoueur(taha);
game.ajouterJoueur(salim);
game.initialiserCarte();
game.afficherscore();
game.choisirIdentite();
game.distribuerRumourCard();
game.displayCardsForAllPlayers();
game.commencerpar();
}
}
}
The above is my code for the main engine, i didn't post the code for all the classes, but the game runs well on console side.
package diagrammedeclasse;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class interfacetest {
private JFrame frame;
private Player player;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
interfacetest window = new interfacetest();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public interfacetest() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 1280, 720);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton bot4 = new JButton("New button");
bot4.setBounds(245, 10, 164, 230);
JButton bot3 = new JButton("New button");
bot3.setBounds(193, 10, 164, 230);
JButton bot2 = new JButton("New button");
bot2.setBounds(139, 10, 164, 230);
JButton bot1 = new JButton("New button");
bot1.setBounds(87, 10, 164, 230);
JButton bot0 = new JButton("New button");
bot0.setBounds(31, 10, 164, 230);
// getting the image of the angry mob card
DeckImage angrymobcard = new DeckImage();
BufferedImage angrymob = angrymobcard.getImage(0, 0);
// getting the image of the inquisition card
DeckImage inquisitioncard = new DeckImage();
BufferedImage inquisition = inquisitioncard.getImage(0, 1);
// getting the image of the pointed hat card
DeckImage pointedhatcard = new DeckImage();
BufferedImage pointedhat = pointedhatcard.getImage(0, 2);
// getting the image of the hooked nose card
DeckImage hookednosecard = new DeckImage();
BufferedImage hookednose = hookednosecard.getImage(1, 0);
// getting the image of the broomstick card
DeckImage broomstickcard = new DeckImage();
BufferedImage broomstick = broomstickcard.getImage(1, 1);
// getting the image of the wart card
DeckImage wartcard = new DeckImage();
BufferedImage wart = wartcard.getImage(1, 2);
// card5.setIcon(new ImageIcon(wart));
// getting the image of the ducking stool card
DeckImage duckingstoolcard = new DeckImage();
BufferedImage duckingstool = duckingstoolcard.getImage(2, 0);
// hon code el card.setIcon(new ImageIcon(duckingstool))
// getting the image of the cauldron card
DeckImage cauldroncard = new DeckImage();
BufferedImage cauldron = cauldroncard.getImage(2, 1);
// getting the image of the evil Eye card
DeckImage evileyecard = new DeckImage();
BufferedImage evileye = evileyecard.getImage(2, 2);
// getting the image of the toad card
DeckImage toadcard = new DeckImage();
BufferedImage toad = toadcard.getImage(3, 0);
// getting the image of the black cat card
DeckImage blackcatcard = new DeckImage();
BufferedImage blackcat = blackcatcard.getImage(3, 1);
// getting the image of the pet newt card
DeckImage petnewtcard = new DeckImage();
BufferedImage petnewt = petnewtcard.getImage(3, 2);
JButton card = new JButton("New button");
card.setBounds(31, 437, 164, 230);
JButton card1 = new JButton("New button");
card1.setBounds(205, 437, 164, 230);
JButton card2 = new JButton("New button");
card2.setBounds(382, 437, 164, 230);
JButton card3 = new JButton("New button");
card3.setBounds(559, 437, 164, 230);
JButton card4 = new JButton("New button");
card4.setBounds(736, 437, 164, 230);
JLabel welcometext = new JLabel("Welcome to Witch Hunt !");
welcometext.setHorizontalAlignment(SwingConstants.CENTER);
welcometext.setBounds(205, 10, 409, 226);
frame.getContentPane().add(welcometext);
JButton exitbutton = new JButton("Exit");
exitbutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.exit(0);
}
});
JButton startbutton = new JButton("Start");
startbutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// remove old stuff
startbutton.setVisible(false);
exitbutton.setVisible(false);
welcometext.setVisible(false);
// start the new game
Partie game = new Partie();
Bots marc = new Bots("marc");
Bots taha = new Bots("taha");
Bots grg = new Bots("grg");
Bots elissa = new Bots("elissa");
Bots salim = new Bots("salim");
while(!game.jeuterminer())
{
game.initialiser();
game.ajouterJoueur(marc);
game.ajouterJoueur(elissa);
game.ajouterJoueur(grg);
game.ajouterJoueur(taha);
game.ajouterJoueur(salim);
game.initialiserCarte();
game.afficherscore();
game.choisirIdentite();
game.distribuerRumourCard();
game.displayCardsForAllPlayers();
game.commencerpar();
}
// show the back of the other player cards
DeckImage backcard = new DeckImage();
BufferedImage back = backcard.getImage(0, 3);
frame.getContentPane().add(bot4);
frame.getContentPane().add(bot3);
frame.getContentPane().add(bot2);
frame.getContentPane().add(bot1);
frame.getContentPane().add(bot0);
bot4.setIcon(new ImageIcon(back));
bot3.setIcon(new ImageIcon(back));
bot2.setIcon(new ImageIcon(back));
bot1.setIcon(new ImageIcon(back));
bot0.setIcon(new ImageIcon(back));
// create your cards
frame.getContentPane().add(card);
frame.getContentPane().add(card1);
frame.getContentPane().add(card2);
frame.getContentPane().add(card3);
frame.getContentPane().add(card4);
// show your cards
ArrayList<JButton> bouton = new ArrayList<JButton>();
bouton.add(card);
bouton.add(card1);
bouton.add(card2);
bouton.add(card3);
bouton.add(card4);
player = player.getdernierJoueur();
Iterator<RumourCard> it = player.getMain().iterator();
for (int i = 0; i < 5; i++) {
while (it.hasNext()) {
switch (it.next().getRumourCard()) {
case Angry_Mob:
bouton.get(i).setIcon(new ImageIcon(angrymob));
break;
case The_Inquisition:
bouton.get(i).setIcon(new ImageIcon(inquisition));
break;
case Pointed_Hat:
bouton.get(i).setIcon(new ImageIcon(pointedhat));
break;
case Hooked_Nose:
bouton.get(i).setIcon(new ImageIcon(hookednose));
break;
case Broomstick:
bouton.get(i).setIcon(new ImageIcon(broomstick));
break;
case Wart:
bouton.get(i).setIcon(new ImageIcon(wart));
break;
case Ducking_Stool:
bouton.get(i).setIcon(new ImageIcon(duckingstool));
break;
case Cauldron:
bouton.get(i).setIcon(new ImageIcon(cauldron));
break;
case Evil_eye:
bouton.get(i).setIcon(new ImageIcon(evileye));
break;
case Toad:
bouton.get(i).setIcon(new ImageIcon(toad));
break;
case Black_Cat:
bouton.get(i).setIcon(new ImageIcon(blackcat));
break;
case Pet_Newt:
bouton.get(i).setIcon(new ImageIcon(petnewt));
break;
}
}
}
}
});
startbutton.setBounds(10, 10, 185, 108);
frame.getContentPane().add(startbutton);
exitbutton.setBounds(10, 128, 185, 108);
frame.getContentPane().add(exitbutton);
}
}
Here is what i have tried to do in the graphical interface part so far, i got the images for the cards and thought of getting a start button that runs the main code of the game and when i do this, the game runs fine on console but the graphical interface freezes. I want to know if this is the right way or if there is another way to do it. Any help would be really appreciated.