• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFrame extending a class

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Thanks
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I've got it, I delayed a lot to answer because I didn't understood but now it's working, Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic