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

  • Home
  • SEARCH
  • 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 828135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:40:55+00:00 2026-05-15T03:40:55+00:00

I understand that the title might not be descriptive enough, but I’m making a

  • 0

I understand that the title might not be descriptive enough, but I’m making a magic square game in Java and basically, I’m trying to replicate user input as found in the sudoku game here: http://www.websudoku.com/.

What I have is a n x n grid of Buttons (not JButton) as the board and what I want the user to be able to do is when the user clicks on one of the buttons, similar to the game above, it allows the user to type in his guess in the button itself instead of popping up a dialog box with an input field of some sort.

I don’t know where to start, I am a beginner in Java (not very beginner, but my knowledge with the various Java APIs is very limited), so I’m trying to find out if this would be possible and if it is, how would I go about doing it? Thanks for any help.


I didn’t know if this belonged in comments or answers, but I am posting this as an extension to the previous question. Thank you, both of you, for your help.

I have basically achieved what I set out to do with the program. But now, I want to make it better by having it operate in a multithreaded way. Do any of you have any suggestions as to what aspect of such a magic square program could be delegated to separate threads.

As of now, what the program does is this: prompt the user for the square size > build n x n grid and when user clicks a start button, it starts timing the user. while the user inputs a new entry, the board constantly updates the totals on each row, column and diagonal and updates the appropriate boxes. Finally, when the check for a successful magic square board turns out true, it disables all the textfields and lets the user start a new game or exit.

Once again, while I have programmed in Java for a while, my knowledge is very limited and right now, I want to understand how simple programs like these, while they work well on a single thread, can be built in a multithreaded way.

Lastly, I was checking the Memory used when I run my program (basically looking through task manager in windows, under javaw.exe) and for a grid of 19 x 19, it says about 19000K. Is this too much or about right and if its too much, how can I reduce it?

Thank you greatly for any help.

  • 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-05-15T03:40:56+00:00Added an answer on May 15, 2026 at 3:40 am

    I would avoid this gui design, since it will not work as the user expects it to. However, if you really want the behavior, I suggest you start with a JTextField and give it a BevelBorder. Something like this:

    JTextField tf = new JTextField();
    tf.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    yourPanel.add(tf);
    

    A complete stub program could look something like this:

    import java.awt.*;
    
    import javax.swing.*;
    import javax.swing.border.*;
    
    public class FrameTest {
        public static void main(String[] args) throws InterruptedException {
    
            JFrame jf = new JFrame("Demo");
            jf.getContentPane().setLayout(new GridLayout(9, 9, 3, 3));    
    
            for (int i = 0; i < 9*9; i++) {
                JTextField tf = new JTextField(1);
                tf.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
                tf.setBackground(new Color(230, 230, 230));
                tf.setHorizontalAlignment(JTextField.CENTER);
                tf.setFont(tf.getFont().deriveFont(20f));
                jf.add(tf);
            }
    
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            jf.pack();
            jf.setVisible(true);
    
        }
    }
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.