?
Solved

Adding non-panel components to a panel?

Posted on 2003-03-27
8
Medium Priority
?
237 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
[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
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
Independent Software Vendors: 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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 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