File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Back Forward in java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Back Forward in java application" Watch "Back Forward in java application" New topic
Author

Back Forward in java application

shan sonata
Greenhorn

Joined: Aug 17, 2003
Posts: 2
Hi, i'm doing some java programmings and need help from you.
Here's the question:
I'm doing Back Forward task by using Back and Forward Buttons.
It's in not in applet like someone posted before. These're variables:

JPanel ContentPrevious, ContentCurrent, ContentNext;
JButton BackButton, ForwardButton;
boolean BackActivated = true;
boolean ForwardActivated = false;
Action action = new Action();
//////////////////////////////
//
//somewhere call action
//
//////////////////////////////////

public class Action implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (BackActivated)
{
if (e.getSource()==BackButton)
{
ContentNext = new JPanel();
ContentNext = ContentCurrent; //problem: ContentNext doesn't take ContentCurrent value
ContentCurrent.setVisible(false);
Content.remove(ContentCurrent);
ContentCurrent = new JPanel();
ContentCurrent = ContentPrevious;//problem: ContentCurrent doesn't take ContentPrevious value
Content.add(ContentCurrent);
forwardActivated = true;
BackActivated = false;
}
}

else if (forwardActivated)
{
if (e.getSource()==ForwardButton)
{
ContentPrevious = new JPanel();
ContentPrevious = ContentCurrent;//same problem

ContentCurrent.setVisible(false);
Content.remove(ContentCurrent);
ContentCurrent = new JPanel();
ContentCurrent = ContentNext;//same problem
Content.add(ContentCurrent);
forwardActivated = false;
BackActivated = true;

}
}
}
}

Hope anyone can help me.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Hope anyone can help you what? Are you getting errors? You need to tell us what problems you are having so that we know what you need help with.


GenRocket - Experts at Building Test Data
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I'm also not sure what you're after, but copy/compile/run this to see the JPanels changing.
shan sonata
Greenhorn

Joined: Aug 17, 2003
Posts: 2
Sorry for not telling you clearer. The problems are in comments in the code i posted. It didn't work properly.
.....
ContentNext = ContentCurrent; //problem: ContentNext doesn't take ContentCurrent value
.....

ContentNext didn't take the value of ContentCurrent like in C++?!
Michael, i tried ur code and it works properly. But there's only 3 panel.
My problem is: i have lots of panel and each time i show a panel in the frame, it becomes ContentCurrent.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I'm still not sure I'm reading this correctly - you have multiple JPanels and you want to show the next one, or the previous one, depending on whether a forward or back button is clicked. If so, perhaps one way might be to have an array of JPanels and a counter, then if forward button is selected, add 1 to the counter then add JPanel[ctr] etc.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Wouldn't this be a perfect use for CardLayout?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Back Forward in java application