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 15 of 15

Thread: Won't load next class...

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Won't load next class...

    Okay, so I'm making a small game in which you have to go through a maze and get to the end to get to the next level. So far I have 2 levels and both work when set to be played. What I can't seem to get to work is when level1 is finished, loading level two. Both levels work when they are set to true, it's just switching between them while the program is running that I can't seem to do.

    Here's the Board class, if you want any more code if you think that could help, just ask.
    (I know some of my methods may not be the most efficient, but this is my first actual program without tutorials etc.)
    package maze;
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
     
    import java.util.ArrayList;
     
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
     
     
    import maze.Level1;
    import maze.Player;
     
     
     
    public class Board extends JPanel implements ActionListener {
     
     
    	private Image wall;
     
     
    	private int B_WIDTH;
        private int B_HEIGHT;
     
     
    	private Timer timer;
    	private Player player;
     
     
    	boolean level1 = true;
    	boolean level2 = false;	
     
    	Level1 level1Obj = new Level1();
    	Level2 level2Obj = new Level2();
     
     
    	 public Board() {
     
     
    		 ImageIcon ii = new ImageIcon(this.getClass().getResource("wall.png"));
    	    	wall = ii.getImage();
     
    		 addKeyListener(new TAdapter());
    		 player = new Player();
     
     
    		 if(level1){
    		 if(level1Obj.wallUp){
    				player.level1wall = true;
    			}
    		if(level1Obj.wallUp==false){
    					player.level1wall = false;
    				}
    		 }
     
    		 timer = new Timer(5, this);
    	        timer.start();
     
    	     if(level1Obj.wallUp){
    	    	 player.level1collision();
    	     }
     
    	    setFocusable(true);
    	    setBackground(Color.DARK_GRAY);
    	    setDoubleBuffered(true);
    	    setSize(400, 300);
     
     
    	}
     
    	 public void addNotify() {
    	        super.addNotify();
    	        B_WIDTH = getWidth();
    	        B_HEIGHT = getHeight();   
    	    }
     
     
     
    	public void paint(Graphics g) 
    	{
    		super.paint(g);			
    		Graphics2D g2d = ( Graphics2D )g; 
     
     
     
     
    			if(level1){
     
    				level1Obj.paintComponent(g);
     
    			}
     
     
    			if(level2){
     
    				level2Obj.paintComponent(g);
     
    			}
    		for(int i = 0; i <= 18; i++){
     
    			g2d.drawImage(wall, i*30, 0, this);
        		g2d.drawImage(wall, i*30, 540, this);
        		g2d.drawImage(wall, 0, i*30, this);
        		g2d.drawImage(wall, 570, i*30, this);
    		}
     
     
    		g2d.drawImage(player.getImage(), player.getX(), player.getY(), this);
     
    		Toolkit.getDefaultToolkit().sync();
     
     
    	}
    	public void actionPerformed(ActionEvent e) {
    		player.move();
            player.collision();
            collision();
            repaint();  
     
        }
     
     
    	public void collision(){
    		Rectangle r1 = player.getBounds();
     
    		if(level1){
    			Rectangle r2 = level1Obj.getBounds();
     
    			Rectangle r3 = level1Obj.getBounds1();
    			Rectangle r4 = level1Obj.getBounds2();
     
    			if(r1.intersects(r2)){
    				level1Obj.wallUp = false;
     
    			}
    			if(r1.intersects(r3)){
    				if(level1Obj.wallUp){
    					player.dx = 0;
    					player.rightTrue = false;
    				}
    			}
     
    			if(r1.intersects(r4)){
    				player.x = 40;
    				player.y = 500;
    				level1=false;
    				level2 = true;
     
     
     
     
     
    			}
     
     
    		}
     
    		if(level2==true){
     
    			Rectangle r5 = level2Obj.getBounds();
    			Rectangle r6 = level2Obj.getBounds1();
    			Rectangle r7 = level2Obj.getBounds2();
    			Rectangle r8 = level2Obj.getBounds5();
    			Rectangle r9 = level2Obj.getBounds7();
     
    			Rectangle b1 = level2Obj.getBounds3();
    			Rectangle b2 = level2Obj.getBounds4();
    			Rectangle b3 = level2Obj.getBounds6();
     
    			Rectangle e = level2Obj.getBounds8();
     
    			if(r1.intersects(r5) || r1.intersects(r6)){
    					player.level2collision();
    			}
    			if(level2Obj.button1){
    				if(r1.intersects(r7)){
    					player.dy = 0;
    					player.upTrue = false;
    				}
    			}
    			if(r1.intersects(b1)){
    				level2Obj.button1 = false;
    			}
    			if(level2Obj.button2){
    				if(r1.intersects(r8)){
    					player.level2collision();
    				}
    			}
    			if(r1.intersects(b2)){
    				level2Obj.button2 = false;
    			}
    			if(level2Obj.button3){
    				if(r1.intersects(r9)){
    					player.level2collision();
    				}
    			}
    			if(r1.intersects(b3)){
    				level2Obj.button3 = false;
    			}
    			if(r1.intersects(e)){
    				level2 = false;
    				player.x = 40;
    				player.y = 500;
    			}
     
    		}
    	}
     
     
     
    	private class TAdapter extends KeyAdapter {
     
            public void keyReleased(KeyEvent e) {
                player.keyReleased(e);
            }
     
            public void keyPressed(KeyEvent e) {
                player.keyPressed(e);
            }
        }
     
    }

    Thanks for any help!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,101
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Won't load next class...

    just switching between them while the program is running that I can't seem to do.
    Have you tried debugging the code by adding some println statements to print out the values of the variables that control program flow so you can see what the computer sees and know why the code is doing what it is doing?

    The posted code doesn't compile because of missing classes.
    Also it does not have a main() method for testing.
    Last edited by Norm; September 19th, 2012 at 05:27 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Won't load next class...

    I will try the adding some print statements.

    The main method is in a seperate class which then calls this class.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Won't load next class...

    Quote Originally Posted by Huw View Post
    The main method is in a seperate class which then calls this class.
    Each class could(should) have its own main method, even if it was there just for testing the class

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Won't load next class...

    Quote Originally Posted by jps View Post
    Each class could(should) have its own main method, even if it was there just for testing the class
    If they all had main methods, how would the program know which to run, or am I just being stupid here?
    I don't know alot about java since I've learnt on the Internet using different tutorials etc.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,101
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Won't load next class...

    Each class can only have ONE main() method. When you start a program you specify the class to start execution with. Its main() method is the one that is executed.

    Having a main() method in a class allows it to be tested as a single program so its methods can be called and tested individually without having any other classes involved.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Won't load next class...

    I've added a main method to the class, but I still don't see how I'm going to get the class to 'restart' but with level2 true, I'm sorry if I seem really stupid with these questions.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,101
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Won't load next class...

    Can you post code that will compile and execute for testing?

    Have you tried debugging the code by adding some println statements to print out the values of the variables that control program flow so you can see what the computer sees and know why the code is doing what it is doing?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Won't load next class...

    I think I've found that its the paint method which isn't being called again after level2 is true.

    Here's all the code:

    Maze:
    package maze;
     
    import javax.swing.JFrame;
     
    public class Maze extends JFrame {
     
        public Maze() {
     
        	add(new Board());
     
     
        		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        		setSize(600, 600);
        		setLocationRelativeTo(null);
        		setTitle("Maze");
     
        		setResizable(false);
        		setVisible(true);
     
     
     
     
     
     
     
     
        }
     
        public static void main(String[] args) {
     
        		new Maze();
     
     
        }
    }

    Board

    package maze;
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
     
    import java.util.ArrayList;
     
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
     
     
    import maze.Level1;
    import maze.Player;
     
     
     
    public class Board extends JPanel implements ActionListener {
     
     
    	private Image wall;
     
     
    	private int B_WIDTH;
        private int B_HEIGHT;
     
     
    	private Timer timer;
    	private Player player;
     
     
    	boolean level1 = true;
    	boolean level2 = false;	
     
    	Level1 level1Obj = new Level1();
    	Level2 level2Obj = new Level2();
     
     
    	 public Board() {
     
     
    		 ImageIcon ii = new ImageIcon(this.getClass().getResource("wall.png"));
    	    	wall = ii.getImage();
     
    		 addKeyListener(new TAdapter());
    		 player = new Player();
     
     
    		 if(level1){
    		 if(level1Obj.wallUp){
    				player.level1wall = true;
    			}
    		if(level1Obj.wallUp==false){
    					player.level1wall = false;
    				}
    		 }
     
    		 timer = new Timer(5, this);
    	        timer.start();
     
    	     if(level1Obj.wallUp){
    	    	 player.level1collision();
    	     }
     
    	    setFocusable(true);
    	    setBackground(Color.DARK_GRAY);
    	    setDoubleBuffered(true);
    	    setSize(400, 300);
     
     
    	}
     
    	 public void addNotify() {
    	        super.addNotify();
    	        B_WIDTH = getWidth();
    	        B_HEIGHT = getHeight();   
    	    }
     
    	 public void paint(Graphics g) 
    		{
    			super.paint(g);			
    			Graphics2D g2d = ( Graphics2D )g; 
     
     
     
     
    				if(level1==true){
     
    					level1Obj.paintComponent(g);
     
    				}
     
     
    				if(level2==true){
     
    					level2Obj.paintComponent(g);
    					System.out.println("painting");
     
    				}
    			for(int i = 0; i <= 18; i++){
     
    				g2d.drawImage(wall, i*30, 0, this);
    	    		g2d.drawImage(wall, i*30, 540, this);
    	    		g2d.drawImage(wall, 0, i*30, this);
    	    		g2d.drawImage(wall, 570, i*30, this);
    			}
     
     
    			g2d.drawImage(player.getImage(), player.getX(), player.getY(), this);
     
    			Toolkit.getDefaultToolkit().sync();
     
     
    		}
     
     
     
    	public void actionPerformed(ActionEvent e) {
    		player.move();
            player.collision();
            collision();
            repaint();  
     
        }
     
     
    	public void collision(){
    		Rectangle r1 = player.getBounds();
     
    		if(level1){
    			Rectangle r2 = level1Obj.getBounds();
     
    			Rectangle r3 = level1Obj.getBounds1();
    			Rectangle r4 = level1Obj.getBounds2();
     
    			if(r1.intersects(r2)){
    				level1Obj.wallUp = false;
     
    			}
    			if(r1.intersects(r3)){
    				if(level1Obj.wallUp){
    					player.dx = 0;
    					player.rightTrue = false;
    				}
    			}
     
    			if(r1.intersects(r4)){
    				player.x = 40;
    				player.y = 500;
    				level1=false;
    				level2 = true;
    				System.out.println("level2");
     
    			}
     
     
    		}
     
    		if(level2==true){
     
    			System.out.println("collision");
    			Rectangle r5 = level2Obj.getBounds();
    			Rectangle r6 = level2Obj.getBounds1();
    			Rectangle r7 = level2Obj.getBounds2();
    			Rectangle r8 = level2Obj.getBounds5();
    			Rectangle r9 = level2Obj.getBounds7();
     
    			Rectangle b1 = level2Obj.getBounds3();
    			Rectangle b2 = level2Obj.getBounds4();
    			Rectangle b3 = level2Obj.getBounds6();
     
    			Rectangle e = level2Obj.getBounds8();
     
    			if(r1.intersects(r5) || r1.intersects(r6)){
    					player.level2collision();
    			}
    			if(level2Obj.button1){
    				if(r1.intersects(r7)){
    					player.dy = 0;
    					player.upTrue = false;
    				}
    			}
    			if(r1.intersects(b1)){
    				level2Obj.button1 = false;
    			}
    			if(level2Obj.button2){
    				if(r1.intersects(r8)){
    					player.level2collision();
    				}
    			}
    			if(r1.intersects(b2)){
    				level2Obj.button2 = false;
    			}
    			if(level2Obj.button3){
    				if(r1.intersects(r9)){
    					player.level2collision();
    				}
    			}
    			if(r1.intersects(b3)){
    				level2Obj.button3 = false;
    			}
    			if(r1.intersects(e)){
    				level2 = false;
    				player.x = 40;
    				player.y = 500;
    			}
     
    		}
    	}
     
     
     
    	private class TAdapter extends KeyAdapter {
     
            public void keyReleased(KeyEvent e) {
                player.keyReleased(e);
            }
     
            public void keyPressed(KeyEvent e) {
                player.keyPressed(e);
            }
        }
     
     
     
     
    }

    Player

    package maze;
     
    import java.awt.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.event.KeyEvent;
    import java.awt.Rectangle;
     
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
     
    public class Player extends JPanel {
     
     
        private Image buckysFront;
        private Image buckysLeft;
        private Image buckysRight;
        private Image buckysBack;
     
     
        private boolean playerUp = true;
        private boolean playerDown = false;
        private boolean playerLeft = false;
        private boolean playerRight = false;
        boolean leftTrue = true;
        boolean rightTrue = true;
        boolean upTrue = true;
        boolean downTrue = true;
        boolean level1 = true;
        boolean level1wall = true;
     
     
        int dx;
        int dy;
        private int width;
        private int height;
        int x;
        int y;
     
     
     
        public Player() {
        	x = 40;
            y = 500;
     
     
     
            ImageIcon iibB = new ImageIcon(this.getClass().getResource("buckysBack.png"));
            	buckysBack = iibB.getImage();
     
            ImageIcon iibF = new ImageIcon(this.getClass().getResource("buckysFront.png"));
            	buckysFront = iibF.getImage();
     
        	ImageIcon iibL = new ImageIcon(this.getClass().getResource("buckysLeft.png"));
        		buckysLeft = iibL.getImage();
     
        	ImageIcon iibR = new ImageIcon(this.getClass().getResource("buckysRight.png"));
        		buckysRight = iibR.getImage();
     
        	width = buckysBack.getWidth(null);
        	height = buckysBack.getHeight(null);
     
        }
     
     
        public void move() {
            x += dx;
            y += dy;
        }
     
        public int getX() {
            return x;
        }
     
        public int getY() {
            return y;
        }
        public void collision(){
        	if(getX()<30){
        		dx = 0;
        		leftTrue = false;
        	}
        	if(getX()>540){
        		dx = 0;
        		rightTrue = false;
        	}
        	if(getY()<30){
        		dy = 0;
        		upTrue = false;
        	}
        	if(getY()>509){
        		dy = 0;
        		downTrue = false;
        	}
     
        }
     
        	public void level1collision(){
        			if(getX()>90){
        				dx = 0;
        				rightTrue = false;
        			}
        		}
     
        	public void level2collision(){
        		if(playerRight){
        			dx = 0;
        			x = x-1;
        			rightTrue = false;
        		}
        		if(playerLeft){
        			dx = 0;
        			x = x+1;
        			leftTrue = false;
        		}
        		if(playerUp){
        			dy = 0;
        			y = y+1;
        			upTrue = false;
        		}
        		if(playerDown){
        			dy = 0;
        			y = y-1;
        			downTrue = false;
        		}
        	}
     
     
     
     
        public Image getImage() {
        	if(playerUp){
            return buckysBack;
        	}
        	if(playerDown){
        		return buckysFront;
        	}
        	if(playerLeft){
        		return buckysLeft;
        	}
        	return buckysRight;
        }
     
        public Rectangle getBounds() {
            return new Rectangle(x, y, width, height);
        }
     
     
        public void keyPressed(KeyEvent e) {
     
            int key = e.getKeyCode();
     
            if(leftTrue){
            if (key == KeyEvent.VK_LEFT) {
                dx = -1;
                playerLeft = true;
                playerRight = false;
                playerUp = false;
                playerDown = false;
                rightTrue = true;
                upTrue = true;
                downTrue = true;
     
            }
    }
            if(rightTrue){
            if (key == KeyEvent.VK_RIGHT) {
                dx = 1;
                playerLeft = false;
                playerRight = true;
                playerUp = false;
                playerDown = false;
                leftTrue = true; 
                upTrue = true;
                downTrue = true;
            }
            }
     
            if(upTrue){
            if (key == KeyEvent.VK_UP) {
                dy = -1;
                playerLeft = false;
                playerRight = false;
                playerUp = true;
                playerDown = false;
                leftTrue = true;
                rightTrue = true;
                downTrue = true;
     
            }
            }
     
            if(downTrue){
            if (key == KeyEvent.VK_DOWN) {
                dy = 1;
                playerLeft = false;
                playerRight = false;
                playerUp = false;
                playerDown = true;
                leftTrue = true;
                rightTrue = true;
                upTrue = true;
            }
            }
            if(dx==1 && dy==1){
            	dx = 0;
            	dy = 0;
            }
            if(dx==1 && dy==-1){
            	dx = 0;
            	dy = 0;
            }
            if(dx==-1 && dy==1){
            	dx = 0;
            	dy = 0;
            }
            if(dx==-1 && dy==-1){
            	dx = 0;
            	dy = 0;
            }
        }
     
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
     
            if (key == KeyEvent.VK_LEFT) {
                dx = 0;
            }
     
            if (key == KeyEvent.VK_RIGHT) {
                dx = 0;
            }
     
            if (key == KeyEvent.VK_UP) {
                dy = 0;
            }
     
            if (key == KeyEvent.VK_DOWN) {
                dy = 0;
            }
        }
     
     
    }

    Level1
    package maze;
     
    import java.awt.*;
     
     
     
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
     
    import maze.Player;
     
    public class Level1 extends JPanel {
     
    	private Image wall;
    	private Image greenButton;
    	private Image walls;
    	private Image end;
     
     
        private int x;
        private int y;
        private int width;
        private int height;
     
        private Player player;
     
        boolean wallUp = true;
     
    	public Level1(){
     
     
    		player = new Player();
     
     
     
        ImageIcon iiw = new ImageIcon(this.getClass().getResource("walls.png"));
        	walls = iiw.getImage();
     
        ImageIcon iigB = new ImageIcon(this.getClass().getResource("greenButton.png"));
        	greenButton = iigB.getImage();
     
        ImageIcon iie = new ImageIcon(this.getClass().getResource("finishHole.png"));
        	end = iie.getImage();
     
     
     
     
    	width = walls.getWidth(null);
    	height = walls.getHeight(null);
     
    	}
    	public Rectangle getBounds2() {
    		return new Rectangle(540, 510, 30, 30);
    	}
    	public Rectangle getBounds1() {
    		return new Rectangle(120, 0, width, height);
    	}
     
    	public Rectangle getBounds() {
            return new Rectangle(60, 60, 30, 30);
        }
     
    	public void paintComponent(Graphics g) 
    	{
    		super.paintComponents(g);			
    		Graphics2D g2 = ( Graphics2D )g;
     
    		g2.drawImage(greenButton, 60, 60, this);
    		g2.drawImage(end, 540, 510, this);
    		if(wallUp){
    			g2.drawImage(walls, 120, 0, this);
    		}
     
     
      }
     
     
    }

    Level2
    package maze;
     
    import java.awt.*;
     
     
     
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
     
    import maze.Player;
     
    public class Level2 extends JPanel {
     
    	private Image greenButton;
    	private Image end;
    	private Image wallHalf;
    	private Image wallHalfSide;
     
    	boolean button1 = true;
    	boolean button2 = true;
    	boolean button3 = true;
     
    	public Level2(){
     
     
        ImageIcon iigB = new ImageIcon(this.getClass().getResource("greenButton.png"));
        	greenButton = iigB.getImage();
     
        ImageIcon iie = new ImageIcon(this.getClass().getResource("finishHole.png"));
        	end = iie.getImage();
     
        ImageIcon iiwh = new ImageIcon(this.getClass().getResource("wallhalf.png"));
        	wallHalf = iiwh.getImage();
     
        ImageIcon iiwhs = new ImageIcon(this.getClass().getResource("wallhalfside.png"));
        	wallHalfSide = iiwhs.getImage();
     
     
    	}
    	public Rectangle getBounds8(){
    		return new Rectangle(540, 510, 30, 30);
    	}
    	public Rectangle getBounds7(){
    		return new Rectangle(540, 30, 210, 330);
    	}
     
    	//green button in room 3
    	public Rectangle getBounds6(){
    		return new Rectangle(60, 60, 30, 30);
    	}
    	public Rectangle getBounds5(){
    		return new Rectangle(-30, 240, 30, 270);
    	}
    	//green button in room2
    		public Rectangle getBounds4() {
    			return new Rectangle(390, 60, 30, 30);
    		}
     
    	//green button in room1
    	public Rectangle getBounds3() {
    		return new Rectangle(180, 510, 30, 30);
    	}
     
    	public Rectangle getBounds2() {
    		return new Rectangle(0, 330, 270, 30);
    	}
    	public Rectangle getBounds1() {
    		return new Rectangle(210, 360, 30, 270);
    	}
     
    	public Rectangle getBounds() {
            return new Rectangle(210, 0, 30, 270);
        }
     
     
    	public void paintComponent(Graphics g) 
    	{
    		super.paintComponents(g);			
    		Graphics2D g2d = ( Graphics2D )g;
     
    		g2d.drawImage(greenButton, 60, 60, this);
    		g2d.drawImage(greenButton, 180, 510, this);
    		g2d.drawImage(greenButton, 390, 60, this);
    		g2d.drawImage(end, 540, 510, this);
    		g2d.drawImage(wallHalf, 210, 0, this);
    		g2d.drawImage(wallHalf, 210, 360, this);
     
     
    		if(button1){
    			g2d.drawImage(wallHalfSide, 0, 330, this);
    		}
    		if(button2){
    			g2d.drawImage(wallHalfSide, -30, 240, this);
    		}
    		if(button3){
    			g2d.drawImage(wallHalfSide, 210, 330, this);
    			g2d.drawImage(wallHalfSide, 450, 330, this);
    		}
     
     
     
      }
     
     
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,101
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Won't load next class...

    its the paint method which isn't being called again
    Does the code call repaint() when you want the paint() method to be called?

    Where are the println statements to print out the values of the variables that control the program execution?
    Last edited by Norm; September 20th, 2012 at 10:46 AM. Reason: Note re println
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Won't load next class...

    Quote Originally Posted by Norm View Post
    Does the code call repaint() when you want the paint() method to be called?
    I just tried calling repaint() in the method which changes the level, but I don't think any of my methods have 'if(level2==true)' are being run for some reason, so I think it might be a problem to do with setting level2 to true?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,101
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Won't load next class...

    Where are the println statements to print out the values of the variables that control the program execution so you can debug the code?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Won't load next class...

    I think I may have got it to work!

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,101
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Won't load next class...

    Add lots more printlns to print out the values of the variables that control the execution of the code that you want executed.

    The timer period is probably too short. You should only call repaint() when something being drawn changes location. The current code is calling repaint() too often.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Won't load next class...

    Quote Originally Posted by Huw View Post
    If they all had main methods, how would the program know which to run, or am I just being stupid here?
    It is a good question, and the answer is, you specify which class the program will start with, and the main method of that class will be called.

    So for example, if you had another class which also had a main method, that main method would just never be called unless you called it somewhere in your code that is executing. (which you can and likely will do eventually)

Similar Threads

  1. Replies: 4
    Last Post: September 3rd, 2012, 02:47 AM
  2. won't load png
    By NewAtJava in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 30th, 2012, 03:24 PM
  3. How to load class path for .properties file
    By kewlkeny in forum Web Frameworks
    Replies: 1
    Last Post: January 23rd, 2012, 07:40 AM
  4. newbie question: Error: Could not find or load main class Java Result: 1
    By ideaman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2012, 10:40 PM
  5. how to load a class and type cast to that class?
    By chinni in forum Object Oriented Programming
    Replies: 2
    Last Post: November 9th, 2009, 09:18 AM