import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.EtchedBorder;
public class WinInWin implements ActionListener
{
String path_FerixClient;
static String path_config;
String path_pics;
JButton btn_test, btn_test2;
JPanel panel_icons;
JPanel pane;
JToolBar toolbar1;
JToolBar toolbar2;
public JDesktopPane desktop = new JDesktopPane();
public Container cp;
JMenuBar menuleiste;
JInternalFrame frame;
public WinInWin(){
JFrame f = new JFrame();
f.setTitle("Desktop Window");
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.add( desktop );
f.setSize( 1100, 800 );
desktop.setBackground(new Color(200,200,200));
getMenuLeiste();
f.setJMenuBar(menuleiste);
f.setVisible( true );
}
public void getMenuLeiste()
{
menuleiste = new JMenuBar();
JMenu ebook = new JMenu ("EBook");
JMenuItem test2 = new JMenuItem ("test2");
test2.setActionCommand ("test2");
JMenuItem test = new JMenuItem ("test");
test.setActionCommand ("test");
test2.addActionListener(this);
test.addActionListener(this);
ebook.addSeparator();
ebook.add(test2);
ebook.addSeparator();
ebook.add(test);
menuleiste.setBorder(new EtchedBorder() );
menuleiste.setBackground(new Color(211,211,211));
menuleiste.add(ebook);
}
public static void main( String args[] )
{
new WinInWin();
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
//System.out.println(cmd);
if(cmd.equals("test2")){
if(!offen("test2")){
int begin_width = desktop.getWidth() - test2.getWidthFrame();
int begin_height = desktop.getHeight() - test2.getHeightFrame();
new test2("test2" , desktop, begin_width, begin_height);
setFrameInFront(test2.getInternalFrame());
}else{
setFrameInFront(test2.getInternalFrame());
}
}
if(cmd.equals("test")){
if(!offen("Test")){
int begin_width = desktop.getWidth() - test.getWidthFrame();
int begin_height = desktop.getHeight() - test.getHeightFrame();
new test("Test", desktop, begin_width, begin_height);
setFrameInFront(test.getInternalFrame());
}else{
setFrameInFront(test.getInternalFrame());
}
}
}
public boolean offen(String ueber_title)
{
boolean offen=false;
System.out.println("--------------------------------");
for (int i = 0; i < desktop.getComponentCount(); i++)
{
if (desktop.getComponent(i) instanceof JInternalFrame)
frame = (JInternalFrame) desktop.getComponent(i);
System.out.println("Titel : " + frame.getTitle());
if(frame.getTitle().equals(ueber_title)){
offen = true;
}
}
return offen;
}
private void setFrameInFront(JInternalFrame frame) {
try {
frame.setSelected(true);
} catch (PropertyVetoException e) {
JOptionPane.showMessageDialog(null, "Gewähltes Frame konnte nicht in den Vordergrund gestellt werden");
e.printStackTrace();
}
}
}