import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.CardLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class mainframe extends JFrame {
private JPanel contentPane;
private CardLayout layout;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
mainframe frame = new mainframe();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public mainframe() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
layout = new CardLayout();
JPanel content = new JPanel(layout);
contentPane.add(content, BorderLayout.CENTER);
// content.setLayout(new CardLayout(0, 0));
JPanel page1 = new JPanel();
content.add(page1, "PAGE1");
page1.setLayout(null);
JLabel lblSeite1 = new JLabel("Seite1");
lblSeite1.setBounds(178, 123, 66, 15);
page1.add(lblSeite1);
JPanel page2 = new JPanel();
content.add(page2, "Page2");
page2.setLayout(null);
JLabel lblSeite2 = new JLabel("Seite2");
lblSeite2.setBounds(172, 111, 66, 15);
page2.add(lblSeite2);
JMenuBar menuBar = new JMenuBar();
contentPane.add(menuBar, BorderLayout.NORTH);
JMenuItem mntmSeite = new JMenuItem("Seite1");
mntmSeite.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
layout.show(content, "PAGE1");
}
});
menuBar.add(mntmSeite);
JMenuItem mntmSeite_1 = new JMenuItem("Seite2");
mntmSeite_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
layout.show(content, "PAGE2");
}
});
menuBar.add(mntmSeite_1);
}
}