Results 1 to 8 of 8
  1. #1
    Rylogy is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Angry 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?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: Button that Draws to canvas


  3. #3
    Rylogy is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Re: Button that Draws to canvas

    Oh wow. I'll take a good look at this tutorial.
    Thank you very much.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Button that Draws to canvas

    Moving to AWT/Swing

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Rylogy is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Re: Button that Draws to canvas

    I'm not sure I follow.

    Quote Originally Posted by DarrylBurke View Post
    Moving to AWT/Swing

    db

  6. #6
    Rylogy is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default 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?

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default 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.

  8. #8
    Rylogy is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Re: Button that Draws to canvas

    Word! I'll definitely try that. Thank you for your help.

Similar Threads

  1. SWT canvas look like button
    By viswa_s in forum SWT / JFace
    Replies: 0
    Last Post: 01-03-2011, 12:29 PM
  2. JApplet.getGraphics() draws but JFrame doesn't
    By ChazZeromus in forum New To Java
    Replies: 5
    Last Post: 07-27-2009, 11:02 PM
  3. Replies: 0
    Last Post: 07-05-2009, 01:31 PM
  4. Replies: 0
    Last Post: 06-28-2008, 10:25 PM
  5. FreeHand Draws poorly
    By Chetanji in forum Java 2D
    Replies: 1
    Last Post: 04-24-2008, 05:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •