Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

relationship between super and child  RSS feed

 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to make an application and must use strategy pattern my idea is to create a super class in this case Movie Player and three sub classer and they'll komminesera with each other using strattegy pattern, one of the sub classes is Button Panel and I want to add it to Movie Player and it was to be its child,so how can I add the butt panel to Movie Player and it shall be its children???

MoviePlayer:


ButtonsPanel:

 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one of the sub classes is Button Panel


Then it should extend JPanel, not JFrame. Then to use the panel you add the components directly to the panel. There is no need to create a panel since the class "is a JPanel". Then you add the ButtonPanel to the frame.
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to extend the panel class at all?
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to do is create a frame with the movie player class and add button to the panel without creating an instance of the button panel I have to use strategy patteron
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Strategy pattern helps you to deal with situations where you need to choose either or implementation of a algorithm/feature. What is the feature you are trying to use strategy pattern? This is not clear to me.

You have mentioned ButtonPanel - let me assume this will have some buttons like play/pause/stop. Are you also trying to provide an alternate button panel? which will lot more features than the basic panel?
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I'll make a stop movie application where I have a frame wich contain three panels, one panel will show pictures from laptop camera, and other panel show the picture i have taket, and then the third will contain buttons, so with the help of three buttons should be able to take pictures and then they play with but certain frequency.
My solution is to create a super class and it will be just frame and three subclaaser where should I have the panels and they'll kommuniaera with each other using stratgy pattern, so I want to add the panela with the Strategy pattern. And uppdate them
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The panels should probably not intercommunicate. You should pass the control signals via other classes. The panels are designed for display: use them for display. Use other classes to implement the Strategy pattern if you need it.
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah i know, i dont want to change the panel. I want to change that who is in the panel. So my problem now is how can i add the panel to the frame and it must be the its child without creating instans variable if it possiable.
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create the panel as a local variable in the constructor or setUpGui method. It is probably unnecessary to have it as a field.
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean the panel can't add to movieplayer and extend it same time??
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is yes, but you have got the words in the wrong order.
You might need a class like MoviePanel which extends JPanel, if that is what you mean. You can add an object from that panel class to another (ordinary) panel object.
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i code the frame and the panel in same class så i can't use the strategy pattern i must separate the panel and the frame or du you have an other solution??
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the strategy pattern apply to the frame and panel? The logic of the application should be independent of the display.
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Does the strategy pattern apply to the frame and panel? The logic of the application should be independent of the display.


here is an UML diagram that show how i thinking, i have creat the movie player and the panels so the problem is now how to add them to movieplayer with strategy pattern.



http://i62.tinypic.com/33wy7v8.png
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth should a button panel extend movie player? A button panel is imply an ordinary panel which you add buttons to. The button classes do not have any unusual features; they simply have listeners and text and colours as value of pre‑existing fields. I fail to see why you need the strategy pattern here.

The movie player class is probably simply a panel which has had its paintComponent method overridden. There is an interesting example of such overriding here in an anonymous class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!