how do u display text on the applet when a button is pressed?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: how do u display text on the applet when a button is pressed?

  1. #1
    Join Date
    May 2005
    Posts
    14

    how do u display text on the applet when a button is pressed?

    ok, so i have buttons on the screen and when it is clicked the action method is called. How do i get it to print text on the java applet when it is clicked? When i try to say g.drawString("You Clicked This Button"); it says that it cant resolve g or whatever. i have g in my paint method though. So how do i get it to draw text on the java applet after the button is clicked.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You call repaint() when the button is clicked, and in the paint method you
    draw your text using the Graphics pointer that is passed as a parameter (g)
    to that method.

    Note: the Graphics g in paint/update is the pointer to the display's graphical
    context, if you do rapid drawing (animations) you will get flickering if you
    use it as it is. To avoid that you will have to implement double buffering.

    But, for displaying a simple line of text at a button click, this wont have any
    side effects.
    Last edited by sjalle; 06-08-2005 at 08:38 AM.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center