2

JFrames在 NetBeans 编辑器中设计了两个(mainFrame.java 和 child.java)。我想JFrame从第一帧调用第二个作为子窗口。我怎么称呼它?

4

3 回答 3

2
于 2012-09-25T12:09:14.430 回答
0

制作第一帧的对象,然后在第二帧调用它。

firstframe fm = new firstframe();
fm.setVisible(true);
于 2012-09-27T07:56:06.250 回答
0

如果我理解正确,您希望在其中有一个带有子/子窗口的主窗口。如果是这样,请查看以下代码。

截屏:在此处输入图像描述

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
 * Sample demonstrates using JInternalFrame as a child window of a main
 * JFrame window  TicTacToe class extends JInternalFrame.
 * @author Kirk
 *
*/
public class BoardBuilder extends JFrame {

    private TicTacToe board;
    JDesktopPane desktopPane = new JDesktopPane();

    public BoardBuilder() {
        SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               board = new TicTacToe("TicToc Toe", true);
               board.setSize(250, 250);
               board.setClosable(true);
               board.setIconifiable(true);
               board.setDefaultCloseOperation(TicTacToe.DISPOSE_ON_CLOSE);
               if (!board.isVisible())
                   board.setVisible(true);

               desktopPane.add(board);
               add(desktopPane);
           }
       });

   }

   public static void main(String[] args) {
       BoardBuilder builderBoard = new BoardBuilder();
       builderBoard.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
       builderBoard.setSize(640, 480);
       builderBoard.setVisible(true);

    }

   }

调用子窗口将此代码块放在按钮单击事件侦听器中

SwingUtilities.invokeLater(new Runnable() {
               public void run() {
               board = new TicTacToe("TicToc Toe", true);
               board.setSize(250, 250);
               board.setClosable(true);
               board.setIconifiable(true);
               board.setDefaultCloseOperation(TicTacToe.DISPOSE_ON_CLOSE);
               if (!board.isVisible())
                   board.setVisible(true);

               desktopPane.add(board);
               add(desktopPane);
           }
       });

有关未来信息,请查看此链接docs.oracle-InternalFrames

于 2017-11-13T04:43:32.020 回答