Created
May 17, 2009 18:24
-
-
Save seanh/113083 to your computer and use it in GitHub Desktop.
A simple demonstration of Java Swing's CardLayout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scratch; | |
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
/** | |
* A simple demonstration of Swing's CardLayout. | |
* | |
* @author seanh | |
*/ | |
class CardLayoutDemo { | |
private JFrame frame = new JFrame("Swing Refresh Bug?"); | |
private Container contentPane = frame.getContentPane(); | |
private JPanel cardPanel = new JPanel(); | |
private CardLayout cardLayout = new CardLayout(); | |
private Component currentComponent; | |
private JButton next; | |
CardLayoutDemo() { | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
cardPanel.setLayout(cardLayout); | |
cardPanel.add(new JLabel("One"),"One"); | |
cardPanel.add(new JLabel("Two"),"Two"); | |
cardPanel.add(new JLabel("Three"),"Three"); | |
next = new JButton("Next"); | |
next.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
cardLayout.next(cardPanel); | |
} | |
}); | |
contentPane.setLayout(new BorderLayout()); | |
contentPane.add(cardPanel,BorderLayout.CENTER); | |
contentPane.add(next,BorderLayout.SOUTH); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
public static void main(String[] args) { | |
CardLayoutDemo demo = new CardLayoutDemo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment