Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:37:38+00:00 2026-06-13T06:37:38+00:00

Now I need to write a 8-puzzle game, which looks [like this] The instructor

  • 0

Now I need to write a 8-puzzle game, which looks [like this]

enter image description here

The instructor asked us to write three different classes, which are Piece.java, EightPuzzle.java, and EightPuzzlePanel.java.
As you can see,
Piece.java represents each individual piece like “1”, “2” in this eight puzzle board;
EightPuzzle.java represents the the game board to hold these 9 pieces/buttons.
EightPuzzlePanel.java is the GUI stuff.

So my question is, since we need to create a Piece[][] piece = new Piece[][], a 2D array, and we also need to arrange these piece on the board. I thought I could create 9 JButtons and put the 2D array in link with the 9 JButtons (or there have a better way to sort the 2D-array), but I don’t know how to do that.

Also the buttons need to be controlled by both mouse and keyboard. This is another challenge for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:37:39+00:00Added an answer on June 13, 2026 at 6:37 am

    Since this is homework I will not go into much detail, but this is how I would go about it:

    1. Make Piece extends the JButton class. The Piece object takes the text to display and also the location of the image you would like it to render. You should be able to find plenty of examples online on how to add an image to a JButton.
    2. Make EightPuzzle extend the JPanel class and also use the Grid Layout to render the Pieces neatly in a grid. This class takes on a 2D array of Piece objects which it will then render.
    3. Make EightPuzzlePanel also extend the JPanel class. This class takes in another JPanel (EightPuzzle) and appends any other buttons you might need.
    4. Finally create a Main class which extends JFrame and then I append the EightPuzzlePanel to it (which should in turn contain the other panel with the other buttons).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some complicated, problem to be solved. Now I need to write such
Until now I've been only writing console applications but I need to write a
I have this regex working but now need to allow numbers without the decimal
I have a cluster of 500 linux boxes which now need to use the
I've used antlr and javacc/freecc for a while. Now I need to write a
I'm working on a puzzle right now....trying to write if (x==5 || x==7) With
I have created a project and it works fine. Now I need to write
Usually I develop in Java but now I need to write an app that
I'm working in a framework that uses commons-fileupload. Now I need to write unit
I have some code that produces an infinite loop. Now I need to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.