Re: moving a token from a board(JPG)



Sir, this is the code of my game for reference:

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.text.*;
import javax.swing.*;

public class initiateGame extends JFrame implements ActionListener
{
private JPanel WeaponsPanel;
private JPanel charactersPanel;
private JPanel cardsPanel;
private JPanel buttonsPanel;
private JPanel planetsPanel;
private JPanel textPanel;
private JPanel bottom;
private JPanel questionPanel;
private JPanel spinnerPanel;
private JPanel spinQuesPanel;
private JTextField textField;
private JTextArea textArea;
private JTextArea nameBox;
private JTextArea IPBox;
private JButton createGameButton;
private JButton exitButton;
private JButton suggestionButton;
private JButton refuteButton;
private JButton submit;
private JButton spinButton;
private JCheckBox tina;
private JCheckBox same;
private JCheckBox mona;
private JCheckBox geroge;
private JCheckBox ubura;
private JCheckBox steve;
private JCheckBox weaponPhaser;
private JCheckBox weaponHyperRope;
private JCheckBox weaponLaserSword;
private JCheckBox weaponBiolgicalAgents;
private JCheckBox weaponFlamethrower;
private JCheckBox weaponRadioactiveChemical;
private JLabel picLabel[];
private JLabel planetsLabel;
private static String userName, questionText, planetsName;
private final static int totalNums = 6, timeToWait = 75;
private int realNumSpins, numSpins, currentSpinLocation = 0;
private javax.swing.Timer t, t2;


public static void main (String arg[])
{
new initiateGame();
}

public initiateGame()
{
WeaponsPanel = new JPanel();
charactersPanel = new JPanel();
cardsPanel = new JPanel();
buttonsPanel = new JPanel();
planetsPanel = new JPanel();
textPanel = new JPanel();
bottom = new JPanel();
questionPanel = new JPanel();
spinnerPanel = new JPanel();
spinQuesPanel = new JPanel();
textField = new JTextField(20);
textArea = new JTextArea();
createGameButton = new JButton("Create Game");
exitButton = new JButton("Exit");
submit = new JButton("Submit Question");
suggestionButton = new JButton("Make Suggestion");
refuteButton = new JButton("Refute");
spinButton = new JButton("Spin");
tina = new JCheckBox("Tina Time Traveler");
same = new JCheckBox("Same Space Voyager");
mona = new JCheckBox("Mona Moon Walker");
geroge = new JCheckBox("George Galaxy Wanderer");
ubura = new JCheckBox("Ubura Universalist");
steve = new JCheckBox("Steve Stargazer");
weaponPhaser = new JCheckBox("Phaser");
weaponHyperRope = new JCheckBox("Hyper Rope");
weaponLaserSword = new JCheckBox("Laser Sword");
weaponBiolgicalAgents = new JCheckBox("Biological Agents");
weaponFlamethrower = new JCheckBox("Flamethrower");
weaponRadioactiveChemical = new JCheckBox("Radioactive
Chemical");

cardsPanel.add(WeaponsPanel, BorderLayout.EAST);
cardsPanel.add(charactersPanel, BorderLayout.WEST);

bottom.setLayout(new FlowLayout(FlowLayout.LEFT));
bottom.add(buttonsPanel);
bottom.add(textPanel);

buttonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
buttonsPanel.add(createGameButton);
createGameButton.setActionCommand("create");
createGameButton.addActionListener(this);
spinButton.setMnemonic('s');
spinButton.setActionCommand("spin");
spinButton.addActionListener(this);
buttonsPanel.add(spinButton);
buttonsPanel.add(suggestionButton);
buttonsPanel.add(refuteButton);
buttonsPanel.add(exitButton);
exitButton.setActionCommand("exit");
exitButton.addActionListener(this);

questionPanel.setLayout(new FlowLayout());

textPanel.setLayout(new BoxLayout(textPanel,
BoxLayout.Y_AXIS));
textArea.setBackground(Color.white);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
JScrollPane statusScroll = new JScrollPane(textArea);
statusScroll.setPreferredSize(new Dimension(10, 80));

statusScroll.setVerticalScrollBarPolicy(statusScroll.VERTICAL_SCROLLBAR_AS_NEEDED);
textPanel.add(statusScroll);
textPanel.add(questionPanel);

questionPanel.add(textField);
submit.setMnemonic('q');
submit.setActionCommand("submit");
submit.addActionListener(this);
questionPanel.add(submit);

cardsPanel.setLayout(new BoxLayout(cardsPanel,
BoxLayout.X_AXIS));
cardsPanel.add(charactersPanel);
cardsPanel.add(WeaponsPanel);

charactersPanel.setLayout(new BoxLayout(charactersPanel,
BoxLayout.Y_AXIS));
charactersPanel.add(tina);
charactersPanel.add(same);
charactersPanel.add(mona);
charactersPanel.add(geroge);
charactersPanel.add(ubura);
charactersPanel.add(steve);

WeaponsPanel.setLayout(new BoxLayout(WeaponsPanel,
BoxLayout.Y_AXIS));
WeaponsPanel.add(weaponPhaser);
WeaponsPanel.add(weaponHyperRope);
WeaponsPanel.add(weaponLaserSword);
WeaponsPanel.add(weaponBiolgicalAgents);
WeaponsPanel.add(weaponFlamethrower);
WeaponsPanel.add(weaponRadioactiveChemical);

spinQuesPanel.setLayout(new GridLayout(2,0));
spinQuesPanel.add(spinnerPanel);

ImageIcon[] nums = new ImageIcon[totalNums];
picLabel = new JLabel[totalNums];
for (int i=0; i < totalNums; i++)
{
nums[i] = new ImageIcon((i+1) + ".jpg");
picLabel[i] = new JLabel();
picLabel[i].setIcon(nums[i]);
spinnerPanel.add(picLabel[i]);

picLabel[i].setBorder(BorderFactory.createLineBorder(Color.WHITE,1));
}

ImageIcon planets = new ImageIcon("GameBoard.jpg");
planetsLabel = new JLabel();
planetsLabel = new JLabel();
planetsLabel.setIcon(planets);
planetsPanel.add(planetsLabel);

planetsLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE,1));

//set the layout
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(spinQuesPanel, BorderLayout.NORTH);
contentPane.add(cardsPanel, BorderLayout.EAST);
contentPane.add(bottom, BorderLayout.SOUTH);
contentPane.add(planetsPanel, BorderLayout.CENTER);
setTitle("Galaxy Slueth");
setSize(850, 700);
setVisible(true);
}

