Domanda

Guys I am developing a normal system that has a superclass called activity and it has three subclasses for it, 1 is Club, 2 is Sports and 3 is Events. Now I want to calculate the total merits gained by a student based on inputs by the staff.

The logic is this, the superclass will have it's own JFrame and it will have a text field which displays the total from inputs gathered from each subclass. Here is the confusing part for me, I want to have JFrames where users can input values for each subclass. Which means each subclass has it's own JFrame and the sum is sent to the superclass's JFrame.

Main question: Is it possible for a subclass to have it's own JFrame.

2nd Question : Any references or tips on how to implement this?

Thanks a lot people.

È stato utile?

Soluzione

Fields (be they JFrames or any other type) are not owned by classes but by instances. Unless you want your Activity subclasses to be singletons (meaning they have exactly one instance), the answer to your first question is "no".

More importantly though, multiple JFrames in a single application is certainly not what you want. If you want every subclass to have its own way to acquire input, then probably a JTextField (to embeddded in the main frame) and otherwise a JDialog (corresponding to a separate window) would do the trick.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top