2017-01-21 25 views
0

,這似乎不符合的WindowBuilder在上班的路上插件已在Config中設置了gui。當前一個命令運行時,它會創建一個空的小JFrame。配置的主要方法只包含以下內容:如何叫我習慣能夠通過運行</p> <pre><code>Config con = new Config(); con.setVisible(true); </code></pre> <p>但是創建另一個類的實例,它使用的WindowBuilder(Eclipse中)創建了一個類

public static void main(String[] args) { 
    EventQueue.invokeLater(new Runnable() { 
     public void run() { 
      try { 
       Config window = new Config(); 
       window.frame.setVisible(true); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    }); 
} 

構造函數只是調用它包含內容創建一個初始化方法:

public Config(){ 
initialize(); 
} 
private void initialize() { 
     frame = new JFrame(); 
     frame.setBounds(100, 100, 450, 300); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.getContentPane().setLayout(null); 
     frame.setLocationRelativeTo(null); 
     frame.setResizable(false); 

//other configuration here 
} 

我如何可以調用配置從另一個類運行,可見?

回答

0

好的,找到答案。首先,爲了阻止顯示微小的無用幀,不要在初始類中設置可見。相反,只需運行:

Config con = new Config(); 

然後,在配置的構造函數,初始化後一切,加上

frame.setVisible(true); 
相關問題