Results 1 to 19 of 19
Like Tree2Likes
  • 1 Post By KevinWorkman
  • 1 Post By DarrylBurke

Thread: Java Key Listener Need Help

  1. #1
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default Java Key Listener Need Help

    I need help with writing a KeyListener for "Specific" keys like "W", "A", "S", "D". I've been reading up on the tutorial section on the tutorial page of Java. Also been searching around on the internet without understanding anything. Please help! Thanks.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Are you sure you don't want key bindings?

    And have you read the KeyListener tutorial?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    What's the difference? Is the key bindings for like "Binding" the "W" key to an event that happens?
    Yupp, I've read the KeyListener tutorial. (2 times)

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by Alerhau View Post
    What's the difference? Is the key bindings for like "Binding" the "W" key to an event that happens?
    What does the tutorial say? How to Use Key Bindings (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)


    Quote Originally Posted by Alerhau View Post
    Yupp, I've read the KeyListener tutorial. (2 times)
    And what about it did you not understand? If you put together an SSCCE showing where you're stuck, it would be easier to help you.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    Still don't understand it.

    I would be more than happy if someone can give me a small code of how to use the "W", "A", "S", "D" keys in a game. (The example can just be that when you klick one of the keys, the Frame says (For W) "You Walked Upward", and so on. Thanks!

    I'm sorry for not understanding the tutorials. I guess that I'm still a nobie when it comes to making games. But with some help I will learn how you can do. So, thanks again!

    Best Regards Alerhau

  6. #6
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default

    An example so you might better understand it: (using a Japplet and KeyListener)

    Java Code:
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    import javax.swing.JApplet;
    
    
    public class test extends JApplet implements KeyListener {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	public void init()
    	{
    		addKeyListener(this);
    	}
    	
    	@Override
    	public void keyPressed(KeyEvent e) {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void keyReleased(KeyEvent e) {
    		// TODO Auto-generated method stub
    		int keyCode = e.getKeyCode();
    		switch( keyCode ) 
    		{ 
    			case KeyEvent.VK_SPACE:
    				System.out.print("You released the SPACEBAR!!!");
    				break;
    			case KeyEvent.VK_ENTER:
    				System.out.print("You released ENTER!!!");
    				break;
    		}
    	}
    
    	@Override
    	public void keyTyped(KeyEvent e) {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    Last edited by Reskaillev; 08-02-2011 at 01:09 PM.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    @Reskaillev : Do you really want to print "You pressed ..." in the keyReleased(...) method?

    @Alerhau: For your purpose, avoid using a KeyListener and use key bindings as detailed in the linked tutorial.

    db

  8. #8
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    @Reskaillev : Do you really want to print "You pressed ..." in the keyReleased(...) method?

    @Alerhau: For your purpose, avoid using a KeyListener and use key bindings as detailed in the linked tutorial.

    db
    Fixed it (#10CHAR)

  9. #9
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    *Reskaillev* Thankyou for the code. I still do not know where to put it in a JFrame code tho.

    * Am I gonna put it outside the code class?

    (I have one class that opens the window. Also where I have the size of the window and all of that stuff there. Then I have one class for all of the code. That is the "Code" class.)

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    ^ Direct evidence that spoonfeeding is not helpful. ^

    What don't you understand about the tutorials and posted code? What have you tried "to put it in a JFrame code"? What does that mean? What does "outside the code class" mean?
    Fubarable likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    Also, would be nice with some code of the Key Binding, just to see the difference.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    would be nice with some code of the Key Binding
    Still haven't bothered to go through the tutorial, huh? Sometimes I wonder why we waste our time posting links.

    db
    KevinWorkman likes this.

  13. #13
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    I have been going through the tutorial a couple of times. But I am a person that need code sometimes in order to learn. So, I would be more than happy if I can get the same code as you wrote (Reskaillev), but instead of doing it in an Applet it would be great with doing it in a JFrame. Thanks!

    Alerhau

  14. #14
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    I think most people are better at doing their work when somebody else does it for them. That won't help you learn though. What part of the tutorial is confusing?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Alerhau View Post
    I have been going through the tutorial a couple of times. But I am a person that need code sometimes in order to learn.
    Ahem, the tutorials have code samples. Learn away.

    So, I would be more than happy if I can get the same code as you wrote (Reskaillev), but instead of doing it in an Applet it would be great with doing it in a JFrame. Thanks!
    Much better for you to try to write it yourself and post your attempt here if you run into problems.

  16. #16
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    I've tried it out and I got it working in a new project.

    But when I got back to my old one it did'nt work... I'm confused. So I realised that the only way that I can get help now is to post my code.

    First, I will tell you some about the code/program. I'm building a small Dwarf Fortress / Minecraft game in 2D. Right now in order to move, you will have to press buttons (JButtons). Now I wanna change so that you can move over the "Grid" as I call it without clicking the buttons (JButtons). But I can't get it working with the KeyListener. At the bottom of the code you can see what I've done so far. Please help me fix the problem. Thanks!

    Java Code:
    public class Gui extends JFrame{
    	public int xpos = 5;
    	public int ypos = 5;
    	
    	/*Booleans*/
    	//HATCHETS.
    	public boolean HasHatchet = true;
    	public boolean HasGravelHatchet = false;
    	public boolean HasStoneHatchet = false;
    	public boolean HasIronHatchet = false;
    	public boolean HasSpaceHatchet = false;
    	public boolean HasAdminHatchet = true;
    	
    	//HOES.
    	public boolean HasHoe = false;
    	
    	//PICKAXES.
    	public boolean HasPickaxe = true;
    	public boolean HasGravelPickaxe = false;
    	public boolean HasStonePickaxe = false;
    	public boolean HasIronPickaxe = false;
    	public boolean HasSpacePickaxe = false;
    	public boolean HasAdminPickaxe = true;
    	
    	
    	/*Booleans*/
    	
    	/*Res*/
    	//Flooring & Seeds
    	public int Floor_Grass = 0;
    	public int Floor_Stone = 0;
    	
    	//Walls
    	public int Wall_Wood = 0;
    	public int Wall_Stone = 0;
    	public int Wall_Sand = 0;
    	/*Res*/
    	
    	public Icon[] Spr = {new ImageIcon(getClass().getResource("img\\Character.png")), new ImageIcon(getClass().getResource("img\\Sand.png")), new ImageIcon(getClass().getResource("img\\Stone.png"))};
    	public Color[] Col = {new Color(255, 220, 155), Color.DARK_GRAY, Color.GRAY, new Color(100,250,30), new Color(70, 15, 15), new Color(40, 55, 5)};
    	
    	public Panel[][] Grid = new Panel[18][25];
    	
    	public int[][] Values = {{2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    							 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
    	
    	public JPanel Center = new JPanel();
    	
    	public Gui() {
    		
    		/*Code*/
    		add(Center);
    		Center.setBackground(Color.BLACK);
    		Center.setLayout(new GridLayout(Grid.length, Grid[0].length, 1, 1));
    		
    		int i=0, x=0;
    		
    		while(i < Grid.length) {
    			while(x < Grid[0].length) {
    				Grid[i][x] = new Panel(Spr[Values[i][x]]);
    				x++;
    			}
    			i++;
    			x=0;
    		}
    		
    		i = 0;
    		x = 0;
    		
    		while(i < Grid.length) {
    			while(x < Grid[0].length) {
    				Center.add(Grid[i][x]);
    				x++;
    			}
    			i++;
    			x=0;
    		}
    		
    		/*Movement & Buttons*/
    		
    		Grid[xpos][ypos].Sprite.setIcon(Spr[0]);
    		
    		JButton Up = new JButton("    ▲    ");
    		JButton Le = new JButton("    <    ");
    		JButton Ri = new JButton("    >    ");
    		JButton Do = new JButton("    ▼    ");
    		JLabel Objv = new JLabel();
    		
    		JPanel Bar = new JPanel();
    		Bar.setLayout(new GridLayout(13, 1, 0, 0));
    		Bar.setBackground(Color.WHITE);
    		
    		Bar.add(Up);
    		Bar.add(Le);
    		Bar.add(Ri);
    		Bar.add(Do);
    		Bar.add(Objv);
    		
    		add(Bar, BorderLayout.EAST);
    		
    		//Movement Buttons;
    		Up.addActionListener(new ActionListener() {
    			
    			public void actionPerformed(ActionEvent e) {
    				
    				if(Values[xpos-1][ypos] == 1) { //SAND: Testing the sand blocks;
    					Grid[xpos][ypos].Sprite.setIcon(Spr[Values[xpos][ypos]]);
    					Grid[xpos-1][ypos].Sprite.setIcon(Spr[0]);
    					xpos-=1; //END: Of the sand;
    				
    				} else if(Values[xpos-1][ypos] == 2) { //STONE: Testing the stone blocks;
    					if(HasPickaxe == true) {
    						try {
    							if(HasGravelPickaxe == true) {
    								Thread.sleep(7000);
    							} else if(HasStonePickaxe == true) {
    								Thread.sleep(5000);
    							} else if(HasIronPickaxe == true) {
    								Thread.sleep(3000);
    							} else if(HasSpacePickaxe == true) {
    								Thread.sleep(1000);
    							} else if(HasAdminPickaxe == true) {
    								Thread.sleep(0);
    							}
    							
    							Wall_Stone += 1;
    							
    							Values[xpos-1][ypos] = 1;
    							Grid[xpos-1][ypos].Sprite.setIcon(Spr[1]);
    						}catch(Exception E){}
    					} //END: Of the stone;
    					
    				} else if(Values[xpos-1][ypos] == 3) { //GrassTestWithAndOutHoe
    					if(HasHoe == true) {
    						Values[xpos-1][ypos] = 4;
    					}
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos-1][ypos].setBackground(Color.BLACK);
    					xpos-=1;
    					
    				} else if(Values[xpos-1][ypos] == 4) { //DirtTest
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos-1][ypos].setBackground(Color.BLACK);
    					xpos-=1;
    					
    				} else if(Values[xpos-1][ypos] == 5) { //WoodTestChopDownAndCollision
    					if(HasHatchet == true) {
    						try{
    							if(HasStoneHatchet == true) {
    								Thread.sleep(6000);
    							} else if(HasIronHatchet == true) {
    								Thread.sleep(4000);
    							} else if(HasSpaceHatchet == true) {
    								Thread.sleep(2000);
    							} else if(HasAdminHatchet == true) {
    								Thread.sleep(0);
    							}
    						} catch(Exception E) {}
    						Wall_Wood++;
    						Values[xpos-1][ypos] = 4;
    						Grid[xpos-1][ypos].setBackground(Col[Values[xpos-1][ypos]]);
    						}
    					}
    				
    			}
    		});
    		
    		Le.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if(Values[xpos][ypos-1] == 1) {
    					
    				} else if(Values[xpos][ypos-1] == 0) {
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos][ypos-1].setBackground(Color.BLACK);
    					ypos-=1;
    				} else if(Values[xpos][ypos-1] == 3) {
    					if(HasHoe == true) {
    						Values[xpos][ypos-1] = 4;
    					}
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos][ypos-1].setBackground(Color.BLACK);
    					ypos-=1;
    				} else if(Values[xpos][ypos-1] == 4) {
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos][ypos-1].setBackground(Color.BLACK);
    					ypos-=1;
    				} else if(Values[xpos][ypos-1] == 5) {
    					if(HasHatchet == true) {
    						try{
    							if(HasStoneHatchet == true) {
    								Thread.sleep(6000);
    							} else if(HasIronHatchet == true) {
    								Thread.sleep(4000);
    							} else if(HasSpaceHatchet == true) {
    								Thread.sleep(2000);
    							} else if(HasAdminHatchet == true) {
    								Thread.sleep(0);
    							}
    						} catch(Exception exept) {}
    						Wall_Wood++;
    						Values[xpos][ypos-1] = 4;
    						Grid[xpos][ypos-1].setBackground(Col[Values[xpos][ypos-1]]);
    						}
    					}
    			}
    		});
    		
    		Ri.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if(Values[xpos][ypos+1] == 1) {
    					
    				} else if(Values[xpos][ypos+1] == 0) {
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos][ypos+1].setBackground(Color.BLACK);
    					ypos+=1;
    				} else if(Values[xpos][ypos+1] == 3) {
    					if(HasHoe == true) {
    						Values[xpos][ypos+1] = 4;
    					}
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos][ypos+1].setBackground(Color.BLACK);
    					ypos+=1;
    				} else if(Values[xpos][ypos+1] == 4) {
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos][ypos+1].setBackground(Color.BLACK);
    					ypos+=1;
    				} else if(Values[xpos][ypos+1] == 5) {
    					if(HasHatchet == true) {
    						try{
    							if(HasStoneHatchet == true) {
    								Thread.sleep(6000);
    							} else if(HasIronHatchet == true) {
    								Thread.sleep(4000);
    							} else if(HasSpaceHatchet == true) {
    								Thread.sleep(2000);
    							} else if(HasAdminHatchet == true) {
    								Thread.sleep(0);
    							}
    						} catch(Exception exept) {}
    						Wall_Wood++;
    						Values[xpos][ypos+1] = 4;
    						Grid[xpos][ypos+1].setBackground(Col[Values[xpos][ypos+1]]);
    						}
    					}
    			} 
    		});
    		
    		Do.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if(Values[xpos+1][ypos] == 1) {
    					
    				} else if(Values[xpos+1][ypos] == 0) {
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos+1][ypos].setBackground(Color.BLACK);
    					xpos+=1;
    					
    				} else if(Values[xpos+1][ypos] == 3) {
    					if(HasHoe == true) {
    						Values[xpos+1][ypos] = 4;
    					}
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos+1][ypos].setBackground(Color.BLACK);
    					xpos+=1;
    					
    				} else if(Values[xpos+1][ypos] == 4) {
    					Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    					Grid[xpos+1][ypos].setBackground(Color.BLACK);
    					xpos+=1;
    					
    				} else if(Values[xpos+1][ypos] == 5) { //WoodTestChopDownAndCollision
    					if(HasHatchet == true) {
    						try{
    							if(HasStoneHatchet == true) {
    								Thread.sleep(6000);
    							} else if(HasIronHatchet == true) {
    								Thread.sleep(4000);
    							} else if(HasSpaceHatchet == true) {
    								Thread.sleep(2000);
    							} else if(HasAdminHatchet == true) {
    								Thread.sleep(0);
    							}
    						} catch(Exception exept) {}
    						Wall_Wood++;
    						Values[xpos+1][ypos] = 4;
    						Grid[xpos+1][ypos].setBackground(Col[Values[xpos+1][ypos]]);
    						}
    					}
    			}
    		});
    		
    		addKeyListener(new KeyListener() {
    
    			@Override
    			public void keyPressed(KeyEvent e) {
    				// TODO Auto-generated method stub
    				if(e.getKeyCode() == KeyEvent.VK_W) {
    					if(Values[xpos-1][ypos] == 1) { //SAND: Testing the sand blocks;
    						Grid[xpos][ypos].Sprite.setIcon(Spr[Values[xpos][ypos]]);
    						Grid[xpos-1][ypos].Sprite.setIcon(Spr[0]);
    						xpos-=1; //END: Of the sand;
    					
    					} else if(Values[xpos-1][ypos] == 2) { //STONE: Testing the stone blocks;
    						if(HasPickaxe == true) {
    							try {
    								if(HasGravelPickaxe == true) {
    									Thread.sleep(7000);
    								} else if(HasStonePickaxe == true) {
    									Thread.sleep(5000);
    								} else if(HasIronPickaxe == true) {
    									Thread.sleep(3000);
    								} else if(HasSpacePickaxe == true) {
    									Thread.sleep(1000);
    								} else if(HasAdminPickaxe == true) {
    									Thread.sleep(0);
    								}
    								
    								Wall_Stone += 1;
    								
    								Values[xpos-1][ypos] = 1;
    								Grid[xpos-1][ypos].Sprite.setIcon(Spr[1]);
    							}catch(Exception E){}
    						} //END: Of the stone;
    						
    					} else if(Values[xpos-1][ypos] == 3) { //GrassTestWithAndOutHoe
    						if(HasHoe == true) {
    							Values[xpos-1][ypos] = 4;
    						}
    						Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    						Grid[xpos-1][ypos].setBackground(Color.BLACK);
    						xpos-=1;
    						
    					} else if(Values[xpos-1][ypos] == 4) { //DirtTest
    						Grid[xpos][ypos].setBackground(Col[Values[xpos][ypos]]);
    						Grid[xpos-1][ypos].setBackground(Color.BLACK);
    						xpos-=1;
    						
    					} else if(Values[xpos-1][ypos] == 5) { //WoodTestChopDownAndCollision
    						if(HasHatchet == true) {
    							try{
    								if(HasStoneHatchet == true) {
    									Thread.sleep(6000);
    								} else if(HasIronHatchet == true) {
    									Thread.sleep(4000);
    								} else if(HasSpaceHatchet == true) {
    									Thread.sleep(2000);
    								} else if(HasAdminHatchet == true) {
    									Thread.sleep(0);
    								}
    							} catch(Exception E) {}
    							Wall_Wood++;
    							Values[xpos-1][ypos] = 4;
    							Grid[xpos-1][ypos].setBackground(Col[Values[xpos-1][ypos]]);
    							}
    						}
    				}
    			}
    
    			@Override
    			public void keyReleased(KeyEvent e) {
    				// TODO Auto-generated method stub
    				
    			}
    
    			@Override
    			public void keyTyped(KeyEvent e) {
    				// TODO Auto-generated method stub
    				
    			}
    			
    		});
    		
    		/*Movement*/
    	}
    }

  17. #17
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    That was my "Gui" class. I also have an "Engine" class that runs the "Gui".

  18. #18
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    Note... The "XPOS" & "YPOS" is working in the wrong directions! O.O (Nothing to worry about.)
    Last edited by Alerhau; 08-02-2011 at 07:16 PM.

  19. #19
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    You'll have much better luck if you boil that down to an SSCCE like you were asked. People don't really have time to wade through that much code.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. GIOVYNET Java Serial Comm event listener
    By Edudlc in forum New To Java
    Replies: 5
    Last Post: 05-17-2011, 02:38 PM
  2. Java Addition Program Help with Action Listener
    By Syanara in forum New To Java
    Replies: 21
    Last Post: 05-12-2011, 07:03 PM
  3. Java SOAP Listener
    By njitram in forum Advanced Java
    Replies: 1
    Last Post: 01-29-2011, 09:59 PM
  4. java Code to start MDB Listener
    By ganeshkumarm in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 01-20-2011, 12:45 AM
  5. Adding listener to non-Java object?
    By cruxblack in forum Advanced Java
    Replies: 5
    Last Post: 07-30-2007, 02:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •