Olá Pessoal!!!
Bom pessoal depois de quase uma noite inteira tentando fazer isso ainda naum consegui, vou colocar meu codigo para ficar mais facil o entendimento, peço a ajuda de todos pois acho que ja tentei de td mas não da certo. Tenho dois Jpanel e um frame Principal, gostaria de add os Jpannel ao JFrame na medida em que os eventos dos botoes forem chamados, segue abiaxo as classes, que poder ajudar fico extremamente agradecido.
[code]
public class FrameP extends javax.swing.JFrame {
/** Creates new form FrameP */
public FrameP() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButtonp1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Frame Principal");
jButtonp1.setText("Panel 1");
jButtonp1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonp1ActionPerformed(evt);
}
});
jButton2.setText("Panel 2");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButtonp1)
.add(jButton2))
.addContainerGap(569, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(33, 33, 33)
.add(jButtonp1)
.add(18, 18, 18)
.add(jButton2)
.addContainerGap(312, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButtonp1ActionPerformed(java.awt.event.ActionEvent evt) {
new JPanel1().show();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrameP().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton2;
private javax.swing.JButton jButtonp1;
// End of variables declaration
} [/code]
classe Jpanel1
[code]
public class JPanel1 extends javax.swing.JPanel {
/** Creates new form JPane1l */
public JPanel1() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jComboBoxP1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jComboBoxP1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jButton1.setText("OK1");
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(51, 51, 51)
.add(jComboBoxP1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 54, Short.MAX_VALUE)
.add(jButton1)
.add(141, 141, 141))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(79, 79, 79)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jComboBoxP1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(198, Short.MAX_VALUE))
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBoxP1;
// End of variables declaration
} [/code]
Classe jpanel2
public class JPanel2 extends javax.swing.JPanel {
/** Creates new form JPane2l */
public JPanel2() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jComboBoxP2 = new javax.swing.JComboBox();
jButtonOk = new javax.swing.JButton();
setLayout(null);
jComboBoxP2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
add(jComboBoxP2);
jComboBoxP2.setBounds(50, 50, 140, 22);
jButtonOk.setText("OK2");
add(jButtonOk);
jButtonOk.setBounds(210, 50, 55, 23);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JButton jButtonOk;
private javax.swing.JComboBox jComboBoxP2;
// End of variables declaration
}
Oq não entendi foi que ao criar o main dos paineis add eles ao Frame e no eveto dos botoes os chama mas não acontecia nada