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 796677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:40:38+00:00 2026-05-14T22:40:38+00:00

I have task to prepare two windows with swing. One contains grid of squares,

  • 0

I have task to prepare two windows with swing. One contains grid of squares, with random numbers in them. In second I need to load pieces of tiled image and then show them in the correct order, forming tiled image.

Windows should look like this :

alt text http://img535.imageshack.us/img535/3129/lab8a.jpg

Okay so how to bite this? I’ve used swing only few times to draw some 2d polylines, so basically I just theoretically now what to do.

Ok, so window number 1:
I start with creating Jframe for the window. Then I do for loop and in it create 16 JLabels with random numbers in them? How to set margins between each tile and the whole window?

Window number 2:
So I start the same, but instead of loading numbers I add images? Now, how can I load image from file and then set it as background?

  • 1 1 Answer
  • 2 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-14T22:40:38+00:00Added an answer on May 14, 2026 at 10:40 pm

    The following code lays out the JLabels using the GridLayout. The arguments to the GridLayout are the following: rows, cols, horizontal gap, vertical gap. In the example below I have 3 pixels wide gap between labels both vertically and horizontally.

    To use images instead of numbers, you could pass an ImageIcon to the constructor of the JLabel instead of the text.

    However, it looks like your doing a game where the user should be able to click on the tiles. This suggests that you perhaps should use buttons instead of labels, but it’s up to you 🙂

    import java.awt.GridLayout;
    
    import javax.swing.*;
    import javax.swing.border.BevelBorder;
    
    
    public class FrameTest {
    
        public static void main(String[] args) {
            final JFrame f = new JFrame("Frame Test");
    
            JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3));
    
            for (int i = 0; i < 16; i++) {
                JLabel l = new JLabel("" + i, JLabel.CENTER);
                //JLabel l = new JLabel(new ImageIcon("image_file.png"), JLabel.CENTER);
                l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
                l.setFont(l.getFont().deriveFont(20f));
                panel.add(l);
            }
    
            f.setContentPane(panel);
            f.setSize(200, 200);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.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

I have a task to do, I need to take data that has been
I have a task that runs periodically 10 second. I do some picturebox refreshing
I'm stuck with a rake task that need to prepare a newsletter for Mailchimp.
I have a task to prepare application running on iOs and Android. Application will
i have task which takes a parameter and has three modes of results Example
I have task involving reading SAS .xpt files using .NET. For that I'm using
I'm using dhtmlx Gantt Chart UI component which have task list and graphical chart.
I am new this sharepoint development and i have task in hand to do
I have some task regarding do operations on database using ADODB in Vb.NET. Can
I have a task to develop an electronic phone book in which i have

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.