package gui;
/*
* MainFrame.java
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MainFrame extends JFrame{
private static final long serialVersionUID = 1L;
private boolean windowswitcher = false;
private MainPanel mp;
private SetupPanel sp;
public MainFrame(){
createAndShowFrameGUI();
windowswitcher = true;
changePanelOnGUI();
}
// für erstes ma aufrufen
public void createAndShowFrameGUI() {
mp = new MainPanel(this);
sp = new SetupPanel(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("BootOutAll");
getContentPane().add(mp);
setSize(400, 200);
setLocationRelativeTo(null); //center it
setVisible(true);
}
// für änderungen und wechsel
public void changePanelOnGUI() {
if(!windowswitcher) {
getContentPane().remove(sp);
getContentPane().add(mp);
validate();
repaint();
}else{
getContentPane().remove(mp);
getContentPane().add(sp);
validate();
repaint();
}
}
public boolean isWindowswitcher() {
return windowswitcher;
}
public void setWindowswitcher(boolean windowswitch) {
windowswitcher = windowswitch;
}
public static void main(final String[] args){new MainFrame();}
}
class SetupPanel extends JPanel implements ItemListener {
private static final long serialVersionUID = 5352427104900708556L;
// element
private JLabel setupheadline = new JLabel("BootOutAll by Xenexes");
private JButton closesave = new JButton("Save");
private JButton test = new JButton("Test (MainPanel)");
private MainFrame parent;
// *************************************************************************************************************
// ******************** constructor ****************************************************************************
// *************************************************************************************************************
public SetupPanel(MainFrame parent) {
this.parent = parent;
// element-configuration
//setupheadline.setOpaque(true);
setupheadline.setPreferredSize(new Dimension(600,80));
setupheadline.setBackground(new Color( 0x9b7e5f ));
setupheadline.setFont( new Font( "Georgia", Font.BOLD + Font.ITALIC, 33 ) );
setupheadline.setForeground(new Color( 0x686058));
//Listener
test.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
testActionPerformed(evt);
}
});
closesave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
closesaveActionPerformed(evt);
}
});
setLayout(new GridLayout(0,1));
// add component container
//add(grafikpanel, BorderLayout.NORTH);
add(test);
// zum testen ausgeblendet
add(createMainPanel());
}
// *************************************************************************************************************
// ******************** component container ********************************************************************
// *************************************************************************************************************
public JComponent createMainPanel() {
// create container
Box box1 = Box.createHorizontalBox();
Box box2 = Box.createHorizontalBox();
Box box3 = Box.createVerticalBox();
Component spacer2 = Box.createHorizontalGlue();
Component spacer = Box.createHorizontalStrut(0);
// Add everything to a container.
box1.add(closesave);
box1.add(spacer);
box1.add(spacer2);
//box1.add(closesave);
box2.add(setupheadline);
box3.add(box2);
box3.add(box1);
box1.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
box2.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
box3.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
return box3;
}
// *************************************************************************************************************
// ******************** events *********************************************************************************
// *************************************************************************************************************
private void closesaveActionPerformed(final ActionEvent evt) {
parent.setWindowswitcher(false);
parent.changePanelOnGUI();
}
private void testActionPerformed(final ActionEvent evt) {
parent.setWindowswitcher(false);
parent.changePanelOnGUI();
}
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
}
}
class MainPanel extends JPanel{
private JButton bt;
private MainFrame parent;
public MainPanel(MainFrame parent){
this.parent = parent;
bt = new JButton("Test (SetupPanel)");
add(bt, BorderLayout.NORTH);
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doBtAction();
}
});
}
private void doBtAction(){
parent.setWindowswitcher(true);
parent.changePanelOnGUI();
}
}