File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Calling swing functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Calling swing functions" Watch "Calling swing functions" New topic

Calling swing functions

manu nas

Joined: Jun 15, 2013
Posts: 11
Hi guys, im trying to separate my swing in different classes, but what i get is a new window, i just want to add different jlabels, jbuttoms and other things from a new classes to my constructor class, i dont know if its possible or not, heres my resumed code.

My main class

here my constructor class:

And here my new class, where i want to add new JLabels to my constructor class:

How can i call this JLabel from my principal class?

I know i can use the dimension variable in all classes sharing it btw, but i was just trying some things ;/

Hope you guys can help me, im pretty confused right now
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 502


I don't really understand what you mean. But there are two suggestions you might consider:
- Pass your container instance (JFrame or JPanel) to your nuevo class, then add the labels to the container.
- Have a getter methods for the labels in your nuevo class, and use these getters from your container class to access the label objects.

PM Me If You Want to get Urgent Help on Java Programming
manu nas

Joined: Jun 15, 2013
Posts: 11
oh well, thanks for your answer, i just want to modularize my program into classes, grouping them in functions, so, when i call those functions from my actionperformed button, they appear in the container.
I agree. Here's the link:
subject: Calling swing functions
It's not a secret anymore!