private void loginWindow()
{
}

private void joinWindow()
{
}

private void hostWindow()
{
}

public void actionPerformed(ActionEvent e)
{
if ("spin".equals(e.getActionCommand()))
{
//spin function is called
spinButton.setEnabled(false);
for (int i=0; i < totalNums; i++)

picLabel[i].setBorder(BorderFactory.createLineBorder(Color.WHITE,1));
spinner();
}
else if ("submit".equals(e.getActionCommand()))
{
//sends message
questionText = textField.getText();
textArea.append("Question submitted by " + userName +
": \"" + questionText + "\"\n");
}
else if ("exit".equals(e.getActionCommand()))
{
System.exit(0);
}
}

public void spin()
{

picLabel[currentSpinLocation].setBorder(BorderFactory.createLineBorder(Color.WHITE,1));
currentSpinLocation++;
if (currentSpinLocation >= totalNums)
currentSpinLocation = 0;

picLabel[currentSpinLocation].setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
}

public void spinner()
{
//spinner code
realNumSpins = (int)(totalNums*Math.random()) + 1;

numSpins = 12 + realNumSpins;
t = new javax.swing.Timer(timeToWait,taskPerformer);
t2 = new javax.swing.Timer(timeToWait *
numSpins,taskPerformer2);
t.start();
t2.setRepeats(false);
t2.start();
}

public ActionListener taskPerformer = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
spin();
}
};

public ActionListener taskPerformer2 = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
t.stop();
textArea.append(userName + " spun a " + realNumSpins +
".\n");

picLabel[currentSpinLocation].setBorder(BorderFactory.createLineBorder(Color.WHITE,1));

picLabel[realNumSpins-1].setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
currentSpinLocation = 0;
numSpins = 0;
realNumSpins = 0;
spinButton.setEnabled(true);
}
};
}

Have u even heard a game called galaxy sleuth?
It's based on a card game "CLUE"

.