Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drawing a Graphics object in a panel...

Posted on 1998-02-05
5
Medium Priority
?
247 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
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.
Suggested Courses

661 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