import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
public class NewJApplet extends JApplet {
private JPanel mainPanel = new JPanel();
static int stepCount = 0;
// Comments
private JButton nextButton = new JButton ("Next");
private JButton previousButton = new JButton ("Previous");
private JButton restartButton = new JButton ("Restart");
JLabel[] comments = {
new JLabel ("Comment 0"),
new JLabel ("Comment 1"),
new JLabel ("Comment 2"),
new JLabel ("Comment 3"),
new JLabel ("Comment 4"),
new JLabel ("Comment 5")
};
public void init () {
createPanels ();
}
private void createPanels () {
CommentPanel commentPanel = new CommentPanel (this);
mainPanel.add (commentPanel);
getContentPane().add (mainPanel);
}
class CommentPanel extends JPanel {
public CommentPanel (final NewJApplet newapplet) {
add (comments[stepCount]);
add (nextButton);
add (previousButton);
add (restartButton);
nextButton.addActionListener (new buttonListener());
previousButton.addActionListener (new buttonListener());
restartButton.addActionListener (new buttonListener());
setBorder(BorderFactory.createTitledBorder("Comments" + "(Current Step Count: " + stepCount + ")"));
}
}
class buttonListener implements ActionListener {
public void actionPerformed (ActionEvent event) {
if (event.getSource () == nextButton) {
stepCount++;
}
else if (event.getSource () == previousButton)
stepCount--;
else
stepCount = 0;
}
}
}
Edited by Qistina Tajuddin, 21 August 2011 - 02:26 AM.
Updated the code to make it more legible.


Sign In
Create Account

Back to top









