Results 1 to 4 of 4
- 12-10-2009, 12:39 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
Draw more than one line on run time
I'm trying to show an empty form then I'll run a loop to draw some lines!
How can I take the loop out of the paint() method? and make the program repaints itself everytime I add a new line to it?
Java Code:import java.applet.*; import java.awt.*; public class ack extends Applet { int width, height; public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( Color.green ); for ( int i = 0; i < 10; ++i ) { g.drawLine( width, height, i * width / 10, 0 ); } } }
-
You could create an ArrayList of points or Line2D's and then iterate through the points or Line2D's in the paint method. If you want to create a new line you create a new Line2D object, add it to the ArrayList and then instruct the GUI to repaint itself.
- 12-10-2009, 02:28 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
Thanks
how ca I make the GUI repaint itself
-
I'm not 100% sure for AWT. I use Swing (which I recommend that you use as well), and with Swing we call repaint() on the component. Perhaps you can do the same with AWT components, but again, don't hold me to this.
Similar Threads
-
Need to read an .ini and .abook file line by line (both files contain texts)
By ollyworks in forum Java AppletsReplies: 4Last Post: 09-10-2009, 10:18 AM -
How to: draw line between 2 nodes of 2 trees
By kholostoi in forum Java 2DReplies: 1Last Post: 09-03-2009, 07:10 PM -
When do we draw the line for loose coupling.
By h8alfred in forum Advanced JavaReplies: 0Last Post: 03-27-2009, 03:05 AM -
How to Draw line in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:08 PM -
How to draw a thick line
By johnt in forum Java 2DReplies: 1Last Post: 05-31-2007, 04:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks