Results 1 to 8 of 8
Thread: Button that Draws to canvas
- 02-10-2012, 06:13 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Button that Draws to canvas
Hello Java Forums,
I've been searching a lot on how to draw on canvas and it seems more complicated than I was hoping for. My issue is that I keep running into this code that doesn't help me with what I'm trying to figure out.
Does anyone have any suggestions on how to have some lines get drawn once I push a button?
I keep noticing in example codes that some class extends to a JFrame and then some paint class is declared and there's where code like g.drawLine(int,int,int,int) appears.
How do I make this work with my GUI application?
- 02-10-2012, 06:46 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,236
- Rep Power
- 13
Re: Button that Draws to canvas
Start with: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing) for the basics of painting.
- 02-10-2012, 06:51 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Button that Draws to canvas
Oh wow. I'll take a good look at this tutorial.
Thank you very much.
- 02-10-2012, 10:01 PM #4
Re: Button that Draws to canvas
Moving to AWT/Swing
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 02-11-2012, 02:29 AM #5
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
- 02-11-2012, 03:39 AM #6
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Re: Button that Draws to canvas
Well, I'm still having issues getting this to work at all. How do I "delegate" the painting to my button? How can I make it so when I press a button, my canvas or panel gets drawings on them?
- 02-11-2012, 03:56 AM #7
Re: Button that Draws to canvas
You need to add an action listener to the button. When the action listener is called, it will create instructions for the paintComponent method and call the repaint method. When the JVM calls the paintComponent method, it should look at the instructions left by the action listener and draw what was requested.
- 02-11-2012, 06:42 AM #8
Member
- Join Date
- Feb 2012
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
SWT canvas look like button
By viswa_s in forum SWT / JFaceReplies: 0Last Post: 01-03-2011, 12:29 PM -
JApplet.getGraphics() draws but JFrame doesn't
By ChazZeromus in forum New To JavaReplies: 5Last Post: 07-27-2009, 11:02 PM -
SWT Canvas drawing realtive to image space not canvas space.
By bobbie in forum SWT / JFaceReplies: 0Last Post: 07-05-2009, 01:31 PM -
Demonstration of drawing points. It draws a sine wave
By Java Tip in forum SWT TipsReplies: 0Last Post: 06-28-2008, 10:25 PM -
FreeHand Draws poorly
By Chetanji in forum Java 2DReplies: 1Last Post: 04-24-2008, 05:26 PM
Bookmarks