I want to reference a JPanel I created in the NetBeans GUI Editor. It lives in a class called 'NGWCard1', which extends JPanel and uses 'this' to refer to the JPanel. I can't change the code because it won't let me. Can anyone help?
I put the class in its own file 'NGWCard1.java' and put that into a package. What I want is to reference the JPanel in NGWCard1 remotely from another class with its own .java file in the package.
This is the code in the other class that should reference the JPanel in the NGWCard1 class:
public class NGWCard1 extends javax.swing.JPanel {
/**
* Creates new form NGWCard1
*/
public NGWCard1() {
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() {
ngwBackCrd1 = new javax.swing.JButton();
ngwClearCrd1 = new javax.swing.JButton();
ngwCancelCrd1 = new javax.swing.JButton();
ngwNextCrd1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
ngwInnerJPanel = new javax.swing.JPanel();
ngwBackCrd1.setText("Back");
ngwBackCrd1.setEnabled(false);
ngwBackCrd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ngwBackCrd1ActionPerformed(evt);
}
});
ngwClearCrd1.setText("Clear");
ngwClearCrd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ngwClearCrd1ActionPerformed(evt);
}
});
ngwCancelCrd1.setText("Cancel");
ngwCancelCrd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ngwCancelCrd1ActionPerformed(evt);
}
});
ngwNextCrd1.setText("Next");
ngwNextCrd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ngwNextCrd1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Helvetica", 1, 14));
jLabel1.setText("Please enter a title for your new game in the field below");
org.jdesktop.layout.GroupLayout ngwInnerJPanelLayout = new org.jdesktop.layout.GroupLayout(ngwInnerJPanel);
ngwInnerJPanel.setLayout(ngwInnerJPanelLayout);
ngwInnerJPanelLayout.setHorizontalGroup(
ngwInnerJPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 597, Short.MAX_VALUE)
);
ngwInnerJPanelLayout.setVerticalGroup(
ngwInnerJPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 293, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(127, 127, 127)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(ngwBackCrd1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 84, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 19, Short.MAX_VALUE)
.add(ngwClearCrd1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 84, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(ngwCancelCrd1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 84, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(ngwNextCrd1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 87, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(131, 131, 131))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(ngwInnerJPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.linkSize(new java.awt.Component[] {ngwBackCrd1, ngwCancelCrd1, ngwClearCrd1, ngwNextCrd1}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(ngwInnerJPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(44, 44, 44)
.add(jLabel1)
.add(42, 42, 42)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(34, 34, 34)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(ngwBackCrd1)
.add(ngwClearCrd1)
.add(ngwCancelCrd1)
.add(ngwNextCrd1))
.add(107, 107, 107))
);
layout.linkSize(new java.awt.Component[] {ngwBackCrd1, ngwCancelCrd1, ngwClearCrd1, ngwNextCrd1}, org.jdesktop.layout.GroupLayout.VERTICAL);
}// </editor-fold>
private void ngwNextCrd1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ngwCancelCrd1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ngwClearCrd1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ngwBackCrd1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public void GetThisCard() {
initComponents();
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JButton ngwBackCrd1;
private javax.swing.JButton ngwCancelCrd1;
private javax.swing.JButton ngwClearCrd1;
private javax.swing.JPanel ngwInnerJPanel;
private javax.swing.JButton ngwNextCrd1;
// End of variables declaration
}