Posted December 12, 20168 yr Pretty explanatory. i have a GUI with a text field and a button. For testing purpose i made that when i press the button the text in the text box is displayed in eclipse. But instead of being displayed one time is displayed multiple times, like i press multiple times the button. This is the code for the GUI i'm using package com.forgeguard.gui; import java.io.IOException; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.forgeguard.capabilities.IRegionCapabilities; import com.forgeguard.capabilities.RegionCapabilitiesProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; public class GuiRegion extends GuiScreen{ private static final ResourceLocation BG = new ResourceLocation("textures/gui/demo_background.png"); private GuiTextField textField; private GuiButton button; public void updateScreen() { this.textField.updateCursorCounter(); } @Override public void initGui() { int xPos = width / 2 - 120; int yPos = height / 2 - 87; this.textField = new GuiTextField(2, this.fontRendererObj, xPos + 5, yPos + 100, 238, 20); this.textField.setMaxStringLength(32500); this.textField.setFocused(true); this.button = new GuiButton(0, xPos + 20, yPos + 140, "Save Region"); } @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { if(keyCode == Keyboard.KEY_ESCAPE) { this.mc.displayGuiScreen(null); if(this.mc.currentScreen == null) this.mc.setIngameFocus(); } this.textField.textboxKeyTyped(typedChar, keyCode); } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.mc.getTextureManager().bindTexture(this.BG); int xPos = width / 2 - 120; int yPos = height / 2 - 87; this.drawTexturedModalRect(xPos, yPos, 0, 0, 256, 256); BlockPos pos1; BlockPos pos2; IRegionCapabilities capabilities = Minecraft.getMinecraft().thePlayer.getHeldItemMainhand() .getCapability(RegionCapabilitiesProvider.REGION_CAPABILITIES, null); if (capabilities != null) { this.fontRendererObj.drawString("First Point: ", xPos + 5, yPos + 18, 4210752); this.fontRendererObj.drawString("Second Point: ", xPos + 5, yPos + 38, 4210752); if(capabilities.getFirstPoint() != null) { this.fontRendererObj.drawString("" + capabilities.getFirstPoint().getX(), xPos + 80, yPos + 18, 4210752); this.fontRendererObj.drawString("" + capabilities.getFirstPoint().getY(), xPos + 120, yPos + 18, 4210752); this.fontRendererObj.drawString("" + capabilities.getFirstPoint().getZ(), xPos + 160, yPos + 18, 4210752); } if(capabilities.getSecondPoint() != null) { this.fontRendererObj.drawString("" + capabilities.getSecondPoint().getX(), xPos + 80, yPos + 38, 4210752); this.fontRendererObj.drawString("" + capabilities.getSecondPoint().getY(), xPos + 120, yPos + 38, 4210752); this.fontRendererObj.drawString("" + capabilities.getSecondPoint().getZ(), xPos + 160, yPos + 38, 4210752); } } this.textField.drawTextBox(); this.addButton(this.button); super.drawScreen(mouseX, mouseY, partialTicks); } @Override protected void actionPerformed(GuiButton button) throws IOException { if(button == this.button) { System.out.println(this.textField.getText()); } } } And in eclipse this is displayed (assuming that i write the word text in the text box in the gui) [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text [23:54:20] [Client thread/INFO] [sTDOUT]: [com.forgeguard.gui.GuiRegion:actionPerformed:91]: text Why this happens? Thank you for your help Don't blame me if i always ask for your help. I just want to learn to be better
December 13, 20168 yr It could be since the Drawing can happen many times, there are actually more than just 1 button drawn in that location. Since you just use this.addButton(this.button); I prefer in my render to just use: this.buttonList.clear(); this.buttonList.add(new GuiPlayerStatsButton(CLASS_BACK, x1, y1, "", 0)); //Custom Button That way the list is cleaned, then I just add the buttons whenever the GUI is drawn Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
December 13, 20168 yr Or not remove the buttons from the screen and readd them all the time, and instead do it once, during initGui... https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/industry/client/gui/GuiContainerFilter.java#L48-L49 Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 13, 20168 yr Author Yes the fix was to add the button into the initGui method, dumb me Thank you for your help Don't blame me if i always ask for your help. I just want to learn to be better
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.