Results 1 to 10 of 10
Thread: Ican't Learn Java!!
- 08-15-2012, 09:46 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
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
ErrorJava 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; }
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
- 08-15-2012, 09:48 PM #2
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
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
- 08-15-2012, 09:53 PM #3
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
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
- 08-15-2012, 09:58 PM #4
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
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?
- 08-15-2012, 09:58 PM #5
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
- 08-15-2012, 10:05 PM #6
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
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
- 08-15-2012, 10:05 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 08-15-2012, 10:10 PM #8
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Ican't Learn Java!!
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
- 08-15-2012, 10:23 PM #9
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.
- 08-16-2012, 04:23 AM #10
Re: Ican't Learn Java!!
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Looking for best way to learn Java..?
By kraigballa in forum New To JavaReplies: 6Last Post: 10-09-2011, 12:58 AM -
New to Java, Please help me learn!
By JojoDiaz in forum New To JavaReplies: 7Last Post: 09-30-2011, 06:17 AM -
learn java
By bishwa bhushan in forum New To JavaReplies: 1Last Post: 09-04-2011, 09:59 PM -
What's the best way to learn Java
By gkoef in forum New To JavaReplies: 1Last Post: 11-11-2010, 07:37 PM -
Looking to learn Java.
By Pwhheee in forum New To JavaReplies: 2Last Post: 11-21-2008, 06:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks