Solved

Drawing a Graphics object in a panel...

Posted on 1998-02-05
5
245 Views
Last Modified: 2010-04-16
I am trying to use Graphics.drawString() in a java.awt.Panel and I am having trouble.  I have a Panel on my applet, and when the user's mouse enters the Panel, I want to draw a String of text in the panel.  How do I do this?
0
Comment
Question by:bjg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:russgold
ID: 1232881
Are you using JDK 1.02 or JDK 1.1?
0
 

Author Comment

by:bjg
ID: 1232882
JDK 1.1
0
 
LVL 4

Expert Comment

by:russgold
ID: 1232883
What kind of problems are you having? Are you using a MouseEventListener to detect the mouse moving into the Panel?
0
 

Author Comment

by:bjg
ID: 1232884
Yes, it detects when the mouse moves into the panel successfully, that I checked.  But when I make a call to g.drawString(), nothing happens...
0
 
LVL 4

Accepted Solution

by:
russgold earned 50 total points
ID: 1232885
When doing GUI programming, direct updates to graphics are generally not recommended.  The problem is that the kernel will, at certain times, insist on refreshing the screen by calling update().

Now, the default implementation of update() clears the graphics region to the background and then invokes paint().  The default paint() method for Panel simply updates its child components.

This means that your text could be erased immediately!

A better approach might be to store the desired text and have it drawn on your Panel (once defined) in the paint method.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question