Results 1 to 3 of 3
  1. #1
    JavaNinja is offline Member
    Join Date
    Jul 2015
    Posts
    8
    Rep Power
    0

    Post Why doesn't my code run in eclipse, HELP ME PLEASE!!!!!!!!!!!!!!!!!

    when i try to run my code in eclipse it just says there is this selection can not be launched or when i try to run the whole package as an applet it says this selection doesn't contains an applet
    Java Code:
    package spaceXplorerCode;
    
    import java.awt.BorderLayout;
    import java.awt.Canvas;
    import java.awt.Dimension;
    
    import javax.swing.JFrame;
    
    public class MainGameBootFile extends Canvas implements Runnable {
    
    	private static final long serialVersionUID = 1L;
    	public static final int WIDTH = 160;
    	public static final int HEIGHT = WIDTH / 12 * 9;
    	public static final int SCALE = 3;
    	public static final String NAME = "UniCreator";
    	private JFrame frame;
    
    	public boolean running = false;
    
    	public MainGameBootFile() { // This sets the games dimensions and starts it
    								// up.
    
    		setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    		setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    		setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    
    		frame = new JFrame(NAME);
    
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Closes the
    																// Window.
    		frame.setLayout(new BorderLayout());
    
    		frame.add(this, BorderLayout.CENTER);
    		frame.pack();// Sets the size to the preferred size.
    
    		frame.setResizable(false); // This code sets it that the game can't be
    									// resizable
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    	}
    
    	public synchronized void start() {
    		new Thread(this).start();
    		running = true;
    	}
    
    	public synchronized void stop() {
    
    		running = false;
    
    	}
    
    	public void run() {
    		long lastTime = System.nanoTime();
    		double nsPerTick = 10000000D / 60D;
    
    		int frames = 0;
    		int ticks = 0;
    
    		long lastTimer = System.currentTimeMillis();
    		double delta = 0;
    		while (running) {
    		    System.out.println(frames +","+ ticks);
    			long now = System.nanoTime();
    			delta += (now - lastTime) / nsPerTick;
    			lastTime = now;
    			boolean shouldRender = false;
    			
    			while (delta >= 1) {
    				ticks++;
    				tick();
    				delta -= 1;
    				shouldRender = true;
    			}
    			if (shouldRender){
    			frames++;
    			render();
    			}
    			if (System.currentTimeMillis() - lastTimer >= 1000) {
    				lastTimer += 1000;
    				frames = 0;
    				ticks = 0;
    			}
    		}
    	}
    
    	public void tick() {
    
    	}
    
    	public void render() {
    
    	}
    
    	public void main(String[] args) {
    		new MainGameBootFile().start();
    	}
    
    }
    Last edited by JavaNinja; 08-14-2015 at 02:33 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Why doesn't my code run in eclipse, HELP ME PLEASE!!!!!!!!!!!!!!!!!

    For executing as a normal Java class, that class is missing a static main method.

    For running it as an Applet, then it needs to extend JApplet and deal with the relevant applet methods (init()?)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Why doesn't my code run in eclipse, HELP ME PLEASE!!!!!!!!!!!!!!!!!

    We all have "duh" moments. But it is interesting that you didn't know the answer to such a basic question considering some of the constructs you employed.

    Regards,
    Jim
    Last edited by jim829; 08-14-2015 at 04:31 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 0
    Last Post: 10-11-2013, 02:14 PM
  2. [ask] why doesn't eclipse show hints?
    By aegean247 in forum Eclipse
    Replies: 0
    Last Post: 08-29-2011, 08:51 PM
  3. WASCE doesn't start from Eclipse
    By daro in forum Eclipse
    Replies: 3
    Last Post: 01-08-2011, 11:43 PM
  4. Replies: 11
    Last Post: 06-09-2010, 10:58 AM
  5. Why doesn't this code accept my code?
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 01:39 PM

Tags for this Thread

Posting Permissions

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