Jump to content

[SOLVED]Double Clicking in GUI


Raizunne

Recommended Posts

I'm making a book for my mod. At first when you open the book you are presented with an index, after that another index with a more specific list of items or blocks. The problem is that when I click in one of the menus, it instantly clicks on the second menu that is on the same coordinate.

 

Here's a gfy explaining my interface and my problem

 

Basicly, what I want is index > subindex > item/block entry

And its going index >item/block entry

 

If my code for my GUI is needed, here it is:GitHub

// Code is messy, just started getting into Java

Link to comment
Share on other sites

Simply by override the GuiScreen#mouseClicked(int x, int y, int mouseId) like this:

@Override
/**
@param x = relative mouse position x
@param y = relative mouse position y
@param mouseId = mouse button being pressed
*/
protected void mouseClicked(int x, int y, int mouseId) {
	super.mouseClicked(x, y, mouseId);
	this.initGui();
}

 

Do not call the initGui method during the actionPerformed method because when the mouse is pressed on top of a GuiButton it goes into a loop. When you draw a new button on the same location and the mouse is not released, it continues the loop (the code gets executed immediately so you can never time it when to release your mouse . So when the mouseClicked is done (super call), you re initialize your gui elements.

 

There is no double clicking involved, just fast execution. ;]

 

Note, when writing in Java you should rename the button classes to start with a capital letter.

http://journals.ecs.soton.ac.uk/java/tutorial/java/javaOO/classdecl.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.