Solved

Drawing a Graphics object in a panel...

Posted on 1998-02-05
5
237 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding multiple JVM environments to RedHat 6 7 49
Java basic valueOf question 1 29
collection output issue 9 39
Tagging and Merging on Branch 1 30
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

808 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