内部窗口不会显示在桌面窗格中

时间:2014-06-27 12:07:43

标签: java model-view-controller factory-pattern jinternalframe

在互联网上进行了一些研究后,我创建了一个桌面窗格,我想放置内部框架。我使用工厂模式创建多个内部框架(窗口)

我有抽象类

import javax.swing.*;
public abstract class InternalWindowTemplate extends JInternalFrame{
JInternalFrame internalWindow;

public final void createInternalWindow(String title, int width, int height, int xOffset, int yOffset, boolean isResizable, boolean isClosable, boolean isMaximizable, boolean isIconifiable){
    internalWindow = new JInternalFrame(title, isResizable, isClosable, isMaximizable, isIconifiable);

    setInternalWindowSize(width, height);
    setInternalWindowLocation(xOffset, yOffset);
    internalWindow.setVisible(true);
    internalWindow.setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);
     try {
        internalWindow.setSelected(true);
     } 
     catch (java.beans.PropertyVetoException exception) {
         exception.getMessage();
     }
     catch(Exception exception){
         exception.getMessage();
     }
}
 public void setInternalWindowLocation(int xOffset, int yOffset){
    setLocation(xOffset*getInternalWindowCounter(), yOffset*getInternalWindowCounter());
}

public void setInternalWindowSize(int width, int height){
    setSize(width,height);
}
}

然后我创建一个commandWindow:

import internalFrame.*;
import javax.swing.*;

public class CommandWindow extends InternalWindowTemplate {
   public CommandWindow(){
    createInternalWindow("Command window", 60, 40, 30, 30, false, true, false, false);
   }
}

最后,我为GUI创建了视图

import java.awt.*;
import javax.swing.*;

public class DesktopView extends JFrame{
private JDesktopPane desktop;
InternalWindowTemplate commandWindow;

public DesktopView(){
    //Make the big window be indented 50 pixels from each edge of the screen.
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width  - inset*2, screenSize.height - inset*2);

    //Set up the GUI.
    desktop = new JDesktopPane();
    commandWindow = new CommandWindow();
    desktop.add(commandWindow);
    setContentPane(desktop);
}
}

当我尝试在主

中运行它时
public class DesktopApp {
public static void main(String[] agrs){
    DesktopView desktopView = new DesktopView();
    desktopView.setVisible(true);
    desktopView.setDefaultCloseOperation(DesktopView.EXIT_ON_CLOSE);
}
}

我只获得“大”窗口,但不是内部。我究竟做错了什么?有没有我看不到的东西?任何建议,将不胜感激。提前谢谢

0 个答案:

没有答案