Link to home
Start Free TrialLog in
Avatar of scudco
scudco

asked on

Adding non-panel components to a panel?

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.
Avatar of Mayank S
Mayank S
Flag of India image

Sorry, this is irrelevant to the topic but.... are you Manish Manajan from CoEP, Pune??

Mayank.
Avatar of scudco
scudco

ASKER

Uhm... no.
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.
ASKER CERTIFIED SOLUTION
Avatar of glottis
glottis
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scudco

ASKER

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?
Avatar of scudco

ASKER

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?
Avatar of scudco

ASKER

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.
Avatar of scudco

ASKER

Always remember to setSize() on any Canvas object to make it actually paint itself.