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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:38:12+00:00 2026-06-03T19:38:12+00:00

I am trying to make a button move to another place, i used this

  • 0

I am trying to make a button move to another place, i used this code:

public void actionPerformed(ActionEvent e)
{
    for(int i = 0; i<=29; i++)
    {
        if(e.getSource() == gB[i])
        {
            System.out.println(i);
        }
    }
}

and this is draw board

public void drawBoard()
{
    JPanel gboard = new JPanel();

    for(int i = 0; i < 30; i++)
    {
        gboard.add(gB[i]);
        gB[i].setText(Integer.toString(gB[i].getPieceValue()));

    }

which I think is wrong. Anyone have any idea? I’m not able to get the players moving to the next position.

Thanks

the error is: (all in RED)

 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Controller.actionPerformed(Controller.java:22)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
  • 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-03T19:38:13+00:00Added an answer on June 3, 2026 at 7:38 pm
    public void actionPerformed(ActionEvent e)
    {
        for(int i = 0; i<=29; i++)
        {
            if(e.getSource() == gB[i])
            {
                System.out.println(i);
            }
        }
    }
    

    has only a few names which could hold a value. The ActionEvent named “e” and the array named “gB” are the only names which could be set to null.

    That means either you threw a custom ActionEvent without defining a source, or you didn’t initalize the array gB.

    If you wanted your piece to move, it would probably also help to do more than printout the value of “i” in the action handler; but, I’m guessing you haven’t made it that far in your effort yet.

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

Sidebar

Related Questions

public void MoveMyButton (int x) //where the button suppose to move to { TranslateAnimation
I am trying to make a form move (using the titlebar) from a button
I am trying to make a button to add another input box every time
I am trying to make a UIImageView move when I tap a button. I
I'm trying to move the button under the textarea from js-code. But I can't
I am trying to make this button disable the two other buttons and execute
I'm trying to make a button which glows when the mouse is pointed over
Trying to make a toggle button that hides/shows the right window/pane. Here is a
I'm trying to make a picture button in the compact framework. I made a
Im trying to make it so that on a press of a image button

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.