2012-09-25 55 views
2

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

+1

怎么办你想打电话吗? –

+0

点击mainFrame.java @LewsTherin中的按钮后,我想调用child.java。 –

回答

0

使第一帧的对象然后在第二帧中调用它。

firstframe fm = new firstframe(); 
fm.setVisible(true); 
0

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

截屏:enter image description here

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); 

    } 

    } 

调用子窗口发生在按钮的Click事件的代码块监听

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