1

I am trying to write a slide show program in Java and would like to make the implementation as simple as possible.

The goal is to show a series of slides, each of which has navigation buttons, in addition to other buttons that depend on the slide's content. (A slide showing text would have a magnifyTextButtonand a slide with an image would not have this button.)

I was thinking an abstract Slide class would be appropriate, with subclasses for each slide type: TextSlide and ImageSlide. How would I implement these subclasses so that the magnifyTextButton would show up in TextSlides , and not in any other slide?

Also, my Slide class extends JFrame. Would each instance of a subclass of Slide need to construct a JFrame object if the show is designed to take place in a single window, like in PowerPoint?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user1505713
  • 615
  • 5
  • 20

3 Answers3

3

How would I implement these subclasses so that the magnifyTextButton would show up in TextSlides , and not in any other slide?

You can take a flag to decide whether to show magnify button or not. That flag will be true in TextSlides and false in other. Or you can have this button directly in TextSlide and not in other, this way no need to check anything. And processing related to magnify will only go in one class that is TextSlide.

Would each instance of a subclass of Slide need to construct a JFrame object if the show is designed to take place in a single window, like in PowerPoint?

In my opinion slide classed should extend JPanel. You can easily change panels on a single frame.

Some questions/answers that can help you in this:

Community
  • 1
  • 1
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
3
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Be aware of [this](http://stackoverflow.com/questions/11343649/change-current-card-in-card-layout-with-slide-effect-in-swing#comment14952474_11343649) problem in using CardLayout. – Harry Joy Jul 06 '12 at 04:49
1

You've got a lot going on here, but let's see if I can help out.

1 : I see two options for how to lay out "magnifyTextButton." The first would be to make it a method exclusive to TextSlide. There's no reason that an ImageSlide would need to know anything about magnifyTextButton. In this format, you would then have a "draw" abstract method in your overarching abstract class (which then might be better left as an interface). I don't like this method as much as the one that follows.

Your other option is to make MagnifyTextButton a decorator. This way, you can mix and match MagnifyTextButton onto other classes with text in them (extensions of TextSlide, which you may very well want). This will give you more versatility and will require that your Slide classes need to know even less about MagnifyTextButtons!

2 : I think you want this to be a Jpanel rather than a Jframe.

Mualig
  • 1,444
  • 1
  • 19
  • 42
Ben Pea
  • 11
  • 1