Voici un exemple
Frame1:
package onglet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();
JTabbedPane jTabbedPane1 = new JTabbedPane();
private Frame2[] appli = new Frame2[2];
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setBounds(new Rectangle(27, 16, 352, 30));
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
contentPane.setOpaque(true);
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jTabbedPane1.setBounds(new Rectangle(22, 62, 369, 230));
contentPane.add(jButton1, null);
contentPane.add(jTabbedPane1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
for (int i = 0; i < 2; i++) {
appli[i] = new Frame2();
this.getContentPane().add(appli[i]);
appli[i].setVisible(true);
}
}
}
class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
Frame2
package onglet;
import javax.swing.*;
import java.awt.*;
public class Frame2 extends JFrame {
JButton jButton1 = new JButton();
public Frame2() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(85, 91, 183, 41));
jButton1.setText("jButton1");
this.setLocale(java.util.Locale.getDefault());
this.getContentPane().setLayout(null);
this.getContentPane().add(jButton1, null);
}
}
comment changer frame2 en JPanel????
Code de la route GRATUIT