Results 1 to 7 of 7
Thread: if statements not working
- 07-31-2010, 05:58 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
if statements not working
I'm trying to have an if statement control what is drawn with this code:
I have no clue why it just keeps drawing a rectangle because I'm not changing the wait value from true and it would have to be false to make the rectangle. Is there something wrong with my if statement, or is there another way I should be doing this?Java Code:import java.applet.*; import java.awt.*; public class DrawingLines extends Applet { int width, height; boolean wait = true; public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( Color.green ); if (wait == true) { g.drawLine(10,10,40,40); } else { g.drawRect(20, 20, 100, 100); } } }
-
Your code posted above is in fact drawing a line, not a rectangle, so the only conclusion I can come up with is that the code you are running is not the code you are showing. Can happen.
- 07-31-2010, 06:23 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
When I run it, it doesn't draw a line, this is the exact code I have been using. try and compile and run it in an applet, you'll see it draws a rectangle that isn't filled in.
- 07-31-2010, 06:28 PM #4
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
Never mind, now it seems to be working for some reason, maybe I never saved it.
- 08-01-2010, 05:08 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 08-01-2010, 08:47 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,412
- Blog Entries
- 7
- Rep Power
- 17
- 08-01-2010, 06:05 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Miracles happens to many after several comments on his/her post. ;)
Similar Threads
-
if else statements
By sweetpea123 in forum New To JavaReplies: 4Last Post: 04-12-2010, 07:02 PM -
The code isnt working unless I add print statements at diffrent points!:confused:
By Addez in forum New To JavaReplies: 6Last Post: 11-12-2009, 10:50 AM -
Help with if-else statements
By porchrat in forum New To JavaReplies: 4Last Post: 03-23-2009, 04:24 PM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM -
Help with if else statements
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 07:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks