Results 1 to 6 of 6
- 02-17-2012, 04:56 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
Sub-Sub-Class masking Sub-Class' controls
UPDATE: Problem Solved. Close thread.
Sorry for the confusion. The problem was ChildPanel was painting over ParentPanel's controls. I was asking how to stop ChildPanel from painting over ParentPanel's controls.
The solution is simply to comment out ChildPanel.constructor's call to initComponents(); This prevents the layout manager from positioning ChildPanel's panel overtop of ParentPanel's controls.
==============================
I have a ParentPanel class with a bunch of controls. ParentPanel is subclassed to ChildPanel. ChildPanel has no controls but I want to add more code.
public class AppFrame extends javax.swing.JFrame
{
ChildPanel childPanel;}
public AppFrame()
{
initComponents();}
setTitle("Sub sub class");
setSize(400, 300);
childPanel = new ChildPanel();
// using border layout
add(childPanel, BorderLayout.CENTER);
// omitted generated code on the layout manager
public class ParentPanel extends javax.swing.JPanel
{
public ParentPanel()}
{
initComponents();}
// omitted generated code and variables for controls
public class ChildPanel extends ParentPanel
{
public ChildPanel()}
{
initComponents();}
// omitted generated code
When the app opens the ParentPanel controls are either covered by ChildPanel or not drawn at all. What can I do to keep ParentPanel's controls visible and functioning and add more code to ChildPanel? Am I even using the correct GUI classes?
thanks.Last edited by jroch; 02-17-2012 at 07:05 PM. Reason: problem solved
-
Re: Sub-Sub-Class masking Sub-Class' controls
It's hard for me to say what's wrong based on the information as presented. I'm guessing that you have layout issues, but again with the scant information posted so far, this is just a wild guess. If you are new to Swing, I strongly urge you not to use a code generator to create your applications but instead to go to the Swing tutorials and learn to create applications by hand. Then you'll know exactly what your code is doing or if not doing, where the problems are located, and you'll know what code to show here to make your questions answerable.
- 02-17-2012, 07:29 PM #3
Re: Sub-Sub-Class masking Sub-Class' controls
Does also look like gross misuse of inheritance. Subclassing most emphatically does not represent a parent-child relationship.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-17-2012, 08:09 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
Re: Sub-Sub-Class masking Sub-Class' controls
Inheritance (object-oriented programming) - Wikipedia, the free encyclopedia
In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior ... from pre-existing classes called base classes or superclasses or parent classes or ancestor classes. The new classes are known as derived classes or subclasses or child classes.
So based on Wiki's definition (relative to my app):
ParentPanel = base class aka superclass. Provides a bunch of controls and some generalized functionality.
ChildPanel = subclass aka child class
and JPanel would be the superclass of ParentPanel.
...
A subclass, or child class, is a modular, derivative class that inherits one or more properties from another class (called the superclass, base class, or parent class). The superclass establishes a common interface and foundational functionality, which specialized subclasses can inherit, modify, and supplement.
In my case ChildPanel is inheriting ParentPanel's controls and functionality and then modifying and supplementing some of that functionality.
Thank you for taking the time to read my original post.
-
Re: Sub-Sub-Class masking Sub-Class' controls
So rather than post some code and a clarification of your problem, you've chosen to debate the merits of inheritance. I'm going to assume then that you've solved your problem, because if you haven't I'd have thought that you would have done the former rather than the latter. If my assumption is wrong and you still need our help, consider giving us more information. The link below and here on How to Ask Smart Questions can give good tips that can help let you know just what information we need.
- 02-17-2012, 10:45 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
Re: Sub-Sub-Class masking Sub-Class' controls
The tone of your response is not appreciated Moderator Fubarable. Let's move onto other things.
There is no need to make any assumptions about the state of the problem. Please see the "Last edited" time stamp of the first post 8.05pm at which time I declared the problem solved. Moderator DarrylBurke came along 24 minutes later at 8.29pm and publicly made what I interpreted as a veiled shot. At 9.09pm I made a rebuttal that was fair and without drama.
Please research the facts before accusing me of purposely going off topic and "chos[ing] to debate the merits of inheritance" instead of producing more clarification.
... and would somebody please close/lock this thread before postings get personal.
Have a nice day.
Similar Threads
-
calling a function of a specific type in a java class from another class.....
By safi532 in forum Advanced JavaReplies: 3Last Post: 01-26-2012, 11:20 PM -
How to get a compatible class of a template class? Return type of method is AClass<E>
By SKuypers in forum Advanced JavaReplies: 0Last Post: 12-07-2011, 11:55 AM -
Eclipse Compile Error: Call validateValue(Class<T>, String, Object, Class<?>...)
By Tomshi in forum EclipseReplies: 0Last Post: 03-27-2011, 05:49 AM -
super class reference variable accesses overriding sub class method
By subith86 in forum New To JavaReplies: 5Last Post: 01-26-2011, 06:38 PM -
problem in accessing array values of one class in to jframe class
By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 09:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks