Results 1 to 10 of 10
- 10-02-2011, 08:55 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
<identifier expected> error. please help!
I'm using BlueJ, and i'm a complete newbyJava Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class gfxUser { JFrame f = new JFrame(); GraphicsObj g = new GraphicsObj(); f.add(g); // Error is here.
with it, but I have alot of background in c# and VB, so I'm not a total idiot! :D I just wondered where this error is coming from, can you help please guyys? Thankyou!
-
Re: <identifier expected> error. please help!
You're trying to call methods outside of a method or constructor. Perhaps you want to do this in the class's constructor?
- 10-02-2011, 09:23 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: <identifier expected> error. please help!
I guess I should have been more explicit with the code. The GraphicsObj extends a JPanel, so in theory it should just be like
adding a JPanel too a Frame? The problem is that isn't working for me!
-
Re: <identifier expected> error. please help!
That has no bearing on the problem. Again, you're trying to make method calls outside of a constructor or method. Again, you must make these calls inside of a constructor or method. Please let me know if you don't understand this as it is a fundamental concept in Java.
- 10-02-2011, 10:05 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: <identifier expected> error. please help!
Ah. In that case please tell me what you mean by Methods and constructors. Thankyou! :)
-
Re: <identifier expected> error. please help!
What text or tutorial are you using to learn Java as surely it will describe these things for you. If not, I'm very surprised, but you could also look at the Oracle Java tutorials here: Methods, Constructors
- 10-02-2011, 10:09 PM #7
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: <identifier expected> error. please help!
Sorry! Just dawned on me!! False alarm :)
-
Re: <identifier expected> error. please help!
So you understand? If not:
Java Code:public class Foo { // variables can be declared or declared and initialized here: int a; // declared int b = 3; // declared and initialized, // but that's it. You can't do: b = b + 3; // *** illegal *** // but must do it in a method or constructor: public void myMethod() { b = b + 3; // this is OK } }
- 10-02-2011, 10:18 PM #9
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: <identifier expected> error. please help!
While we're here, I've just realised, obviously, that everything needs to be in a method. Completely rookie mistake on my part, sorry! One more thing though, and that's actually going about calling it.
Basically, I dont know how to call this. It asks for a parameter of type Graphics, but whenever I try to pass it one when it's called it says that Graphics is an abstract and can not be instantiated. Any help?Java Code:public class GraphicsObj extends JPanel { public void paint(Graphics g) { // Set up Graphics object. super.paintComponent(g); this.setBackground(Color.WHITE); g.setColor(Color.blue); // Set Constants. final int XCOORD = 50; final int YCOORD = 50; final int RAD = 30; double xCurCoord = 0; double yCurCoord = 0; // Draw Circle using Circle Theorem. for(int t=0;t<=360;t++) { xCurCoord = XCOORD + (RAD * Math.cos(Math.toRadians(t))); yCurCoord = YCOORD + (RAD * Math.sin(Math.toRadians(t))); g.drawLine(XCOORD,YCOORD,(int)xCurCoord,(int)yCurCoord); } } }
- 10-02-2011, 10:23 PM #10
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Similar Threads
-
identifier expected error
By Java Learner in forum New To JavaReplies: 1Last Post: 04-27-2010, 08:13 PM -
Error:identifier expected(Help!)
By chhoton in forum New To JavaReplies: 8Last Post: 09-22-2009, 04:42 PM -
getting identifier expected error . help me !
By victorkeath in forum New To JavaReplies: 3Last Post: 11-07-2008, 05:49 PM -
Identifier expected error
By vasu18 in forum New To JavaReplies: 1Last Post: 01-01-2008, 05:49 PM -
Error: <identifier> expected
By barney in forum AWT / SwingReplies: 2Last Post: 07-31-2007, 07:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks