Solved

Adding a Label

Posted on 2002-05-06
2
140 Views
Last Modified: 2010-05-18
How do I specify explicitly where I can add a label?

For example, if I have an applet 300x500, how can I put it at  150, 300
0
Comment
Question by:djmajiktc
2 Comments
 
LVL 2

Accepted Solution

by:
mzimmer74 earned 50 total points
ID: 6991979
Well, one way is to set your layout of your applet to null (setLayout(null)) and then set bounds on your label with:

label.setBounds(new Rectangle(150,300,width,height));

width and height are how big you want your label to be.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6992022
you don't need to add the label, you can do something like this:

public class MsgTest extends java.applet.Applet {
   
    private String msg;
 
    public void init()
        {
          msg = "This should go at 150, 300";
      }

      public void paint(Graphics g) {
           if (msg != null && !msg.trim().equals("")) {
                g.drawString(msg, 150, 300);
           }    
      }
     
}

All you have to do is set msg to null or "" and call repaint() to make it go away

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now