if (currentChar == 'b')
{
System.out.print("b");
}
else if (currentChar == 'w')
{
System.out.print("w");
}
else if (currentChar == '.')
{
System.out.print(".");
}
else if (currentChar == ' ')
{
System.out.print("\n");
}
what 's the use of that?
have you tried:
if ( currentChar == ' ')
System.out.print("\n");
else
System.out.print(currentChar);
or something similar?
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
I think that's just a work-in-progress framework, so he can test that part of the code before moving on to doing more exciting things for each char (in which case I thing he is doing exactly the right thing).
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
a Switch statement might make it easier to read.
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
switch(currentChar){
case 'b': printRectangle();
break;
case 'c': printSquare();
break;
case 'd': printCircle();
break;
default: System.out.println("invalid option");
}
where are you trying to draw/print them? in a Panel? in the command line?
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
I want to have more freedom to call the paint method whenever i like and it will print out the object that I want.
It doesn't work that way. The paint method may need to be called because: the window was just re-sized; the window was minimised/restored; the window had been covered by another window but now its been uncovered...
Swing knows about all those things, and calls your paint method whenever it's necessary.
If you decide that you want to change the shape in our window you call Swing's repaint() method, and that tells Swing to schedule a call to your paint method. You will need a variable that you set when the user replies to your menu so the paint method can use it to know which shape to paint.
It's all backwards from what you are thinking now, but it's how it has to work, and you'll soon get the hang of it.
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
There's a graphics method that fills a circle - I'll let you find it ;)
Before you go to animation there's one thing still to do. Strip everything that's not painting out of your paint method. The reason is that that method will be called maybe 30 times per second when you're animating, so you don't want to open and read a file every time.
You use a string of characters to control what's painted. That's OK for now (although you will want to change that later!). Just have a variable to hold that string, read it from the file once when the app starts, then process it one char at a time in paint.
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
OK, that sounds like fun. But you'll still have to read the file outside the print method. Have you looked at how to control the speed/timing of the animation?
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
Btw, how do you make it so whenever I minimize/maximize the JPanel window, the painting does not disappear?
If you have taken the stuff out of paint like I said then min/max should work.
redirect the main method's output to JTextArea of JPanel
Not easy to redirect, but easy to replace the System.out.print(xxx); by myTextArea.append(xxx);
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30