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

Thread: Im new to Java and have an error i cannot fix please help

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Im new to Java and have an error i cannot fix please help

    This is my code I will highlight the error please help thanks
    -------------------------------------------------------------------
    package minecrafttwod;
    import java.applet.*;
    import javax.swing.*;
    import java.awt.*;
    public class Component extends Applet implements Runnable{
    private final long serialVersionUID = 1l;
    private static int pixelsize = 2;
    public static Dimension size = new Dimension(700, 550);
    public static Dimension pixel = new Dimension(size.width / pixelsize, size.height / pixelsize);
    public static String name = "DigBlocks";
    public static boolean isRunning = false;
    private Image screen;
    public Component(int width, int height){

    }
    public Component(){
    setPreferredSize(size);
    }
    public void start(){
    //Defining objects etc
    //Starting game loop
    isRunning = true;
    new Thread(this).start();
    }
    public void stop(){
    isRunning = false;
    }
    public static void main(String args[]){
    Component component = new Component();
    JFrame frame = new JFrame();
    frame.add(component);
    frame.pack();
    frame.setTitle(name);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setVisible(true);
    component.start();
    }
    public void tick(){

    }
    public void render(){
    Graphics g = screen.getGraphics();
    //Drawing things
    g.setColor(new Color(255, 100, 100));
    g.fillRect(0. 0, 100, 100);
    }
    public void run() {
    screen = createVolatileImage(pixel.width, pixel.height);
    while(isRunning){
    tick();
    render();
    try{
    Thread.sleep(5);
    }catch(Exception e) {}
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Im new to Java and have an error i cannot fix please help

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member Spencer4908's Avatar
    Join Date
    Jul 2014
    Location
    UTAH, USA
    Posts
    10
    My Mood
    Cheerful
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Im new to Java and have an error i cannot fix please help

    I see two mistypes right off the bat.

    Where you have g.fillRect() you have a period instead of a comma. And this may just be how you pasted it but where you have your DefaultCloseOperation you have a space where E is on CLOSE for EXIT_ON_CLOSE.

    Like Norm said, if you give us the error we can further understand your problem. Also it is much easier to read your code when you use the code tags, it keeps the formatting the way it should be.

    Hope that helps.

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

    blockmaster2001 (July 6th, 2014)

  5. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Im new to Java and have an error i cannot fix please help

    Thanks this helped the exit on close on close was fine I just copied it wrong that was very helpful I am new and its nice to know there are people about there that can help me with my goals

  6. #5
    Junior Member Spencer4908's Avatar
    Join Date
    Jul 2014
    Location
    UTAH, USA
    Posts
    10
    My Mood
    Cheerful
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Im new to Java and have an error i cannot fix please help

    No problem, glad I could help.

Similar Threads

  1. [SOLVED] My code is 99%, 1 error I can't fix, can you?
    By devin.odriscoll in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 13th, 2013, 02:55 PM
  2. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 24th, 2013, 01:49 PM
  3. Cant fix this error... Help!
    By Hypermegazord in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 1st, 2012, 01:06 PM
  4. Need Help, Not sure how to fix basic error!
    By ChicoTheMan94 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2012, 01:41 PM
  5. Simply error; can't quite fix it.
    By JRabbit in forum Android Development
    Replies: 1
    Last Post: March 19th, 2012, 06:46 PM

Tags for this Thread