Those classes are declared inside of another class. They need to be declared as static.Illegal static declaration in inner class Window.Point
I said that earlier in post#9
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.
Those classes are declared inside of another class. They need to be declared as static.Illegal static declaration in inner class Window.Point
I said that earlier in post#9
If you don't understand my answer, don't ignore it, ask a question.
Hmmm,I see but if i declare the classes Static I cant acceses the method fromInput? How can i make this thing draw it out,I'm really trying my hardest but I'm just so lost like what changes do i need to do in order to make the program FINALLY working
Look at post#22 for how to call the fromInput method.cant acceses the method fromInput?
What is in the In class? How are you supposed to use it to find and read the data file?
I see it is used in the fromInput methods.
If you don't understand my answer, don't ignore it, ask a question.
I tried calling the fromInput method like that and it doesn't work; If i put both the class Point as well as the fromInput method static it compiles errors.In the assignment it says that the classes Point Line Rectangle shouldn't be static,but only the fromInput methods.But even when I try it like that it still doesn't work. The In.class is used to Open and read through the txt file. The In.readInt() reads the next Integrer value it finds, the In.readChar() the next Charachter it finds.
Please explain. Copy and paste the full text of any error messages.it doesn't work
AND
it compiles errors
Here is the Point class I am using and that works://----------------------------------- static class Point { int x; int y; Point(int x, int y) { this.x = x; this.y = y; } static Point fromInput() { int x = In.readInt(); int y = In.readInt(); if (In.done()) return new Point(x, y); else return null; } public void drawMe(MyWindow mw) { //<<<<<<< ADDED mw.drawPoint(x,y); } }
If you don't understand my answer, don't ignore it, ask a question.
So if i paste this into the code with the class Window and all of that it should work? Okay i will try and let you know what happens
Probably not. There needs to be changes to all the classes as per the Point class example.all of that it should work
Compare my code with yours in post#16.
If you don't understand my answer, don't ignore it, ask a question.
Yea yea I got that I need to do it for all classes like you did for Point.Sorry my laptop ran out of batter I'll try it now.
--- Update ---
Window.java:323: error: cannot find symbol
public void drawMe(MyWindow mw) { //<<<<<<< ADDED
^
symbol: class MyWindow
location: class Point
Window.java:405: error: cannot find symbol
w.drawCircle(x, y, r );
^
symbol: variable w
location: class Circle
Window.java:419: error: cannot find symbol
r.draw(w);
^
symbol: method draw(Window)
location: variable r of type Rectangle
Window.java:423: error: cannot find symbol
c.draw(w);
^
symbol: method draw(Window)
location: variable c of type Circle
4 errors
C:\Users\Hp\Desktop\figuren>
What should I change, I only did it for point to test and this came out
EDIT: I saw that the name of MyWindow and mw are diffrent and taht is why it was compiling it like that,i fixed it but now only the Window pops up but no image?
Last edited by arhzz; April 29th, 2020 at 02:46 PM.
See the last line in post#2Window.java:323: error: cannot find symbol MyWindow
Where is the variable w declared? The compiler can not find it.Window.java:405: error: cannot find symbol
w.drawCircle(x, y, r );
^
symbol: variable w
If you don't understand my answer, don't ignore it, ask a question.
Hey just want to say that i finally managed to compile the program and it works now (partially) Thank you so much for your help,I'd never do it without you honestly.SO now it actually only prints out the first line, it doesnt actually go to the end of the txt.file So i'm thinking an for loop that will tell it to go till the end? that could work right?
Yes, you will need a loop to continue reading through the input file until the last record has been processed.
A for loop is usually used when you know before the loop starts, how many iterations it will do.
A while loop is used when the end of the loop condition is detected while the loop is running.
If you don't understand my answer, don't ignore it, ask a question.
Hmmm,I see so actuall using a while would be much better in my case.I'll try a few things and we'll see what happens,Thanks for the advice!
--- Update ---
Okay so i tried it a few ways and it isnt working so hot;
public static void main(String[] args){ In.open("shapes.txt"); int width = In.readInt(); int height = In.readInt(); do { Window w = Window.create(width,height); char ch = In.readChar(); switch(ch){ case 'L': Line l = Line.fromInput(); l.draw(w); break; case 'R': Rectangle r = Rectangle.fromInput(); r.draw(w); break; case 'C': Circle c = Circle.fromInput(); c.draw(w); break; } }while(In.done()); In.close(); } }
Is my condition wrong, or the "position" of my do while loop
EDIT:
I got the code now to get the picture out, but it is "dislocated" not like it is susposed to be, what could be the cause of that
public static void main(String[] args){ In.open("shapes.txt"); int width = In.readInt(); int height = In.readInt(); Window w = Window.create(width,height); do{ char ch = In.readChar(); switch(ch){ case 'L': Line l = Line.fromInput(); l.draw(w); break; case 'R': Rectangle r = Rectangle.fromInput(); r.draw(w); break; case 'C': Circle c = Circle.fromInput(); c.draw(w); break; } }while(In.done()); In.close(); } }
Last edited by arhzz; April 29th, 2020 at 04:06 PM.
What does that mean?it is "dislocated" not like it is susposed to be
Take some graph paper and use the instructions in the data file to draw the image by hand to see what its contents represents.
If you don't understand my answer, don't ignore it, ask a question.
I did, and it is susposed to be a house with a sun in the top left corner, but the image that pops up on my screen, the roof of the house is way off as well as one of the windows, although the door and other window are in the right place. Some parts are right others arent.
Did your manual drawing match what it was supposed to be
or did it match what the program drew?
If you don't understand my answer, don't ignore it, ask a question.
Actually the profesor,gave us what the image should look like accoriding to the coordinates that the txt contains.
Did your manual drawing match what it was supposed to be (ie what you got from the professor)
or did it match what the program drew?
If you don't understand my answer, don't ignore it, ask a question.
arhzz (April 30th, 2020)
Yea,it did match what I got from the professor.
EDIT: I figured it out, the readChar in rectangle and circle were "eating" the first number in numbers like 50 40 etc... So after removing that It works like a charm.
Thanks so much for your help Norm.
Last edited by arhzz; April 30th, 2020 at 01:41 AM.