CardLayout() not working
I am trying to get it to where if the user selects new it will change
the panel, but it isn't working at all. Nothing changes, but I know
the event method is getting called, because of a print statment.
[code]
private void jMenuItemNewActionPerformed(java.awt.event.ActionEvent
evt) {
java.awt.CardLayout cl = (CardLayout)jPanelMain.getLayout();
String path = "jPanelPagePageWelcome";
cl.show(jPanelMain,path);
System.out.println(path);
}
[/code]
That is where I try to use the cardlayout. The rest of the code is
below
[code]
/*
* Tester.java
*
* Created on April 23, 2008, 4:09 PM
*/
package Tournament;
import java.io.*;
import javax.swing.*;
import java.awt.*;
/**
*
* @author michael
*/
public class Tester extends javax.swing.JFrame {
/**
* Creates new form Tester
*/
public Tester() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code
">
private void initComponents() {
jPanelMain = new javax.swing.JPanel();
jPanelPageWelcome = new javax.swing.JPanel();
jLabelWelcomeMessage = new javax.swing.JLabel();
jPanelPageNew = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenuFile = new javax.swing.JMenu();
jMenuItemNew = new javax.swing.JMenuItem();
jMenuItemLoad = new javax.swing.JMenuItem();
jMenuItemSave = new javax.swing.JMenuItem();
jSeparatorFileMenu = new javax.swing.JSeparator();
jMenuItemExit = new javax.swing.JMenuItem();
jMenuHelp = new javax.swing.JMenu();
jMenuItemAbout = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setName("frameMain");
jPanelMain.setLayout(new java.awt.CardLayout());
jPanelPageWelcome.setBorder(javax.swing.BorderFactory.createTitledBorder("Tournament
Generator"));
jLabelWelcomeMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabelWelcomeMessage.setText("Tournament Generator");
javax.swing.GroupLayout jPanelPageWelcomeLayout = new
javax.swing.GroupLayout(jPanelPageWelcome);
jPanelPageWelcome.setLayout(jPanelPageWelcomeLayout);
jPanelPageWelcomeLayout.setHorizontalGroup(
jPanelPageWelcomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelPageWelcomeLayout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(jLabelWelcomeMessage,
javax.swing.GroupLayout.PREFERRED_SIZE, 249,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(68, Short.MAX_VALUE))
);
jPanelPageWelcomeLayout.setVerticalGroup(
jPanelPageWelcomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelPageWelcomeLayout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jLabelWelcomeMessage,
javax.swing.GroupLayout.PREFERRED_SIZE, 86,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(82, Short.MAX_VALUE))
);
jPanelMain.add(jPanelPageWelcome, "card2");
jButton1.setText("Enter");
jLabel1.setText("Enter name of Tournament");
jLabel2.setText("Select Tournament Pairing Type");
jRadioButton1.setText("Ordered");
jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,
0, 0, 0));
jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton2.setText("Random");
jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,
0, 0, 0));
jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
javax.swing.GroupLayout jPanelPageNewLayout = new
javax.swing.GroupLayout(jPanelPageNew);
jPanelPageNew.setLayout(jPanelPageNewLayout);
jPanelPageNewLayout.setHorizontalGroup(
jPanelPageNewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanelPageNewLayout.createSequentialGroup()
.addContainerGap(283, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
.addGroup(jPanelPageNewLayout.createSequentialGroup()
.addGap(62, 62, 62)
.addGroup(jPanelPageNewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addGroup(jPanelPageNewLayout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE, 162,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel1)
.addGroup(jPanelPageNewLayout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(jPanelPageNewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2)
.addComponent(jRadioButton1))))
.addContainerGap(102, Short.MAX_VALUE))
);
jPanelPageNewLayout.setVerticalGroup(
jPanelPageNewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanelPageNewLayout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(24, 24, 24)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
42, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
);
jPanelMain.add(jPanelPageNew, "card3");
jMenuFile.setText("File");
jMenuItemNew.setText("New");
jMenuItemNew.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jMenuItemNewActionPerformed(evt);
}
});
jMenuFile.add(jMenuItemNew);
jMenuItemLoad.setText("Load");
jMenuItemLoad.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jMenuItemLoadActionPerformed(evt);
}
});
jMenuFile.add(jMenuItemLoad);
jMenuItemSave.setText("Save");
jMenuItemSave.setEnabled(false);
jMenuItemSave.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jMenuItemSaveActionPerformed(evt);
}
});
jMenuFile.add(jMenuItemSave);
jMenuFile.add(jSeparatorFileMenu);
jMenuItemExit.setText("Exit");
jMenuItemExit.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jMenuItemExitActionPerformed(evt);
}
});
jMenuFile.add(jMenuItemExit);
jMenuBar1.add(jMenuFile);
jMenuHelp.setText("Help");
jMenuItemAbout.setText("About");
jMenuItemAbout.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jMenuItemAboutActionPerformed(evt);
}
});
jMenuHelp.add(jMenuItemAbout);
jMenuBar1.add(jMenuHelp);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelMain,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(20, Short.MAX_VALUE)
.addComponent(jPanelMain,
javax.swing.GroupLayout.PREFERRED_SIZE, 225,
javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>
private void
jMenuItemNewActionPerformed(java.awt.event.ActionEvent evt)
{
java.awt.CardLayout cl = (CardLayout)jPanelMain.getLayout();
String path = "jPanelPagePageWelcome";
cl.show(jPanelMain,path);
System.out.println(path);
}
private void
jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt)
{
javax.swing.JFrame jFrameAbout = new
javax.swing.JFrame("About");
javax.swing.JLabel jLabel1 = new
javax.swing.JLabel("<html>Created by: <br>" +
"Chris Miceli<br>Will Folse<br>Michael Miceli<p>CSC
3380</html>");
jFrameAbout.setMinimumSize(new Dimension(300,150));
Point p1 = jPanelMain.getLocation();
jFrameAbout.setLocation((int)p1.getX()+100,(int)p1.getY()
+100);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jFrameAbout.getContentPane().add(jLabel1);
jFrameAbout.pack();
jFrameAbout.setVisible(true);
/**/
}
private void
jMenuItemSaveActionPerformed(java.awt.event.ActionEvent evt)
{
jFileChooser1 = new javax.swing.JFileChooser();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
int retval = jFileChooser1.showSaveDialog(Tester.this);
if (retval == jFileChooser1.APPROVE_OPTION) {
file = jFileChooser1.getSelectedFile();
}
System.out.println("File name is " + file.toString());
}
private void
jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
}
private void
jMenuItemLoadActionPerformed(java.awt.event.ActionEvent evt)
{
jFileChooser1 = new javax.swing.JFileChooser();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
int retval = jFileChooser1.showOpenDialog(Tester.this);
if (retval == jFileChooser1.APPROVE_OPTION) {
file = jFileChooser1.getSelectedFile();
}
System.out.println("File name is " + file.toString());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Tester().setVisible(true);
}
});
}
private File file;
private javax.swing.JFileChooser jFileChooser1;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabelWelcomeMessage;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenu jMenuFile;
private javax.swing.JMenu jMenuHelp;
private javax.swing.JMenuItem jMenuItemAbout;
private javax.swing.JMenuItem jMenuItemExit;
private javax.swing.JMenuItem jMenuItemLoad;
private javax.swing.JMenuItem jMenuItemNew;
private javax.swing.JMenuItem jMenuItemSave;
private javax.swing.JPanel jPanelMain;
private javax.swing.JPanel jPanelPageNew;
private javax.swing.JPanel jPanelPageWelcome;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JSeparator jSeparatorFileMenu;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
[/code]