• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

refactoring question

 
chihwah li
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have the following situation clock that has a analog and digital view in the same JFrame:

Classes:
- ClockFrame extends JFrame
- ClockPanel extends JPanel implements Observer,
- TimeGenerator class extends Observable implements Runnable

What happends:
- I run timeGenrator's main, creates TimeGenerator and ClockPanel.
- timeGenerator calls method addObserver(ClockPanel)
- The ClockPanel creates ClockPanel, then calls method ClockFrame.addPanel(this). To add this JPanel to the JFrame.

I must follow the situation above because:
- TimeGenerator can only add an instance if it created it. I don't know how to call method addObserver() if it did not create that ClockPanel instance.
- Because the panel is created, I let ClockPanel create an instance of ClockFrame and call method ClockPanel.addPanel(this).

Problem:
- I am trying to create 1 class for each clock view: Clockanalog and a class ClockDigital. but How can I do that? The problem is that only one ClockPanel (analog or digital) can create the ClockFrame.
Without creating the instance in a specific ClockPanel, I don't know how to add it to the ClockPanel.

Hope it's clear... I can provide my code if needed. What Java principle do I lack to successfully refactor this code? If you have suggestions, please do tell. =)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic