Question
I need to convert this from SWING to JAVAFX please! this is very very very urgent!!!! import java.awt.Color; import java.awt.event.MouseEvent; import javax.swing.JLabel; import javax.swing.JPanel; public
I need to convert this from SWING to JAVAFX please! this is very very very urgent!!!!
import java.awt.Color;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class minesweeperGUI extends javax.swing.JFrame implements java.awt.event.MouseListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
minesweeper game;
JPanel gamePanel;
JPanel statusPanel;
JLabel statusLabel;
minesweeperGUI.mineButton[][] mb;
Color backGround;
int numRows = 9;
int numCols = 9;
javax.swing.Icon mineIcon = new javax.swing.ImageIcon(getClass().getResource("mine.jpg"));
javax.swing.Icon minexIcon = new javax.swing.ImageIcon(getClass().getResource("minex.jpg"));
javax.swing.Icon mineredIcon = new javax.swing.ImageIcon(getClass().getResource("minered.jpg"));
javax.swing.Icon flagIcon = new javax.swing.ImageIcon(getClass().getResource("flag.jpg"));
@SuppressWarnings("deprecation")
public minesweeperGUI()
{
backGround = Color.WHITE;
javax.swing.JMenu localJMenu = new javax.swing.JMenu("File");
localJMenu.setMnemonic('F');
javax.swing.JMenuItem localJMenuItem1 = new javax.swing.JMenuItem("New");
localJMenuItem1.setMnemonic('N');
localJMenu.add(localJMenuItem1);
localJMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent paramAnonymousActionEvent) {
minesweeperGUI.this.newGame();
}
});
javax.swing.JMenuItem localJMenuItem2 = new javax.swing.JMenuItem("Exit");
localJMenuItem2.setMnemonic('X');
localJMenu.add(localJMenuItem2);
localJMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent paramAnonymousActionEvent) {
System.exit(0);
}
});
javax.swing.JMenuBar localJMenuBar = new javax.swing.JMenuBar();
setJMenuBar(localJMenuBar);
localJMenuBar.add(localJMenu);
gamePanel = new JPanel();
gamePanel.setLayout(new java.awt.GridLayout(numRows, numCols));
statusPanel = new JPanel();
statusPanel.setLayout(new java.awt.FlowLayout(1));
statusLabel = new JLabel();
statusLabel.setFont(new java.awt.Font("Serif", 1, 24));
statusPanel.add(statusLabel);
java.awt.Container localContainer = getContentPane();
localContainer.setLayout(new java.awt.BorderLayout());
localContainer.add(statusPanel, "North");
localContainer.add(gamePanel, "Center");
gamePanel.addMouseListener(this);
game = new minesweeper(numRows, numCols);
mb = new minesweeperGUI.mineButton[numRows][numCols];
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++)
{
mb[i][j] = new minesweeperGUI.mineButton(i, j);
mb[i][j].addMouseListener(this);
gamePanel.add(mb[i][j]);
}
}
statusLabel.setText("New Game");
setTitle("Minesweeper");
setContentPane(localContainer);
setSize(400, 300);
show();
}
private void newGame() {
game = new minesweeper(numRows, numCols);
updateGame();
statusLabel.setText("New Game");
}
public void updateGame()
{
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
switch (game.getBoard(i, j))
{
case '1':
mb[i][j].setText("1");
mb[i][j].setForeground(Color.blue);
mb[i][j].setIcon(null);
mb[i][j].setBackground(backGround);
break;
case '2':
mb[i][j].setText("2");
mb[i][j].setForeground(Color.green);
mb[i][j].setIcon(null);
mb[i][j].setBackground(backGround);
break;
case '3':
mb[i][j].setText("3");
mb[i][j].setForeground(Color.red);
mb[i][j].setIcon(null);
mb[i][j].setBackground(backGround);
break;
case '4':
mb[i][j].setText("4");
mb[i][j].setForeground(Color.orange);
mb[i][j].setIcon(null);
mb[i][j].setBackground(backGround);
break;
case '5':
case '6':
case '7':
case '8':
mb[i][j].setText(Integer.toString(game.getBoard(i, j)));
mb[i][j].setIcon(null);
mb[i][j].setBackground(backGround);
break;
case ' ':
mb[i][j].setText("");
mb[i][j].setIcon(null);
mb[i][j].setBackground(backGround);
break;
case 'X':
mb[i][j].setText("");
mb[i][j].setIcon(null);
mb[i][j].setBackground(null);
break;
case '?':
mb[i][j].setText("?");
mb[i][j].setForeground(Color.blue);
mb[i][j].setIcon(null);
break;
case 'F':
mb[i][j].setText("");
mb[i][j].setIcon(flagIcon);
break;
case '*':
mb[i][j].setText("");
mb[i][j].setBackground(backGround);
mb[i][j].setIcon(mineIcon);
break;
case '-':
mb[i][j].setText("");
mb[i][j].setBackground(backGround);
mb[i][j].setIcon(minexIcon);
break;
case '!':
mb[i][j].setText("");
mb[i][j].setBackground(backGround);
mb[i][j].setIcon(mineredIcon);
}
}
}
statusLabel.setText(game.getStatus());
if (game.getStatus().equalsIgnoreCase("play"))
{
statusLabel.setForeground(Color.black);
statusLabel.setText("Game in Progress ...");
} else if (game.getStatus().equalsIgnoreCase("win"))
{
statusLabel.setForeground(new Color(10, 104, 17));
statusLabel.setText("You Win! : - )");
}
else
{
statusLabel.setForeground(Color.red);
statusLabel.setText("You Lose : - (");
}
}
public static void main(String[] paramArrayOfString)
{
minesweeperGUI localMinesweeperGUI = new minesweeperGUI();
localMinesweeperGUI.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent paramAnonymousWindowEvent) {
System.exit(0);
}
});
}
public void mouseClicked(MouseEvent paramMouseEvent)
{
minesweeperGUI.mineButton localMineButton = (minesweeperGUI.mineButton)paramMouseEvent.getSource();
if (paramMouseEvent.getButton() == 1)
{
game.markTile(localMineButton.getRow(), localMineButton.getCol(), 0);
}
else if (paramMouseEvent.getButton() == 3)
{
switch (game.getTiles(localMineButton.getRow(), localMineButton.getCol()))
{
case 1:
game.markTile(localMineButton.getRow(), localMineButton.getCol(), 3);
break;
case 3:
game.markTile(localMineButton.getRow(), localMineButton.getCol(), 2);
break;
case 2:
game.markTile(localMineButton.getRow(), localMineButton.getCol(), 1);
}
}
updateGame();
}
public void mousePressed(MouseEvent paramMouseEvent) {}
public void mouseReleased(MouseEvent paramMouseEvent) {}
public void mouseEntered(MouseEvent paramMouseEvent) {}
public void mouseExited(MouseEvent paramMouseEvent) {}
private class mineButton
extends javax.swing.JButton
{
/**
*
*/
private static final long serialVersionUID = 1L;
int r;
int c;
public mineButton(int paramInt1, int paramInt2)
{
r = paramInt1;
c = paramInt2;
}
public int getRow() {
return r;
}
public int getCol() { return c; }
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started