Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am stuck finishing my puzzle. All I have left to do isAllow input either from

ID: 3653762 • Letter: I

Question

I am stuck finishing my puzzle. All I have left to do isAllow input either from a file or from the console.If the user provides a filename as a parameter on the command line then read the input from the file otherwise read the input from the console.In order to give the input from a file that is named infoo.txt the user will type the following on the command lineC:> java puzzle infoo.txt also must be able to write to text outfoo.text if user entersC:> java puzzle infoo.txt outfoo.textMake sure that you validate the puzzle input appropriately. For invalid puzzle entry display the message

Explanation / Answer

Main program // SlidePuzzle.java - Puzzle to slide pieces to correct position. // Fred Swartz, 2003-May, 2004-May // The SlidePuzzle program consists of three files: // SlidePuzzle.java - this file with main to create window. // SlidePuzzleGUI.java - implements the GUI interface. // SlidePuzzleModel.java - the logical functioning. import javax.swing.JFrame; ///////////////////////////////////////////// class SlidePuzzle class SlidePuzzle { //============================================= method main public static void main(String[] args) { JFrame window = new JFrame("Slide Puzzle"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setContentPane(new SlidePuzzleGUI()); window.pack(); // finalize layout window.show(); // make window visible window.setResizable(false); }//end main }//endclass SlidePuzzle Graphical User Interface // SlidePuzzleGUI.java - GUI for SlidePuzzle // Fred Swartz, 2003-May-10, 2004-May-3 // // The SlidePuzzleGUI class creates a panel which // contains two subpanels. // 1. In the north is a subpanel for controls (just a button now). // 2. In the center a graphics // This needs a few improvements. // Both the GUI and Model define the number or rows and columns. // How would you set both from one place? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; /////////////////////////////////////////////////// class SlidePuzzleGUI // This class contains all the parts of the GUI interface class SlidePuzzleGUI extends JPanel { //=============================================== instance variables private GraphicsPanel _puzzleGraphics; private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel(); //end instance variables //====================================================== constructor public SlidePuzzleGUI() { //--- Create a button. Add a listener to it. JButton newGameButton = new JButton("New Game"); newGameButton.addActionListener(new NewGameAction()); //--- Create control panel JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); controlPanel.add(newGameButton); //--- Create graphics panel _puzzleGraphics = new GraphicsPanel(); //--- Set the layout and add the components this.setLayout(new BorderLayout()); this.add(controlPanel, BorderLayout.NORTH); this.add(_puzzleGraphics, BorderLayout.CENTER); }//end constructor //////////////////////////////////////////////// class GraphicsPanel // This is defined inside the outer class so that // it can use the outer class instance variables. class GraphicsPanel extends JPanel implements MouseListener { private static final int ROWS = 3; private static final int COLS = 3; private static final int CELL_SIZE = 80; // Pixels private Font _biggerFont; //================================================== constructor public GraphicsPanel() { _biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2); this.setPreferredSize( new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS)); this.setBackground(Color.black); this.addMouseListener(this); // Listen own mouse events. }//end constructor //=======================================x method paintComponent public void paintComponent(Graphics g) { super.paintComponent(g); for (int r=0; r
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote