Slide show in Java? - java

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?

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:
slide effect with JPanel
Slide JPanel Content in a JForm on Java

have look at CardLayout
put Images as Icon / ImageIcon to JLabel
put JLabel contains Image as new Card

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.

Related

JPanels one above the other

I want to design a jFrame where there are three jButtons and a set of three jpanels one above the other. When we call a jPanel from the respective jButton , that pane will be displayed. It would appear to the user as if the same portion of the jFrame is displaying the content to be shown on clicking each jButton.But when i am trying to set the jPanels one above the other, they are being shown side by side thus elongating the jFrame horizontally. What should i do to put one jPanel over the other? Any other idea than jPanel which should do the work i intend to do would also be help !!
Your behavior sounds like you are using a FlowLayout. This will not "layer" anything. Instead us a CardLayout, which does exactly what you are trying to accomplish. You call method like show, next, and previous to navigate the panels. See How to Use CardLayout for more details.
Also there are probably hundreds of other examples here on so. Go through the cardlayout questions.
[Tip: navigate the different tabs like "votes" and "frequent" to filter to some of the better posts]
Here's one that uses the show() method to switch between two panels by name.

Java Clear Screen

I'm looking for a specific code that if a button is clicked the whole applet will clear screen and a new interfaces like labels, images, buttons will appear, is it possible? or if not are there any methods on terminating an applet then run a different applet at the same time when a button was pressed?
I'm not 100% if this is what you're asking, but I'll try and help with it anyway:
You may want to do some research into JPanels and the setViewport() method, this way, you can add all the items you want.
e.g. Say you had 2 JPanels, a and b, you can put a load of buttons and labels and whatever you want on one JPanel and then a load more onto the other, then you can simply switch between them using setViewport(a); or setViewort(b);
It's really simple and useful if you don't want to make a new JFrame pop- up for seperate parts of your program.

Java GUI - Changing inside JPanels dynamically

Trying to figure out if it's possible and difficultly level around the below problem as depending on such might consider other alternatives...
If I have a overall JFrame framework, can I construct various different JPanels with their associated components and actions then say pass these JPanels as args depending on user interaction so the inside of the overall JFrame/JPanel changes. I'm assuming there must be some implementation that achieves this, but having trouble find the answer.. For example I construct a JPanel, which has border layout, and the centre position will change different JPanels depending on what a user does etc.. I thought it would be a simple as create a JPanel, then passing it to a method which calls the overall Jpanel add(component, borderlayout.center) method which would change what is shown, but doesn't work like that and assumed that must only work for constructor when GUI is first constructed..
Sorry for the length, but if someone can point me in the right direction i'd be appreciated...
Removing and adding components does work as expected. You need to call revalidate() on the parent component once it's done, though.
If that doesn't work, post an SSCCE exhibiting the problem.

Java: single frame vs multiple frames

Think about the classic installation process, where you have a "next" button and when you click it the content of the window changes. To represent this situation I thought of two possible solutions:
-when "next" is clicked destroy the current JFrame and create a new JFrame, maybe passing to his constructor useful information (e.g. actual window size, content inserted by the user in the current frame, ...)
-when "next" is clicked remove all the components from the current JFrame and add new components as needed
The first solution looks way better about OOprogramming, because I can keep separate classes for different frames and I can avoid huge methods that empty the frame and repopulate it. However the first solution sounds a bit "dirty" and I should pass lots of parameters to the new frame. To represent this situation I would choose the second solution.
Now think about a menu with an "option" component: in this situation I would create a new JFrame when "option" is clicked, so that I can populate it with option items. Is this a correct solution? Is there a way I can always know which one is the best solution? Are there any solutions I didn't think about?
Destroying the main JFrame would be silly -- not to mention jarring for the user. Just use a single JFrame and change its contents.
To implement an installer wizard, use a single JFrame containing one large JPanel on top and a smaller one containing the "Next", "Back", "Cancel" buttons along the bottom. When the Next or Back buttons are pressed, you replace the large JPanel. You can have many different JPanel subclasses, one for each "page" of the wizard.
There's a LayoutManager called CardLayout which is ideal for implementing this scenario -- it manages a "stack" of components, and only shows one of those components at a time. Use a BorderLayout in the JFrame. Into the center position put a JPanel with a CardLayout. Then add the individual pages of the wizard to that JPanel, so the CardLayout can manage them.
The CardLayout is well suited for this. You just swapout the JPanel contents when the "Next" button is pressed.

J2ME Form Layout

I'm trying to make a menu like shown below. I have some items that extends CustomItem and consists of an Image and some Text. Now I want to position them as shown, but run into problems doing so - it seems only some minimal layout directives can be used in a Form. Is there a way for custom positioning using the Form class or is there another class I could use?
Make a HorizontalLayout CustomItem that aligns everything that is added to it horizontally.
Details:
Such class should have some kind of array to store all the items, and when there is a request to draw it, it should ask the width of each element inside it, do some calculations and call the items' draw method. Of course, such stuff is rather difficult. You would also have to implement the selection of these items with left/right keys...
It may be slightly better to use Canvas.

Categories