Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Adding non-panel components to a panel?

Posted on 2003-03-27
8
Medium Priority
?
247 Views
Last Modified: 2010-03-31
I am currently trying to implement an Alarm program in which I have a panel with text boxes for the hour and minute in one panel and the clock in another panel. I've figured out how to do each of these individually yet I cannot figure out how to put the clock graphics into its own separate panel and repaint it for animation. My question is Is there a way to make a panel that can use the paint() method and also be recalled through the repaint() method?

So far I've tried containing the paint() method in its own class called MyPanel and then creating an instance of that class("MyPanel mp = new MyPanel()" and also "MyPanel mp = new Panel()") adding it to the Frame and calling repaint() on the panel. I've had no luck with either. This is really killing me. Any help is appreciated, thanks.
0
Comment
Question by:scudco
8 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 8216804
Sorry, this is irrelevant to the topic but.... are you Manish Manajan from CoEP, Pune??

Mayank.
0
 

Author Comment

by:scudco
ID: 8216817
Uhm... no.
0
 
LVL 1

Expert Comment

by:kckchak
ID: 8216858
Using GridBagLayout, you need to place the panel properly and then it will be displayed accordingly. Later step is to override the paint() method, display your own content.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Accepted Solution

by:
glottis earned 80 total points
ID: 8217090
What you could also do is that Create a Canvas object:

public MyClock extends Canvas {
  public void paint(Graphics g) {
   // do some painting picasso
  }
}

you can then add this canvas to your panel. add a timer to your panel which will keep on calling the repaint() of your canvas.
0
 

Author Comment

by:scudco
ID: 8219797
Well I created MyClock class and put all the paint components in there, added it to my panel but it still won't even paint anything in the clock. I still get the TextFields and Buttons but no clock... This is depressing... Any suggestions?
0
 

Author Comment

by:scudco
ID: 8219876
Well I created MyClock class and put all the paint components in there, added it to my panel but it still won't even paint anything in the clock. I still get the TextFields and Buttons but no clock... This is depressing... Any suggestions?
0
 

Author Comment

by:scudco
ID: 8219938
Sorry about that double post, I just realized what it was. I needed to set the size of the MyClock object... Well it works now, Thanks for the help, glottis.

And kckchak, I looked at GridBagLayout and it seemed like it must've been for applets, although, I'm not sure about that. I'm compiling this on a sun machine not for applets. Even if it wasn't just for applets I was able to use glottis' answer much easier. Thanks for your help, as well.
0
 

Author Comment

by:scudco
ID: 8219941
Always remember to setSize() on any Canvas object to make it actually paint itself.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

578 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