Results 1 to 7 of 7
Thread: Drawing staircases
- 01-20-2010, 03:11 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 2
- Rep Power
- 0
-
What do you know so far? Can you draw lines? a rectangle? have you created applets before and drawn in them? do you use applets or japplets? Please give us something we can work with here.
- 01-20-2010, 04:04 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 2
- Rep Power
- 0
lines.
Yes, I am familiar with applets, but I'm lost with this problem.
I'm not familiar with japplets, but I could say that the applets I'm working with are graphic applets.
Sorry for the oversight.
- 01-20-2010, 08:33 PM #4
Java Code:// <applet code="StairApplet" width="400" height="400"></applet> // at the prompt>appletviewer StairApplet.java import java.awt.*; import javax.swing.*; public class StairApplet extends JApplet { public void paint(Graphics g) { int w = getWidth(); int h = getHeight(); g.setColor(Color.blue); g.drawRect(0,0,w-1,h-1); g.setColor(Color.red); int steps = 8; for(int i = 0; i < steps; i++) { int x1 = i*(w/steps); int x2 = (i+1)*(w/steps); int y1 = h-1 - i*(h/steps); int y2 = y1; g.drawLine(x1, y1, x2, y2); } } }
-
- 01-21-2010, 05:43 AM #6
That is the rigorous way to do it. When people learn with applets sometimes they learn to draw in the Container paint method. For simple beginnings this is okay. When you add components things get messy and it is much easier to draw on a separate component. Container drawing can be complicated but sometimes it's just what's needed. Depends on what we're doing. Flexibility can be a good thing.
- 01-21-2010, 07:20 AM #7
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
Similar Threads
-
Drawing a grid
By CrystalMoth in forum Java 2DReplies: 11Last Post: 01-10-2010, 05:07 AM -
Drawing Applet
By Urgle in forum New To JavaReplies: 6Last Post: 11-19-2008, 08:38 AM -
Drawing a map
By Karp in forum AWT / SwingReplies: 4Last Post: 11-07-2008, 12:26 PM -
Problem with 3D drawing.
By Supamagier in forum Advanced JavaReplies: 0Last Post: 08-31-2008, 12:39 PM -
Help with 2-D Drawing
By Deathmonger in forum New To JavaReplies: 4Last Post: 06-18-2008, 02:23 AM


LinkBack URL
About LinkBacks


Bookmarks