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.

Results 1 to 8 of 8

Thread: Layout Manager and Keyboard Panel

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Layout Manager and Keyboard Panel

    I am working on a program to run a game engine. Right now I am working with a frame that has two panels in it. One is for the main display, and the other is for the keyboard controls. The problem I am having is that I want to run some subroutines that utilize the getHeight() and getLength() commands in the keyboard panel. When I try to use it, it gives results for the keyboard panel rather than the entire frame.

    I have tried running different layout managers. CardLayout, GridLayout, BorderLayout, even multiple frames and have not been able to get the desired results. I had the most success with the BorderLayout, and could use fixed numbers rather than the getHeight() and getWidth() commands, but then the window would not adjust properly if resized.

    I realize that my code is not optimized and looks pretty sloppy at the moment. That is not something I am worried about right now as I can always go through and clean it up once I get everything working properly.

    Any help would be appreciated.

    import java.awt.BorderLayout;
     
     
     
    import java.awt.CardLayout;
    import java.awt.Graphics;
    import java.awt.GridLayout;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
     
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
     
     
     
    public class gameTester2 extends JFrame {
    	//tester variables
    	private KeyboardPanel keyboardPanel = new KeyboardPanel();
    	private static int charPoint[] = {30, 120};
    	private static int bgPoint[] = {0, -150};
    	private static environment[] environment;
     
     
     
    	public static int[] getCharPoint() {
    		return charPoint;
    	}
    	public static void setCharPoint(int[] charPoint) {
    		gameTester2.charPoint = charPoint;
    	}
    	public static int[] getBgPoint() {
    		return bgPoint;
    	}
    	public static void setBgPoint(int[] bgPoint) {
    		gameTester2.bgPoint = bgPoint;
    	}
    	public static environment[] getEnvironment() {
    		return environment;
    	}
    	public static void setEnvironment(environment[] environment) {
    		gameTester2.environment = environment;
    	}
     
    	public static void main(String[] args){
     
    		int[][] layout = getMap0(); //get map0 layout
     
    		int temp = 0;
     
    		for (int i = 0; i < layout.length; i++){ //build environment array length
    			for (int j = 0; j < layout[1].length; j++){
    				if (layout[i][j] == 1){ //if (0 < layout[i][j] < 20); if 20 types of environment objects
    					temp++;
    				}
    			}		
    		}
     
    		environment[] tempEnvironment = new environment[temp]; //new environment array with length
     
    		temp = 0;
    		for (int i = 0; i < layout.length; i++){ //build environment array
    			for (int j = 0; j < layout[1].length; j++){
    				if (layout[i][j] == 1){
    					int point[] = {i * 50, (j * 50) + bgPoint[1]};
    					tempEnvironment[temp] = new environment("basicBlock", point);  //basicBlock constructors 
    					temp++; 
    				}
    				if (layout[i][j] == 2){
    					int point[] = {i * 50, j * 50};
    					tempEnvironment[temp] = new environment("metalBlock", point); //metalBlock constructors
    					temp++;
    				}
    			}
    		}
     
    		environment = tempEnvironment; //set environment
     
    		//setup frame
    		gameTester2 frame = new gameTester2();
    		frame.setTitle("Tester");
    		frame.setSize(600, 500);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    	}
     
    	public gameTester2(){
    		//game tester constructor, sets up layout manager for frame
    		String vp = "null";
    		setLayout(new BorderLayout());
     
    		JPanel p1 = new AnimatedPanel(vp);
    		p1.setSize(600, 500);
     
    		JPanel p2 = new KeyboardPanel();
    		p2.setSize(0, 0);
     
     
    		add(p1, BorderLayout.CENTER);
     
    		add(p2, BorderLayout.SOUTH);
    		p2.setFocusable(true);
    	}
     
    	static class AnimatedPanel extends JPanel{
     
    		//setup ImageIcons and Image objects for various images. sections for player, enemy, weapon and environment objects
     
    		//player.getFaceRight(), if true, playerIcon = "NinjaRight.gif";
    		//player.getFaceRight(), if false, playerIcon = "NinjaLeft.gif";
     
    		ImageIcon playerIcon = new ImageIcon("/Users/zerosdamnation/Documents/Projects/Photoshop/NinjaRight.gif");
    		Image playerIcon2 = playerIcon.getImage();
     
    		// String bg = "Documents/Projects/Photoshop/" + theme + "/";
    		// ImageIcon background = new ImageIcon(bg + "background.gif");
    		ImageIcon background = new ImageIcon("/Users/zerosdamnation/Documents/Projects/Photoshop/backgroundtest.gif");
    		Image background2 = background.getImage();
     
    		// ImageIcon basicBlock = new ImageIcon(bg + "basicBlock.gif");
    		ImageIcon basicBlock = new ImageIcon("/Users/zerosdamnation/Documents/Projects/Photoshop/block.gif");
    		Image basicBlock2 = basicBlock.getImage();
     
    		public AnimatedPanel(String message){
    			//setup timer for various checks and repaint command 
    			Timer timer = new Timer(62, new TimerListener());
    			timer.start();
    		}
     
    		protected void paintComponent(Graphics g){
    			super.paintComponent(g);
     
     
    			//get image variables
     
    			//g.draw image(which image, # of pixels from left border, # of pixels from top border, width of image, height of image, this??)
    			//draw in order of display, with background first, then level, then player
     
    			g.drawImage(background2, bgPoint[0], bgPoint[1], 800, 600, this); //draw background image
     
    			for (int i = 0; i < environment.length; i++){ //draw environment objects
    				int[] temp = environment[i].getPoint();	
    				g.drawImage(basicBlock2, temp[0], temp[1], 50, 50, this);
    			}
     
    			g.drawImage(playerIcon2, charPoint[0], charPoint[1], 70, 90, this); //draw player
     
    			//draw enemy objects
     
    			//draw player weapons
     
    			//draw enemy weapons
     
     
    		}
     
    		class TimerListener implements ActionListener{
    			//setup various checks here
    			public void actionPerformed(ActionEvent e){
    				//or setup various checks here
    				repaint();
    			}		
    		}
    	}
     
    	static class KeyboardPanel extends JPanel{ 
    		//keyboardPanel variables, might want to consolidate some into tester variables
    		private int bgx = 0;
    		private int bgy = 0;
    		private int x;
    		private int y;
    		private int x2;
    		private int y2;
     
    		public KeyboardPanel(){
    			addKeyListener(new KeyAdapter(){
    				public void keyPressed(KeyEvent e){
    					switch (e.getKeyCode()){ //gets key pressed
     
    					//check for keyreleased code
     
    					//fix getHeight/getWidth commands
    					case KeyEvent.VK_DOWN:
    						int[] point = getCharPoint();
    						y = point[1];
    						y2 = getHeight();
    						float temp0 = y;
    						float temp2 = y2;
    						float loc = temp0 / temp2;
    						System.out.println("Key Down");
    						System.out.println("y = " + temp0);
    						System.out.println("y2 = " + temp2);
    						System.out.println("loc = " + loc);
     
    						if (loc > 0.75){
    							bgx++;
    							if (bgx == 3){ //background frame movement
    								int[] temp = bgPoint;
    								temp[1] = temp[1] - 4;
    								bgPoint = temp;
    								bgx = 0;
    							}
    							for (int i = 0; i < environment.length; i++){ //environment movement
    								int[] temp = environment[i].getPoint();
    								temp[1] = temp[1] - 8; //number of pixels to move
    								environment[i].setPoint(temp);
    							}
    						}
    						else {
    							point[1] = point[1] + 8; //player movement
    							setCharPoint(point);
    						}				
    						break;
     
    					case KeyEvent.VK_UP:
    						int[] point2 = getCharPoint();
    						y = point2[1];
    						//getHeight() is returning 10 for some reason?
    						y2 = getHeight();
    						float temp3 = y;
    						float temp4 = y2;
    						float loc2 = temp3 / temp4;
    						System.out.println("Key Up");
    						System.out.println("y = " + temp3);
    						System.out.println("y2 = " + temp4);
    						System.out.println("loc = " + loc2);
     
    						if (loc2 < 0.25){
    							bgx--;
    							if (bgx == -3){
    								int[] temp = bgPoint;
    								temp[1] = temp[1] + 4;
    								bgPoint = temp;
    								bgx = 0;
    							}
    							for (int i = 0; i < environment.length; i++){
    								int[] temp = environment[i].getPoint();
    								temp[1] = temp[1] + 8; //number of pixels to move
    								environment[i].setPoint(temp);
    							}
    						}
    						else {
    							point2[1] = point2[1] - 8;
    							setCharPoint(point2);
    						}				
    						break;
     
     
    					case KeyEvent.VK_LEFT:
    						int[] point3 = getCharPoint();
    						x = point3[0];
    						x2 = getWidth();
    						float temp5 = x;
    						float temp6 = x2;
    						float loc3 = temp5 / temp6;
    						System.out.println("Key Left");
    						System.out.println("x = " + temp5);
    						System.out.println("x2 = " + temp6);
    						System.out.println("loc = " + loc3);
     
    						if (loc3 < 0.25){
    							bgy--;
    							if (bgy == -3){
    								int[] temp = bgPoint;
    								temp[0] = temp[0] + 4;
    								bgPoint = temp;
    								bgy = 0;
    							}
    							for (int i = 0; i < environment.length; i++){
    								int[] temp = environment[i].getPoint();
    								temp[0] = temp[0] + 8; //number of pixels to move
    								environment[0].setPoint(temp);
    							}
    						}
    						else {
    							point3[0] = point3[0] - 8;
    							setCharPoint(point3);
    						}		
     
    						break;
     
    					case KeyEvent.VK_RIGHT:
    						int[] point4 = getCharPoint();
    						x = point4[0];
    						x2 = getWidth();
    						float temp7 = x;
    						float temp8 = x2;
    						float loc4 = temp7 / temp8;
    						System.out.println("Key Right");
    						System.out.println("x = " + temp7);
    						System.out.println("x2 = " + temp8);
    						System.out.println("loc = " + loc4);
     
    						if (loc4 < 0.25){
    							bgy--;
    							if (bgy == -3){
    								int[] temp = bgPoint;
    								temp[0] = temp[0] - 4;
    								bgPoint = temp;
    								bgy = 0;
    							}
    							for (int i = 0; i < environment.length; i++){
    								int[] temp = environment[i].getPoint();
    								temp[0] = temp[0] - 8; //number of pixels to move
    								environment[0].setPoint(temp);
    							}
    						}
    						else {
    							point4[0] = point4[0] + 8;
    							setCharPoint(point4);
    						}		
     
    						break;
    					}
     
     
    					repaint();
    				}
    			});
    		}	
    	}	
     
    	public static int[][] getMap0(){
    		//map 0, aka level 1
    		//int[][] map = {{2,3, 0}, {2,2,2}, {3,3,3}}; a better way to do it. 
    		int[][] map = new int[32][12];  
    		map[0][0] = 1; map[1][0] = 0; map[2][0] = 0; map[3][0] = 0; map[4][0] = 0; map[5][0] = 0; map[6][0] = 0; map[7][0] = 0;
    		map[8][0] = 0; map[9][0] = 0; map[10][0] = 0; map[11][0] = 0; map[12][0] = 0; map[13][0] = 0; map[14][0] = 0; map[15][0] = 0; 
    		map[16][0] = 0; map[17][0] = 0; map[18][0] = 0; map[19][0] = 0; map[20][0] = 0; map[21][0] = 0; map[22][0] = 0; map[23][0] = 0;
    		map[24][0] = 0; map[25][0] = 0; map[26][0] = 0; map[27][0] = 0;	map[28][0] = 0; map[29][0] = 0; map[30][0] = 0; map[31][0] = 1;
     
    		map[0][1] = 1; map[1][1] = 0; map[2][1] = 0; map[3][1] = 0; map[4][1] = 0; map[5][1] = 0; map[6][1] = 0; map[7][1] = 0;
    		map[8][1] = 0; map[9][1] = 0; map[10][1] = 0; map[11][1] = 0; map[12][1] = 0; map[13][1] = 0; map[14][1] = 0; map[15][1] = 0; 
    		map[16][1] = 0; map[17][1] = 0; map[18][1] = 0; map[19][1] = 0; map[20][1] = 0; map[21][1] = 0; map[22][1] = 0; map[23][1] = 0;
    		map[24][1] = 0; map[25][1] = 0; map[26][1] = 0; map[27][1] = 0;	map[28][1] = 0; map[29][1] = 0; map[30][1] = 0; map[31][1] = 1;	
     
    		map[0][2] = 1; map[1][2] = 0; map[2][2] = 0; map[3][2] = 0; map[4][2] = 0; map[5][2] = 0; map[6][2] = 0; map[7][2] = 0;
    		map[8][2] = 0; map[9][2] = 0; map[10][2] = 0; map[11][2] = 0; map[12][2] = 0; map[13][2] = 0; map[14][2] = 0; map[15][2] = 0; 
    		map[16][2] = 0; map[17][2] = 0; map[18][2] = 0; map[19][2] = 0; map[20][2] = 0; map[21][2] = 0; map[22][2] = 0; map[23][2] = 0;
    		map[24][2] = 0; map[25][2] = 0; map[26][2] = 0; map[27][2] = 0;	map[28][2] = 0; map[29][2] = 0; map[30][2] = 0; map[31][2] = 1;	
     
    		map[0][3] = 1; map[1][3] = 0; map[2][3] = 0; map[3][3] = 0; map[4][3] = 0; map[5][3] = 0; map[6][3] = 0; map[7][3] = 0;
    		map[8][3] = 0; map[9][3] = 0; map[10][3] = 0; map[11][3] = 0; map[12][3] = 0; map[13][3] = 0; map[14][3] = 0; map[15][3] = 0; 
    		map[16][3] = 0; map[17][3] = 0; map[18][3] = 0; map[19][3] = 0; map[20][3] = 0; map[21][3] = 0; map[22][3] = 0; map[23][3] = 0;
    		map[24][3] = 0; map[25][3] = 0; map[26][3] = 0; map[27][3] = 0;	map[28][3] = 0; map[29][3] = 0; map[30][3] = 0; map[31][3] = 1;	
     
    		map[0][4] = 1; map[1][4] = 0; map[2][4] = 0; map[3][4] = 0; map[4][4] = 0; map[5][4] = 0; map[6][4] = 0; map[7][4] = 0;
    		map[8][4] = 0; map[9][4] = 0; map[10][4] = 0; map[11][4] = 0; map[12][4] = 0; map[13][4] = 0; map[14][4] = 0; map[15][4] = 0; 
    		map[16][4] = 0; map[17][4] = 0; map[18][4] = 0; map[19][4] = 0; map[20][4] = 0; map[21][4] = 0; map[22][4] = 0; map[23][4] = 0;
    		map[24][4] = 0; map[25][4] = 0; map[26][4] = 0; map[27][4] = 0;	map[28][4] = 0; map[29][4] = 0; map[30][4] = 0; map[31][4] = 1;	
     
    		map[0][5] = 1; map[1][5] = 0; map[2][5] = 0; map[3][5] = 0; map[4][5] = 0; map[5][5] = 0; map[6][5] = 0; map[7][5] = 0;
    		map[8][5] = 0; map[9][5] = 0; map[10][5] = 0; map[11][5] = 0; map[12][5] = 0; map[13][5] = 0; map[14][5] = 0; map[15][5] = 0; 
    		map[16][5] = 0; map[17][5] = 0; map[18][5] = 0; map[19][5] = 0; map[20][5] = 0; map[21][5] = 0; map[22][5] = 0; map[23][5] = 0;
    		map[24][5] = 0; map[25][5] = 0; map[26][5] = 0; map[27][5] = 0;	map[28][5] = 0; map[29][5] = 0; map[30][5] = 0; map[31][5] = 1;	
     
    		map[0][6] = 1; map[1][6] = 0; map[2][6] = 0; map[3][6] = 0; map[4][6] = 0; map[5][6] = 0; map[6][6] = 0; map[7][6] = 0;
    		map[8][6] = 0; map[9][6] = 0; map[10][6] = 0; map[11][6] = 0; map[12][6] = 0; map[13][6] = 0; map[14][6] = 0; map[15][6] = 0; 
    		map[16][6] = 0; map[17][6] = 0; map[18][6] = 0; map[19][6] = 0; map[20][6] = 0; map[21][6] = 0; map[22][6] = 0; map[23][6] = 0;
    		map[24][6] = 0; map[25][6] = 0; map[26][6] = 0; map[27][6] = 0;	map[28][6] = 0; map[29][6] = 0; map[30][6] = 0; map[31][6] = 1;	
     
    		map[0][7] = 1; map[1][7] = 0; map[2][7] = 0; map[3][7] = 0; map[4][7] = 0; map[5][7] = 0; map[6][7] = 0; map[7][7] = 0;
    		map[8][7] = 0; map[9][7] = 0; map[10][7] = 0; map[11][7] = 0; map[12][7] = 0; map[13][7] = 0; map[14][7] = 0; map[15][7] = 0; 
    		map[16][7] = 0; map[17][7] = 0; map[18][7] = 0; map[19][7] = 0; map[20][7] = 0; map[21][7] = 0; map[22][7] = 0; map[23][7] = 0;
    		map[24][7] = 0; map[25][7] = 0; map[26][7] = 0; map[27][7] = 0;	map[28][7] = 0; map[29][7] = 0; map[30][7] = 0; map[31][7] = 1;	
     
    		map[0][8] = 1; map[1][8] = 0; map[2][8] = 0; map[3][8] = 0; map[4][8] = 0; map[5][8] = 0; map[6][8] = 0; map[7][8] = 0;
    		map[8][8] = 0; map[9][8] = 0; map[10][8] = 0; map[11][8] = 0; map[12][8] = 0; map[13][8] = 0; map[14][8] = 0; map[15][8] = 0; 
    		map[16][8] = 0; map[17][8] = 0; map[18][8] = 0; map[19][8] = 0; map[20][8] = 0; map[21][8] = 0; map[22][8] = 0; map[23][8] = 0;
    		map[24][8] = 0; map[25][8] = 0; map[26][8] = 0; map[27][8] = 0;	map[28][8] = 0; map[29][8] = 0; map[30][8] = 0; map[31][8] = 1;	
     
    		map[0][9] = 1; map[1][9] = 0; map[2][9] = 0; map[3][9] = 0; map[4][9] = 0; map[5][9] = 0; map[6][9] = 0; map[7][9] = 0;
    		map[8][9] = 0; map[9][9] = 0; map[10][9] = 0; map[11][9] = 0; map[12][9] = 0; map[13][9] = 0; map[14][9] = 0; map[15][9] = 0; 
    		map[16][9] = 0; map[17][9] = 0; map[18][9] = 0; map[19][9] = 0; map[20][9] = 0; map[21][9] = 0; map[22][9] = 0; map[23][9] = 0;
    		map[24][9] = 0; map[25][9] = 0; map[26][9] = 0; map[27][9] = 0;	map[28][9] = 0; map[29][9] = 0; map[30][9] = 0; map[31][9] = 1;	
     
    		map[0][10] = 1; map[1][10] = 0; map[2][10] = 0; map[3][10] = 0; map[4][10] = 0; map[5][10] = 0; map[6][10] = 0; map[7][10] = 0;
    		map[8][10] = 0; map[9][10] = 0; map[10][10] = 0; map[11][10] = 0; map[12][10] = 0; map[13][10] = 0; map[14][10] = 0; map[15][10] = 0; 
    		map[16][10] = 0; map[17][10] = 0; map[18][10] = 0; map[19][10] = 0; map[20][10] = 0; map[21][10] = 0; map[22][10] = 0; map[23][10] = 0;
    		map[24][10] = 0; map[25][10] = 0; map[26][10] = 0; map[27][10] = 0;	map[28][10] = 0; map[29][10] = 0; map[30][10] = 0; map[31][10] = 1;	
     
    		map[0][11] = 1; map[1][11] = 1; map[2][11] = 1; map[3][11] = 1; map[4][11] = 1; map[5][11] = 1; map[6][11] = 1; map[7][11] = 1;
    		map[8][11] = 1; map[9][11] = 1; map[10][11] = 1; map[11][11] = 1; map[12][11] = 1; map[13][11] = 1; map[14][11] = 1; map[15][11] = 1; 
    		map[16][11] = 1; map[17][11] = 1; map[18][11] = 1; map[19][11] = 1; map[20][11] = 1; map[21][11] = 1; map[22][11] = 1; map[23][11] = 1;
    		map[24][11] = 1; map[25][11] = 1; map[26][11] = 1; map[27][11] = 1;	map[28][11] = 1; map[29][11] = 1; map[30][11] = 1; map[31][11] = 1;
     
    		return map;
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Layout Manager and Keyboard Panel

    The default value for an element in an int array is 0. You only need to set the non-zero entries.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Layout Manager and Keyboard Panel

    I am not quite sure I follow you. Are you referring to this:

    		JPanel p2 = new KeyboardPanel();
    		p2.setSize(0, 0);

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Layout Manager and Keyboard Panel

    I was referring to the massive list of assignment statements for the map array:
          int[][] map = new int[32][12];  
          map[0][0] = 1; 
          map[1][0] = 0;  //<<<<<<<<<<<<< NOT NEEDED
          map[2][0] = 0;  //<<<<<<<<<<<<< NOT NEEDED
           ....
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Layout Manager and Keyboard Panel

    Quote Originally Posted by DOLZero View Post
    I realize that my code is not optimized and looks pretty sloppy at the moment. That is not something I am worried about right now as I can always go through and clean it up once I get everything working properly.
    I got it. It's old code that I haven't optimized. That doesn't help me with my current issue.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Layout Manager and Keyboard Panel

    Are you asking how to get the values for component2 when executing a method in component1?

    You need a reference to component2 in component1 so that the methods in component1 can use that reference to call methods in component2.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Layout Manager and Keyboard Panel

    I think I figured out a way to do what you are suggesting. I created a JFrame variable to use as the general frame and made it static so I could access it anywhere in the code. It seems to work, although I need to fix some of the math in the KeyboardPanel() section of code. Sometimes it just takes a little nudge in the right direction. Thanks!

    EDIT: I want to give you thanks, but I don't want to mess up that 777. That number is so pretty

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Layout Manager and Keyboard Panel

    Using static can be a problem sometimes. Pass a reference (use "this") to the constructor when you create the class that needs the reference and have the constructor save it in a class variable. Then methods in that class can use the reference to get to the other class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Problem with layout manager
    By mDennis10 in forum AWT / Java Swing
    Replies: 1
    Last Post: September 4th, 2011, 07:47 PM
  2. Layout Manager
    By mDennis10 in forum AWT / Java Swing
    Replies: 4
    Last Post: September 3rd, 2011, 10:27 PM
  3. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  4. Layout manager
    By kurt-hardy in forum AWT / Java Swing
    Replies: 3
    Last Post: January 19th, 2011, 10:25 AM
  5. float based layout manager?
    By deepthought in forum AWT / Java Swing
    Replies: 1
    Last Post: January 1st, 2011, 10:11 PM