TestCardLayout1.java
Select all
/* TestCardLayout1.java CIS 260 2/22/2006 David Klick Demonstration of CardLayout using next and previous buttons. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestCardLayout1 extends JFrame { JButton btnNext, btnPrev; JPanel pnlCard[], pnlCards, pnlControl; JButton btn[]; int currentCard = 0; public static void main(String[] args) { TestCardLayout1 app = new TestCardLayout1(); app.setDefaultCloseOperation(EXIT_ON_CLOSE); app.init(); } public void init() { int i; pnlCard = new JPanel[3]; btn = new JButton[12]; pnlCards = new JPanel(); pnlCards.setLayout(new CardLayout()); for (i=0; i
0) { currentCard--; ((CardLayout) pnlCards.getLayout()).previous(pnlCards); } } if (currentCard <= 0) btnPrev.setEnabled(false); else btnPrev.setEnabled(true); if (currentCard >= pnlCard.length-1) btnNext.setEnabled(false); else btnNext.setEnabled(true); } } }