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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:10:55+00:00 2026-05-16T09:10:55+00:00

i really need you guys your help. I have to do animation on a

  • 0

i really need you guys your help. I have to do animation on a 3 X 3 grid of images.

My questions are :

1)
How do i construct the 3 X 3 grid with the images.?

This is what i did but is not working because because i get nullpointerException in this line : rail[x][y] = new JLabel(icon);

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ButtonGrid {

    JFrame frame=new JFrame(); //creates frame

    JButton[][] grid; //names the grid of buttons
    JLabel[][] rail = null;

    public ButtonGrid(int width, int length){ //constructor with 2 parameters
            frame.setLayout(new GridLayout(width,length)); //set layout of frame
            grid=new JButton[width][length]; //allocate the size of grid
            for(int y=0; y<length; y++){ 
                    for(int x=0; x<width; x++){
                            //grid[x][y]=new JButton("("+x+","+y+")");   
                            //frame.add(grid[x][y]); //adds button to grid
                        ImageIcon icon = createImageIcon("images/crossingsHorizontal.JPG", "");
                        //JLabel lab = new JLabel(icon);
                        rail[x][y] = new JLabel(icon);
                        frame. add(rail[x][y]);
                    }
            }
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
            frame.pack(); 
            frame.setVisible(true);
    }

     public static ImageIcon createImageIcon(String path,String description) {
            java.net.URL imgURL = ButtonGrid.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL, description);
            } else {

                return null;
            }
    }


    public static void main(String[] args) {
        new ButtonGrid(3,3);//makes new ButtonGrid with 2 parameters
}


}

2)
How can i use this grid as a background for my animation?

3)
I have to rotate the the image in grid [2][2], how can i access this image alone and rotate it? I know how to do the rotation so tell me how to get the element [2][2] so that i can rotate it.

thanks for your 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-16T09:10:56+00:00Added an answer on May 16, 2026 at 9:10 am

    This line is wrong with Swing:

    frame.setLayout(new GridLayout(width,length))
    

    As I remember, we should apply layouts to panels, i.e.

    frame.getContentPane().setLayout (new GridLayout(width,length));
    

    This line is wrong as well:

    frame.add(rail[x][y]);
    

    the solution is the same: use contentPane.

    Some basics could be found at JFrame javadocs page.

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

Sidebar

Related Questions

I've some questions .. and I really need your help. I have an application.
hy guys, i really need your help. i've succesfully connected to ftp server via
guys i really REALLY need some help on this one. 2 days i've been
I really need help with interfaces in general... Any resources that you guys would
I really need your help in my issue very quickly and it's too close
I'm not a beginner at C# but I really need to increase my understanding,
Hi guys I know that this is really bad idea but I want join
Need help badly guys, I have three tables tbl_questions, tbl_answers and tbl_link_qa tbl_questions is
Hey guys, I am really messing up with this. I tried this but it
I have decided that I really need to get some flowcharts for reverse engineering

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.