File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes refactoring question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "refactoring question" Watch "refactoring question" New topic

refactoring question

chihwah li

Joined: Apr 23, 2010
Posts: 25

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

- 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).

- 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. =)
I agree. Here's the link:
subject: refactoring question
It's not a secret anymore!