so I have just gotten started with java programming.. and I have been following a guy on youtube, (thejavahub) and have downloaded netbeans & JDK, well, ive followed his programming while he does it on screen, but my code keeps coming up with the error "Class world is public, should be declared in a file named World.java" EVERY time I put in "public class world {" it keeps yelling at me for the word "world" and I cannot figure out what I was doing wrong, I have rewritten the script over and over, to make sure im following the youtuber's EXACT words.. then I gave up, & the next day I logged onto netbeans, and found an example of coding, so I went into it... and their example was broken with the EXACT same thing.. "Class world is public, should be declared in a file named World.java" in it was in their EXAMPLE coding! so it doesn't make any sense, ill put the example coding in and ill you can tell me what you guys think, any feedback would be EXTREMELY appreciated! thank you.
this is the code
|
V
package thejavahub; import java.awt.*; import javax.swing.ImageIcon; //this is where it is broken! ;O // | | | // V V V public class world { private Rectangle[] blocks; private Image[] blockImg; private final int arrayNum = 500; //Block images private Image BLOCK_DIRT_TOP, BLOCK_DIRT, BLOCK_STONE, BLOCK_SKY; private int x, y, xDirection, yDirection; //Map navigation static final int PAN_UP = 0, PAN_DOWN = 1, PAN_LEFT = 2, PAN_RIGHT = 3; public World(){ BLOCK_DIRT_TOP = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_topDirt1.png").getImage(); BLOCK_DIRT = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_dirt1.png").getImage(); BLOCK_STONE = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_stone.png").getImage(); BLOCK_SKY = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_sky.png").getImage(); blocks = new Rectangle[500]; blockImg = new Image[500]; loadArrays(); } private void loadArrays(){ for(int i = 0; i < arrayNum; i++){ if(x >= 500){ x = 0; y += 20; } if(i >= 0 && i < 100){ blockImg[i] = BLOCK_SKY; blocks[i] = new Rectangle(x, y, 20, 20); } if(i >= 100 && i < 125){ blockImg[i] = BLOCK_DIRT_TOP; blocks[i] = new Rectangle(x, y, 20, 20); } if(i >= 125 && i < 225){ blockImg[i] = BLOCK_DIRT; blocks[i] = new Rectangle(x, y, 20, 20); } if(i >= 225 && i < 500){ blockImg[i] = BLOCK_STONE; blocks[i] = new Rectangle(x, y, 20, 20); } x += 20; } } public void draw(Graphics g){ for(int i = 0; i < arrayNum; i++){ g.drawImage(blockImg[i], blocks[i].x, blocks[i].y, null); } } public void moveMap(){ for(Rectangle r : blocks){ r.x += xDirection; r.y += yDirection; } } public void stopMoveMap(){ setXDirection(0); setYDirection(0); } private void setXDirection(int dir){ xDirection = dir; } private void setYDirection(int dir){ yDirection = dir; } public void navigateMap(int nav){ switch(nav){ default: System.out.println("default case entered... Doing nothing."); break; case PAN_UP: setYDirection(-1); break; case PAN_DOWN: setYDirection(1); break; case PAN_LEFT: setXDirection(-1); break; case PAN_RIGHT: setXDirection(1); break; } } }