Write a program which will load an image file and then display a sliding-piece puzzle based on that image.Components in the main frame:a.) button for "Exit"b.) button for "New image"c.) button...

1 answer below »
The assignment is on the file.


Write a program which will load an image file and then display a sliding-piece puzzle based on that image. Components in the main frame: a.) button for "Exit" b.) button for "New image" c.) button for "Play/Pause" b.) JPanel for displaying the puzzle c.) Label showing elapsed play time d.) Label showing number of moves e.) Label showing the number of pieces still not in the correct place Public Static Constant: The number of rows (which will also be the number of columns) Your JErame constructor should build the GUI and set up listeners. e user to select an image file. That se a JFileChooser to appear to allow th the buttons that make up the puzzle. The "New image" button should cau hich are used when constructing image should be cropped into the pieces W This smart button should know where it 1S, n representing one piece of the puzzle. how to swap its Image with the image on Create a subclass of JButto laying is the correct image, and knows know if the image it is disp another smart button. p the timing, and when in "Pause" mode should hide the puzzle by The Play/Pause button should start/sto displaying the original image. " the puzzle pieces, be able to know if the puzzle is h a way that the puzzle is still solvable. The image should be scrambled in suc s the first move, suspended when in the "pause" mode, and stopped Timing should begin when the user make when the puzzle 1s solved. rmation will be given in class. More info
Answered 1 days AfterNov 13, 2022

Answer To: Write a program which will load an image file and then display a sliding-piece puzzle based on that...

Banasree answered on Nov 15 2022
42 Votes
public class Main {
public static void main(String[] args){
new Puzzle();
}
}
impo
rt java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Puzzle extends JFrame implements ActionListener{
}
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,shuffle;
int counter = 0;
JLabel counterLabel;
Puzzle(){
setSize(400,400);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1 = new JButton("1");
b2 = new JButton(" ");
b3 = new JButton("3");
b4 = new JButton("4");
b5 = new JButton("5");
b6 = new JButton("6");
b7 = new JButton("7");
b8 = new JButton("8");
b9 = new JButton("2");
shuffle = new JButton("Shuffle!");
counterLabel = new JLabel("Clicks: 0");
add(b1);add(b2);add(b3);add(b4);add(b5);add(b6);add(b7);add(b8);add(b9); add(shuffle);
Container contentPane =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here