Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: Help with GUI

  1. #1

    Default Help with GUI

    I need help with my gui. I have made a main screen which gives the player options to go to a options screen. When I go on the options screen and select the back button and then ty to go back in the options gui it doesnt work. Here is my eclipse project Pong Project Files (TO COMPILE).zip

    And my Game.java (also included, but i think the problem originates here)
    package net.nivangerow.pong;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    public class Game extends JPanel implements ActionListener{
    	Timer time;
    	public Bat b3;
    	public BatR b4;
    	public Ball ball;
    	Image sccl;
    	Image logo;
    	int scoreL,scoreR;
    	boolean pause=true;
    	public Gui gui;
    	boolean ai=false;
    	Thread aiThread;
    	int aiIntelligence = 8;
    	public GuiPause guipause;
    	public GuiOp guiop;
    	public GuiError guierror;
    	public Game()
    	{
    		b3=new Bat();
    		b4=new BatR();
    		ball=new Ball();
    		setVisible(true);
    		setSize(640, 480);
    		setBackground(Color.BLACK);
    		setFocusable(true);
    		time = new Timer(5, this);
    		time.start();
    		addKeyListener(new AL());
    		scoreL=scoreR=0;
    		ImageIcon i = new ImageIcon(getClass().getResource("sccl.png"));
    		sccl=i.getImage();
    		ImageIcon logo2 = new ImageIcon(getClass().getResource("logo.png"));
    		logo = logo2.getImage();
    		gui = new Gui();
    		guipause=new GuiPause();
    		guiop=new GuiOp();
    		guierror=new GuiError();
    		aiThread = new Thread(new AI(), "aiThread");
    	}
    	public void actionPerformed(ActionEvent e)
    	{
    		if(!pause)
    		{
    			if(ball.x>630&&ball.px==+1){ball.px=-1; scoreR++;}
    			if(ball.x<0&&ball.px==-1){ball.px=+1; scoreL++;}
    			if(ball.y>450&&ball.py==+1)ball.py=-1;
    			if(ball.y<0&&ball.py==-1)ball.py=+1;
    			b3.move();
    			b4.move();
    			ball.move();
    			checkCollisions();
    		}
    		if(ai)
    		{
    			b3.move();
     
    		}
    		repaint();
    	}
    	public void aiInit()
    	{
    		int target=aiGo()-100/2;
    		if(target >= 480 - 100){target = 480 - 100;}
    		if(b3.y > target + 1){b3.y -= 1;}
    		if(b3.y < target - 1){b3.y += 1;}
    	}
    	public int aiGo(){
    			int tmpx = ball.x;
    			int tmpy = ball.y;
    			if(ball.px> 0){return (480)/2-15;}
    		return(tmpy);	
    	}
     
    	public void checkCollisions()
    	{
    		Rectangle ballC = ball.getBounds();
    		Rectangle b3C = b3.getBounds();
    		Rectangle b4C = b4.getBounds();
    		if(ballC.intersects(b3C))
    		{
    			ball.x=10;
    			ball.px=+1;
    		}
    		if(ballC.intersects(b4C))
    		{
    			ball.x=620;
    			ball.px=-1;
    		}
    	}
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		Graphics2D g2d = (Graphics2D)g;
    		g2d.drawImage(sccl, 320, 0, null);
    		Font fontL = new Font("Arial", Font.PLAIN, 30);
    		g2d.setFont(fontL);
    		g2d.setColor(Color.WHITE);
    		g2d.drawString(scoreR+"																				"+scoreL, 215, 100);
    		if(scoreL>=9){g2d.setColor(Color.RED); g2d.drawString("The right side has won!", 160, 200); pause=true; aiThread.stop();}
    		if(scoreR>=9){g2d.setColor(Color.RED); g2d.drawString("The left side has won!", 160, 200); pause=true; aiThread.stop();}
    		g2d.drawImage(b3.bat, 0, b3.y, null);
    		g2d.drawImage(b4.bat, 630, b4.y, null);
    		g2d.drawImage(ball.ball, ball.x, ball.y, null);
    		if(gui.visible){
    			g2d.drawImage(gui.background, 0, 0, null);
    			g2d.drawImage(ball.ball, 200, gui.y, null);
    			g2d.drawImage(logo, 120, 10, null);
    			g2d.drawString("1 Player",260, 215);
    			g2d.drawString("2 Player",260, 315);
    			g2d.drawString("Options",260, 415);
    		}
    		if(guipause.visible&&pause){
    			g2d.drawImage(gui.background, 0, 0, null);
    			g2d.drawImage(ball.ball, 200, guipause.y, null);
    			g2d.drawString("GAME PAUSED",210, 115);
    			g2d.drawString("Continue",254, 215);
    			g2d.drawString("Abort Game",250, 315);
    		}
    		if(guiop.visible&&pause){
    			g2d.drawImage(gui.background, 0, 0, null);
    			g2d.drawImage(ball.ball, 200, guiop.y, null);
    			g2d.drawString("GAME OPTIONS",210, 115);
    			g2d.drawString("AI intelligence: A < "+aiIntelligence+" > D",220, 215);
    			g2d.drawString("Back",285, 315);
    		}
    		if(guierror.visible&&pause){
    			gui.visible=false;
    			guiop.visible=false;
    			guipause.visible=false;
    			g2d.drawImage(gui.background, 0, 0, null);
    			g2d.drawString("FATAL AI ERROR",210, 115);
    			g2d.drawString("A fatal error occoured with the AI!",110, 215);
    			g2d.drawString("Setting the AI intelligence under 8",110, 265);
    			g2d.drawString("can cause crashes. Please restart game.",50, 315);
    		}
    	}
    	public class AL extends KeyAdapter
    	{
    		public void keyPressed(KeyEvent e)
    		{
    			int key = e.getKeyCode();
    			if(!pause){
    				if(key==KeyEvent.VK_W&&!ai)
    				{
    					b3.py=-1;
    				}
    				if(key==KeyEvent.VK_S&&!ai)
    				{
    					b3.py=+1;
    				}
    				if(key==KeyEvent.VK_I)
    				{
    					b4.py=-1;
    				}
    				if(key==KeyEvent.VK_K)
    				{
    					b4.py=+1;
    				}
    			}
    			if(gui.visible&&pause)
    			{
    				if(key==KeyEvent.VK_W)
    				{
    					gui.y-=100;
    					if(gui.y<=200)gui.y=200;
    				}
    				if(key==KeyEvent.VK_S)
    				{
    					gui.y+=100;
    					if(gui.y>=400)gui.y=400;
    				}
    				if(key==KeyEvent.VK_ENTER)
    				{
    					if(gui.y==200)
    					{
    						gui.visible=false;
    						ai=true;
    						pause=false;
    						aiThread.start();
    					}
    					if(gui.y==300)
    					{
    						ai=false;
    						gui.visible=false;
    						pause=false;
    					}
    					if(gui.y==400)
    					{
    						//WHY DOES THIS ONLY WORK ONCE?
    						gui.visible=false;
    						guiop.visible=true;
    					}
    				}
    			}
    			if(guipause.visible&&pause)
    			{
    				if(key==KeyEvent.VK_W)
    				{
    					guipause.y-=100;
    					if(guipause.y<=200)guipause.y=200;
    				}
    				if(key==KeyEvent.VK_S)
    				{
    					guipause.y+=100;
    					if(guipause.y>=300)guipause.y=300;
    				}
    				if(key==KeyEvent.VK_ENTER)
    				{
    					if(guipause.y==200)
    					{
    						aiIntelligence = tempaiIntelligence;
    						pause=false;
    						guipause.visible=false;
    					}
    					if(guipause.y==300)
    					{
    						aiIntelligence = tempaiIntelligence;
    						pause=true;
    						guipause.visible=false;
    						gui.visible=true;
    						ball.x=ball.y=100;
    						ball.py=+1;
    						ball.px=+1;
    						b3.y=b4.y=180;
    						scoreL=scoreR=0;
    					}
    				}
    			}
    			if(guiop.visible&&pause)
    			{
    				if(key==KeyEvent.VK_W)
    				{
    					guiop.y-=100;
    					if(guiop.y<=200)guiop.y=200;
    				}
    				if(key==KeyEvent.VK_S)
    				{
    					guiop.y+=100;
    					if(guiop.y>=300)guiop.y=300;
    				}
    				if(guiop.y==200)
    				{
    					if(key==KeyEvent.VK_A)aiIntelligence--;
    					if(key==KeyEvent.VK_D)aiIntelligence++;
    				}
    				if(key==KeyEvent.VK_ENTER)
    				{
    					if(guiop.y==300)
    					{
    						guiop.visible=false;
    						gui.visible=true;
    					}
    				}
    			}
    			if(key==KeyEvent.VK_ESCAPE&&!pause&&gui.visible==false)
    			{
    				tempaiIntelligence = aiIntelligence;
    				aiIntelligence = 1000;
    				pause=true;
    				guipause.visible=true;
    			}
    		}
    		int tempaiIntelligence;
    		public void keyReleased(KeyEvent e)
    		{
    			int key = e.getKeyCode();
    			if(!pause){
    				if(key==KeyEvent.VK_W&&!ai)
    				{
    					b3.py=0;
    				}
    				if(key==KeyEvent.VK_S&&!ai)
    				{
    					b3.py=0;
    				}
    				if(key==KeyEvent.VK_I)
    				{
    					b4.py=0;
    				}
    				if(key==KeyEvent.VK_K)
    				{
    					b4.py=0;
    				}
    			}
    		}
    	}
    	public class AI extends Thread {
    		AI(){}
    		AI(String threadName) {
    			super(threadName);
    			System.out.println(this);
    			start();
    		}
    		public void run() {
    			try{
    				if(ai)aiInit();
    				aiThread.currentThread().sleep(aiIntelligence);
    				run();
    			}catch(StackOverflowError ex){guierror.visible=true; pause=true;} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }

    Thanks in advance.
    Last edited by nivangerow; September 6th, 2011 at 10:14 AM.


  2. #2

    Default Re: Help with GUI

    Can somebody help me? please?

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    You shouldn't bump your thread like that. It looks impatient- there are hundreds of posts here each with its own urgent user, and bumping your thread after only 20 minutes makes it look like you think your time is more important than theirs, which is pretty rude. Also, bumping your thread makes it look like your question has received a reply, so people will think you're already getting help and will not look at your question at all. So bumping your thread actually decreases your chances of getting help!

    I recommend you check out the link in my signature on asking questions the smart way.

    That being said, I also recommend you post an SSCCE (which I've asked you to do before). You've posted way too much code, which isn't even runnable. If you're that impatient to get help, I would think you'd want to make it as easy as possible for us to help you? Post an SSCCE and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4

    Default Re: Help with GUI

    It is runnable, you need to download my workspace (in the OP)

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Quote Originally Posted by nivangerow View Post
    It is runnable, you need to download my workspace (in the OP)
    SSCCE stands for Short, Self-Contained, Compilable Example. What you posted is none of them.

    When you post code, it should be as short as possible while still showing the behavior, and we should be able to copy and paste it into our own editors to check it out. We shouldn't have to download anything, or write anything, or add any import statements.

    If you don't do the bare minimum of boiling your code down to an SSCCE, then don't be impatient when it takes longer than twenty minutes for somebody to help you. If you post an SSCCE, I'll look at it now. Otherwise, you have to wait for somebody with more patience to come along. Up to you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6

    Default Re: Help with GUI

    K im working on it.

  7. #7

    Default Re: Help with GUI

    Right Here is my SSCCE:

    Pong.java:

    package net.nivangerow.pong;
    import javax.swing.*;
    import java.awt.*;
    public class Pong {
    	public static void main(String[] args)
    	{
    		JFrame frame = new JFrame("Pong SSCCE");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    		frame.setResizable(false);
    		frame.setSize(640, 480);
    		frame.add(new Game());
    	}
    }

    Game.java

    package net.nivangerow.pong;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    public class Game extends JPanel implements ActionListener{
    	Timer time;
     
    	boolean pause=true;
    	public Gui gui;
    	boolean ai=false;
     
    	int aiIntelligence = 8;
    	public GuiPause guipause;
    	public GuiOp guiop;
    	public GuiError guierror;
    	public Game()
    	{
    		setVisible(true);
    		setSize(640, 480);
    		setBackground(Color.BLACK);
    		setFocusable(true);
    		time = new Timer(5, this);
    		time.start();
    		addKeyListener(new AL());
    		gui = new Gui();
    		guipause=new GuiPause();
    		guiop=new GuiOp();
    		guierror=new GuiError();
    	}
    	public void actionPerformed(ActionEvent e)
    	{
     
    		repaint();
    	}
     
     
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		Graphics2D g2d = (Graphics2D)g;
     
    		Font fontL = new Font("Arial", Font.PLAIN, 30);
    		g2d.setFont(fontL);
    		g2d.setColor(Color.WHITE);
     
    		if(gui.visible){
     
    			g2d.drawString("1 Player",260, 215);
    			g2d.drawString("2 Player",260, 315);
    			g2d.drawString("Options",260, 415);
    			g2d.drawRect(200, gui.y, 10, 10);
    		}
    		if(guipause.visible&&pause){
     
    			g2d.drawString("GAME PAUSED",210, 115);
    			g2d.drawString("Continue",254, 215);
    			g2d.drawString("Abort Game",250, 315);
    			g2d.drawRect(200, guipause.y, 10, 10);
    		}
    		if(guiop.visible&&pause){
     
    			g2d.drawString("GAME OPTIONS",210, 115);
    			g2d.drawString("AI intelligence: A < "+aiIntelligence+" > D",220, 215);
    			g2d.drawString("Back",285, 315);
    			g2d.drawRect(200, guiop.y, 10, 10);
    		}
    		if(guierror.visible&&pause){
    			gui.visible=false;
    			guiop.visible=false;
    			guipause.visible=false;
     
    			g2d.drawString("FATAL AI ERROR",210, 115);
    			g2d.drawString("A fatal error occoured with the AI!",110, 215);
    			g2d.drawString("Setting the AI intelligence under 8",110, 265);
    			g2d.drawString("can cause crashes. Please restart game.",50, 315);
    		}
    	}
    	public class AL extends KeyAdapter
    	{
    		public void keyPressed(KeyEvent e)
    		{
    			int key = e.getKeyCode();
    			if(!pause){
     
    			}
    			if(gui.visible&&pause)
    			{
    				if(key==KeyEvent.VK_W)
    				{
    					gui.y-=100;
    					if(gui.y<=200)gui.y=200;
    				}
    				if(key==KeyEvent.VK_S)
    				{
    					gui.y+=100;
    					if(gui.y>=400)gui.y=400;
    				}
    				if(key==KeyEvent.VK_ENTER)
    				{
    					if(gui.y==200)
    					{
    						gui.visible=false;
    						ai=true;
    						pause=false;
    					}
    					if(gui.y==300)
    					{
    						ai=false;
    						gui.visible=false;
    						pause=false;
    					}
    					if(gui.y==400)
    					{
    						//WHY DOES THIS ONLY WORK ONCE?
    						gui.visible=false;
    						guiop.visible=true;
    					}
    				}
    			}
    			if(guipause.visible&&pause)
    			{
    				if(key==KeyEvent.VK_W)
    				{
    					guipause.y-=100;
    					if(guipause.y<=200)guipause.y=200;
    				}
    				if(key==KeyEvent.VK_S)
    				{
    					guipause.y+=100;
    					if(guipause.y>=300)guipause.y=300;
    				}
    				if(key==KeyEvent.VK_ENTER)
    				{
    					if(guipause.y==200)
    					{
    						aiIntelligence = tempaiIntelligence;
    						pause=false;
    						guipause.visible=false;
    					}
    					if(guipause.y==300)
    					{
    						aiIntelligence = tempaiIntelligence;
    						pause=true;
    						guipause.visible=false;
    						gui.visible=true;
     
    					}
    				}
    			}
    			if(guiop.visible&&pause)
    			{
    				if(key==KeyEvent.VK_W)
    				{
    					guiop.y-=100;
    					if(guiop.y<=200)guiop.y=200;
    				}
    				if(key==KeyEvent.VK_S)
    				{
    					guiop.y+=100;
    					if(guiop.y>=300)guiop.y=300;
    				}
    				if(guiop.y==200)
    				{
    					if(key==KeyEvent.VK_A)aiIntelligence--;
    					if(key==KeyEvent.VK_D)aiIntelligence++;
    				}
    				if(key==KeyEvent.VK_ENTER)
    				{
    					if(guiop.y==300)
    					{
    						guiop.visible=false;
    						gui.visible=true;
    					}
    				}
    			}
    			if(key==KeyEvent.VK_ESCAPE&&!pause&&gui.visible==false)
    			{
    				tempaiIntelligence = aiIntelligence;
    				aiIntelligence = 1000;
    				pause=true;
    				guipause.visible=true;
    			}
    		}
    		int tempaiIntelligence;
    		public void keyReleased(KeyEvent e)
    		{
    			int key = e.getKeyCode();
    			if(!pause){
    			}
    		}
    	}
     
    }

    Gui.java

    package net.nivangerow.pong;
    import java.awt.*;
    import javax.swing.*;
     
    public class Gui {
    	boolean visible=true;
    	Image background;
    	int y=200;
    	public Gui()
    	{
    	}
    }
    GuiOp.java

    package net.nivangerow.pong;
    import java.awt.*;
    import javax.swing.*;
     
    public class GuiOp {
    	boolean visible=false;
    	Image background;
    	int y=200;
    	public GuiOp()
    	{
    	}
    }

    GuiError.java

    package net.nivangerow.pong;
    import java.awt.*;
    import javax.swing.*;
     
    public class GuiError {
    	boolean visible=false;
    	Image background;
    	int y=200;
    	public GuiError()
    	{
    	}}

    GuiPause.java

    package net.nivangerow.pong;
    import java.awt.*;
    import javax.swing.*;
     
    public class GuiPause {
    	boolean visible=false;
    	Image background;
    	int y=200;
    	public GuiPause()
    	{
     
    	}
    }

    W+S to move box; enter to select.

    Press S until the box is next to the text that says options and hit enter.
    Then go back and try to go into to the options gui again. That doesnt work.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    First off, I don't want to be annoying, but that's not an SSCCE. It's split up into multiple classes, most of which have nothing to do with the problem, and your Game class still contains way too much code.

    I know you're making an effort though, so I tried it anyway. However, I can't get passed the first screen. The keyboard doesn't do anything, even if I click in the screen first. So I can't really help until you make an actual working example.

    But just from taking a glance at the code, I'd recommend using a debugger, or at the very least some print statements, so you can see what's going on in your program. What is the value of y? What do you think the value of y should be?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9

    Default Re: Help with GUI

    Sorry, to get the key listener to focus you need to press tab. Then it should work.

  10. #10

    Default Re: Help with GUI

    Did it work? Why does my gui not work?

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Seriously, you're going to want to stop bumping your thread, for the reasons I already told you.

    Take a look at the flow of the program in your key listener. More specifically, what happens when it gets done with the first if statement it enters? What happens the second time around? Use a debugger or print statements to help you figure out what's going on.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12

    Default Re: Help with GUI

    Sorry I posted this like 2 secs after you.

    [edit]
    Can you tell me what happens the second time round?
    Last edited by nivangerow; September 6th, 2011 at 09:33 AM.

  13. #13

    Default Re: Help with GUI

    Right I put this System.out.println(gui.visible+" "+guiop.visible);

    in the paint method, because that constantly updates and its all going the way I want it, the variable changes and everything, but it doesnt display and all key actions stil work for the main gui. Help?

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    What happens after that though? I highly recommend using a debugger. Or you could go the long route and put print statements in every single if statement.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #15

    Default Re: Help with GUI

    Why cant you just tell me and what debugger would you recommend?

  16. #16
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Hint: What is the difference between what these two pieces of code might do?

    boolean something = true;
    boolean somethingElse = false;
    if(something){
       somethingElse = true;
       doFirstThing();
    }
    if(somethingElse){
       doSecondThing();
    }

    boolean something = true;
    boolean somethingElse = false;
    if(something){
       somethingElse = true;
       doFirstThing();
    }
    else if(somethingElse){
       doSecondThing();
    }
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. The Following User Says Thank You to KevinWorkman For This Useful Post:

    nivangerow (September 6th, 2011)

  18. #17
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Quote Originally Posted by nivangerow View Post
    Why cant you just tell me and what debugger would you recommend?
    Use whatever debugger comes with your IDE of choice.

    And I can't "just tell you" because that wouldn't be helping. Actually, I pretty much HAVE told you. It's up to you to put the pieces together. If I just tell you what to do, you won't actually learn anything.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  19. #18

    Default Re: Help with GUI

    Come on! I dont get what you mean! Arent they just different ways to lay out stuff?

  20. #19

    Default Re: Help with GUI

    wait... does the else make any difference?

    [edit]

    F*#K how did I miss that? I just put else after my main and pause gui and viola! It worked! Thx so much!

  21. #20
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Quote Originally Posted by nivangerow View Post
    wait... does the else make any difference?

    [edit]

    F*#K how did I miss that? I just put else after my main and pause gui and viola! It worked! Thx so much!
    You're welcome (see, isn't that better than me just telling you?). But I really hope you understand why it works now. If not, I can try to explain it a little better.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  22. #21

    Default Re: Help with GUI

    I still dont quite get it.

  23. #22

    Default Re: Help with GUI

    Btw, about the key listener thing... You know I made a thread about that, thats what I meant. Is there any way I dont have to press tab?

  24. #23
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Quote Originally Posted by nivangerow View Post
    I still dont quite get it.
    I still really recommend you step through it with a debugger. That's all I'm doing. There's no magic to it.

    But what's happening is that the first time you hit enter, you go through this if statement:

    if(gui.visible&&pause)

    And that if statement completes, and you continue evaluating the other if statements (since you aren't using an if statement). Which means that you also enter this if statement, because you just set those variables:

    if(guiop.visible&&pause)

    Once inside that if statement, you reach this inner-if:

    if(guiop.y==300)

    The first time around, that doesn't evaluate to true, but the second time around, it does evaluate to true- presumably because you're setting that variable when you move the selection icon in the options menu the first time around.

    So the second time you hit enter, you also get to that if statement, which I don't think is what you want, because in it you reverse the action:

    guiop.visible=false;
    gui.visible=true;

    Does that make any more sense? If not, the debugger is your friend here. If you want to be a programmer (especially a game programmer), you have to learn to step through your program logic.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  25. #24
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with GUI

    Quote Originally Posted by nivangerow View Post
    Btw, about the key listener thing... You know I made a thread about that, thats what I meant. Is there any way I dont have to press tab?
    Yes, and I gave you some information in that thread, which you proceeded to ignore or argue with. You were given hints and links to tutorials- if you don't want to follow them then that's your prerogative, but I'm not going to waste time repeating myself.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  26. #25

    Default Re: Help with GUI

    Actually I read through it, tried some stuff like requesting the focus and it didnt work.

Page 1 of 2 12 LastLast

Tags for this Thread