File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes JFrame extending a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JFrame extending a class" Watch "JFrame extending a class" New topic

JFrame extending a class

Hugo Alejandro

Joined: Jul 31, 2008
Posts: 11
I have made a class which have some warehouse stuff working fine but the thing is that now I want to make a GUI for a better code manipulation so, I have created in NetBeans a JFrame which will contain 2 JRadioButton and a jButton, I want that when a user clicks the JButton with a selected option, send a response to another JFrame with varibles I would use to call methods so, how can I extend from my warehouse class if by default, JFrame extends from javax.swing.JFrame and how can I pass some data to another JFrame?
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

In your first question you ask 'How do I inherit the warehouse while extending JFrame?"

The answer is, you probably don't want to extend JFrame, and may not to want inherit from warehouse, either. Instead, you probably want another class that HAS-A warehouse, and HAS-A JFrame (composition) rather than IS-A warehouse and IS-A JFrame (inheritance). This third class in your application would feed the information the JFrame needs by getting it from the warehouse.

See This JavaWorld article for an introduction to the difference between inheritance and composition, but do a more extensive search to get a better understanding.

The second question is "How to transfer data from one JFrame to another?" This will be easier when you implement the Composition approach, and will be a matter of:
1) Providing an ActionListener that gets called when the button on Frame1 is pushed
2) Getting the proper information from the warehouse
3) Sending the information to JFrame2 via whatever method calls you make available.

Hugo Alejandro

Joined: Jul 31, 2008
Posts: 11
Ok I've got it, I delayed a lot to answer because I didn't understood but now it's working, Thanks!
I agree. Here's the link:
subject: JFrame extending a class
It's not a secret anymore!