Results 1 to 10 of 10
  1. #1
    rtkwar is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Exclamation Ican't Learn Java!!

    Hi I have my own mmo game on my web site iwant develop it from php to java
    i downloaded many books about java but every time i try example from this books i get errors
    that is make my morale decrease
    Why Ican't learn Java?

    example: itry this code but iget error
    Java Code:
    import javax.swing.*;
    import java.awt.*;
     
    public class UsingFonts extends JFrame
    {
        public UsingFonts()
        {
            super("Using Fonts");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setResizable(false);
            getContentPane().setLayout(null);
            getContentPane().add(new FontArea(new Rectangle(0, 0,
                 DISPLAY_WIDTH, DISPLAY_HEIGHT)));
        
            smallFont = new Font("Courier New", Font.BOLD, 12);
            mediumFont = new Font("Times New Roman", Font.PLAIN, 24);
            largeFont = new Font("Verdana", Font.BOLD+Font.ITALIC, 36);
     
            setVisible(true);
     
            resizeToInternalSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
        }
            
       
        public void resizeToInternalSize(int internalWidth, int
               internalHeight)
        {
            Insets insets = getInsets();
            final int newWidth = internalWidth + insets.left +
                  insets.right;
            final int newHeight = internalHeight + insets.top +
                  insets.bottom;
        
            Runnable resize = new Runnable()
            {
                public void run()
                {
                    setSize(newWidth, newHeight);
                }
            };
        
            if(!SwingUtilities.isEventDispatchThread())
            {
                try
                {
                    SwingUtilities.invokeAndWait(resize);
                }
                catch(Exception e) {}
            }
            else
                resize.run();
            
            validate();
        }
        
        public class FontArea extends JPanel
        {
            public FontArea(Rectangle bounds)
            {
                setLayout(null);
                setBounds(bounds);
                setOpaque(false);
            }
        
            public void paintComponent(Graphics g)
            {
                Graphics2D g2D = (Graphics2D)g;
     
                g2D.setColor(Color.black);
                g2D.fill(getBounds());
     
                g2D.setColor(Color.cyan);
                g2D.setFont(smallFont);
                drawFromPoint("This is the standard coding font from top
                    left (0, 0)", 0, 0, -1, -1, g);
        
                g2D.setColor(Color.red);
                g2D.setFont(mediumFont);
                drawFromPoint(" text from bottom right ("+getWidth()+",
                    "+getHeight()+")", getWidth(), getHeight(), 1, 1, g);
        
                g2D.setColor(Color.green);
                g2D.setFont(largeFont);
                drawFromPoint("text in the middle", getWidth()/2,
                    getHeight()/2, 0, 0, g);
            }
        }
     
       
        public static void drawFromPoint(String text, int x, int y, int
                relativeToX, int relativeToY, Graphics g)
        {
            int widthOffset;
            int heightOffset;
     
            FontMetrics fm = g.getFontMetrics();
     
            if(relativeToX < 0)
                widthOffset = 0;   // left point x
            else if(relativeToX==0)
                widthOffset = -(fm.stringWidth(text)/2); // from middle x
            else       // relativeToX > 0
                widthOffset = -fm.stringWidth(text);     // from right x
     
            if(relativeToY < 0)
                heightOffset = fm.getAscent();   // from top y
            else if(relativeToY==0)
                heightOffset = (fm.getHeight()/2)-fm.getDescent(); 
                 // from middle y
            else // relativeToY > 0
                heightOffset = -fm.getDescent(); // from bottom y
     
            x+=widthOffset;
            y+=heightOffset;
     
            g.drawString(text, x, y);
        }
        
        public static void main(String[] args)
        {
            new UsingFonts();
        }
        
        private Font smallFont;
        private Font mediumFont;
        private Font largeFont;
        
        private static final int DISPLAY_WIDTH = 400;
        private static final int DISPLAY_HEIGHT = 400;
    }
    Error
    Java Code:
    C:\mywork>javac UsingFonts.java
    UsingFonts.java:74: error: unclosed string literal
                drawFromPoint("This is the standard coding font from top
                              ^
    UsingFonts.java:74: error: ';' expected
                drawFromPoint("This is the standard coding font from top
                                                                        ^
    UsingFonts.java:75: error: ')' expected
                    left (0, 0)", 0, 0, -1, -1, g);
                           ^
    UsingFonts.java:75: error: not a statement
                    left (0, 0)", 0, 0, -1, -1, g);
                         ^
    UsingFonts.java:75: error: not a statement
                    left (0, 0)", 0, 0, -1, -1, g);
                             ^
    UsingFonts.java:75: error: ';' expected
                    left (0, 0)", 0, 0, -1, -1, g);
                              ^
    UsingFonts.java:75: error: unclosed string literal
                    left (0, 0)", 0, 0, -1, -1, g);
                               ^
    UsingFonts.java:79: error: unclosed string literal
                drawFromPoint(" text from bottom right ("+getWidth()+",
                                                                     ^
    UsingFonts.java:79: error: ';' expected
                drawFromPoint(" text from bottom right ("+getWidth()+",
                                                                       ^
    UsingFonts.java:80: error: illegal start of expression
                    "+getHeight()+")", getWidth(), getHeight(), 1, 1, g);
                                   ^
    UsingFonts.java:80: error: unclosed string literal
                    "+getHeight()+")", getWidth(), getHeight(), 1, 1, g);
                                    ^
    11 errors
    
    C:\mywork>
    Last edited by JosAH; 08-15-2012 at 10:01 PM. Reason: changed [quote] tags to [code] tags

  2. #2
    rtkwar is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: Ican't Learn Java!!

    All i want learn how i can write text inside applet!!!
    I don't Know Whats I make When Reach to datebase level!! I hope I can Learn Java Without Problems

  3. #3
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Ican't Learn Java!!

    First, calm down (and I don't mean that in a flippant manner).

    Next, start with the basics: Hello World Tutorial

    If you want to learn Java, you need to start from the bottom and learn the syntax first. Once you know the basics, you will be able to understand what the errors are telling you (and why they are telling you things). Then you can start learning about graphics.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  4. #4
    rtkwar is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: Ican't Learn Java!!

    you can tell me what error in this code?
    really iwant learn java but iwant sure if examples in book work good first or no
    i read from this book:Java 1.4 Game Programming
    i want know if this book good for learn java or no?

  5. #5
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: Ican't Learn Java!!

    You have a mmo? can you put up a link to it? I kind of want to see what you have designed so far.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  6. #6
    rtkwar is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: Ican't Learn Java!!

    i programming my mmo with php not java
    sorry friends but i want sure if book is good for learn because iam not english so i take time for translate and understand

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: Ican't Learn Java!!

    Check your double quotes (they're paired); in your code there's one missing somehwere and it makes your compiler puke.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Ican't Learn Java!!

    Quote Originally Posted by rtkwar View Post
    you can tell me what error in this code?
    really iwant learn java but iwant sure if examples in book work good first or no
    i read from this book:Java 1.4 Game Programming
    i want know if this book good for learn java or no?
    The error messages already tell you what is wrong with your code. If you learn the syntax of Java, then you should be able to understand the messages.

    For your book, I suggest that you learn from a source that is more up to date. The current version of Java is 7.6, whereas 1.4 is 3 releases behind (I know, a bit confusing). This is the official tutorial from Oracle, and there are plenty of books that you can use such as Sam's Teach Yourself Java in 21 Days.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Ican't Learn Java!!

    The beginning and ending "s should be on the same line
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Ican't Learn Java!!

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Looking to learn Java.
    By Pwhheee in forum New To Java
    Replies: 6
    Last Post: 10-08-2014, 06:07 PM
  2. Looking for best way to learn Java..?
    By kraigballa in forum New To Java
    Replies: 6
    Last Post: 10-09-2011, 12:58 AM
  3. New to Java, Please help me learn!
    By JojoDiaz in forum New To Java
    Replies: 7
    Last Post: 09-30-2011, 06:17 AM
  4. learn java
    By bishwa bhushan in forum New To Java
    Replies: 1
    Last Post: 09-04-2011, 09:59 PM
  5. What's the best way to learn Java
    By gkoef in forum New To Java
    Replies: 1
    Last Post: 11-11-2010, 07:37 PM

Posting Permissions

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