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

Thread: Importing problems

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Importing problems

    Hello!
    Something is wrong in the import section of the code, what is wrong?
    Error message: Description Resource Path Location Type
    Syntax error on tokens, delete these tokens Marmasso.java /Marmasso/src/ca/vanzeben/Marmasso line 7 Java Problem

    package ca.vanzeben.Marmasso;
     
    import java.awt.BorderLayout;
    import java.awt.Canvas;
    import java.awt.Dimension;
    import java.awt.image.BufferedImage;
    import java.awt.image.DataBufferInt;
     
    import javax.swing.JFrame;
     
    public class Marmasso 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 = "Marmasso";
     
    	private JFrame frame;
     
    	public boolean running = false;
        public int tickCount = 0;
     
        private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
        private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
     
    	public Marmasso() {
    		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);
    		frame.setLayout(new BorderLayout());
     
    		frame.add(this, BorderLayout.CENTER);
    		frame.pack();
     
    		frame.setResizable(false);
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    	}
     
     
    	public synchronized void start() {
    		running = true;
    		new Thread(this).start();
    	}
     
    	public synchronized void stop() {
    		running = false;
    	}
     
    	public void run() {
    		long lastTime = System.nanoTime();
    		double nsPerTick = 1000000000D/60D;
     
    		int ticks = 0;
    		int frames = 0;
     
    		long lastTimer = System.currentTimeMillis();
    		double delta = 0;
     
    		while(running) {
    			long now = System.nanoTime();
    			delta += (now - lastTime) / nsPerTick;
    			lastTime = now;
    			boolean shouldRender = true;
     
    			while (delta >= 1) {
    				ticks++;
    				tick();
    				delta -= 1;
    				shouldRender = true;
    			}
     
    			try {
    				Thread.sleep(1);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    			if (shouldRender) {
    			frames++;
    			render();
    			}
     
    			if (System.currentTimeMillis() - lastTimer >1000) {
                    lastTimer +=1000;
                    System.out.println(ticks + " ticks, " + frames + " frames");
                    frames = 0;
                    ticks = 0;
    			}
    		}
    	}
     
    	public void tick() {
    		tickCount++;
    	}
     
    	public void render() {
     
    	}
     
    	public static void main(String[] args) {
    		new Marmasso().start();	
    	}	
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Importing problems

    There's nothing obviously wrong with what you've posted. Look at the code in your IDE and find line 7. If line 7 is supposed to be a comment, ensure that it is properly written to be a comment. If you can't tell what's wrong with line 7, tell us which line in what you've posted is line 7. If your line 7 is not in the code you've posted, post the first 10 lines of your code and tell us which is line 7.

  3. #3
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Importing problems

    Pasting the code into Vim shows 3 hidden byte order mark characters:
    import java.awt.image.DataBufferInt;<feff><feff><feff>
    Since they're hidden, the simplest way to get rid of them is to delete the above line and the blank line beneath it, and then retype the import statement.

  4. The Following User Says Thank You to jashburn For This Useful Post:

    iMiTzi (May 11th, 2014)

Similar Threads

  1. importing other classes
    By keepStriving in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 11th, 2013, 06:02 PM
  2. Package Importing Help
    By sarwardnj in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 19th, 2013, 07:32 AM
  3. Importing images in Programs
    By n00b in forum AWT / Java Swing
    Replies: 6
    Last Post: November 4th, 2011, 11:09 AM
  4. Importing gif/pictures
    By javanerd in forum Java Theory & Questions
    Replies: 2
    Last Post: October 31st, 2010, 11:58 PM
  5. importing packages..
    By chronoz13 in forum Java IDEs
    Replies: 4
    Last Post: November 23rd, 2009, 05:49 PM