2012-12-13 19 views
0

當用戶點擊編輯按鈕,一個新的幀顯示給他們,當新框架被關閉,我想刷新線來執行,但問題是,刷新線是在關閉新框架之前執行......我使用NetBeans製作UI。一個JFrame中不停止其他框架的代碼

//If user clicks on edit button new frame will be shown to him 
EditUserFrame editUserFrame = new EditUserFrame(); 
Iterator itr = userList.iterator(); 
while(itr.hasNext()){ 
    user = (Users)itr.next(); 
    if((user.getF_name().equals(f_name) && user.getL_name().equals(l_name))){ 
     break; 
    } 
}//End of While Loop 
editUserFrame.setUserObj(user); 
editUserFrame.getExistingValues(); 
editUserFrame.setVisible(true); 
//I want this line to be executed when the editUserFrame is closed.. 
RefreshUserTable(); 

我想要像這樣的新框架可以使JOPtionPane中的圖片給出,就像你們建議的那樣。

enter image description here

+0

參見[多重的用途JFrames,好/壞(http://stackoverflow.com/a/9554657/418556) –

回答

1

可以使用

'editUserFrame.addWindowListener(new WindowAdapter() 
{ 
    public void windowClosed(WindowEvent e){ 
    //call your method from here 
     RefreshUserTable(); 
    } 
};' 

希望這有助於

+0

偉人它的工作... –

+0

也有一些其他的方法來做到這一點,但是這一次我覺得這就夠了。很高興我可以得到一些幫助。 – Aworx

+0

@HaseebWali我注意到你在你的表單中有驗證,因此使用JOptionPane OK_CANCEL並不是理想的解決方案,因爲你沒有直接訪問OK按鈕 - 有可能檢索OK按鈕的額外工作。總之使用OK_CANCEL類型的JOptionPane的可能不是最好的解決辦法。在這種情況下你 – Aworx

3

你想用某種形式的模態對話框。對話框旨在在程序顯示位置「暫停」程序的執行。

退房How to Make Dialogs

你也可以使用一個JOptionPane,使您更容易一樣,因爲他們可以用不同的按鈕/選項比較容易進行配置。退房JOptionPane Features與示例更新的概述

enter image description here

public class TestOptionPane01 { 

    public static void main(String[] args) { 
     new TestOptionPane01(); 
    } 

    public TestOptionPane01() { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
       } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 
       } 

       FormPane formPane = new FormPane(); 
       int result = JOptionPane.showConfirmDialog(
           null, 
           formPane, 
           "Edit User", 
           JOptionPane.OK_CANCEL_OPTION, 
           -1); 

       switch (result) { 

        case JOptionPane.OK_OPTION: 
         System.out.println("You selected okay"); 
         break; 
        case JOptionPane.OK_CANCEL_OPTION: 
         System.out.println("You selected cancel"); 
         break; 

       } 

      } 
     }); 
    } 

    public class FormPane extends JPanel { 

     public FormPane() { 

      setLayout(new GridBagLayout()); 
      GridBagConstraints gbc = new GridBagConstraints(); 
      gbc.gridx = 0; 
      gbc.gridy = 0; 
      gbc.insets = new Insets(2, 2, 2, 2); 
      gbc.gridwidth = GridBagConstraints.REMAINDER; 
      gbc.weightx = 1; 
      gbc.fill = GridBagConstraints.HORIZONTAL; 
      gbc.anchor = GridBagConstraints.WEST; 
      add(new JLabel("Edit User"), gbc); 
      gbc.gridy++; 
      add(new JSeparator(), gbc); 

      gbc.gridwidth = 1; 
      gbc.weightx = 0; 
      gbc.fill = GridBagConstraints.NONE; 
      gbc.gridy++; 
      add(new JLabel("Fill all fields to edit user tecord"), gbc); 

      gbc.gridy++; 
      gbc.gridheight = 2; 
      add(new JLabel("Select Image Icon"), gbc); 
      gbc.gridheight = 1; 
      gbc.gridy += 2; 
      add(new JLabel("First Name"), gbc); 
      gbc.gridy++; 
      add(new JLabel("Last Name"), gbc); 
      gbc.gridy++; 
      add(new JLabel("Password"), gbc); 
      gbc.gridy++; 
      add(new JLabel("Confirm Password"), gbc); 
      gbc.gridy++; 
      add(new JLabel("Email Address"), gbc); 

      gbc.gridx++; 
      gbc.gridy = 3; 
      gbc.anchor = GridBagConstraints.EAST; 
      add(new JLabel("Maximum Image Size 32x32"), gbc); 
      gbc.gridy++; 
      add(new JButton("Select"), gbc); 
      gbc.fill = GridBagConstraints.HORIZONTAL; 
      gbc.gridy++; 
      add(new JTextField(10), gbc); 
      gbc.gridy++; 
      add(new JTextField(10), gbc); 
      gbc.gridy++; 
      add(new JTextField(10), gbc); 
      gbc.gridy++; 
      add(new JTextField(10), gbc); 

      gbc.gridx++; 
      gbc.gridy = 3; 
      gbc.anchor = GridBagConstraints.CENTER; 
      gbc.gridheight = 3; 
      gbc.fill = GridBagConstraints.BOTH; 
      JPanel panel = new JPanel(); 
      panel.setBorder(new BevelBorder(BevelBorder.RAISED)); 
      add(panel, gbc); 
      gbc.gridy += 3; 
      gbc.gridheight = 1; 
      gbc.fill = GridBagConstraints.NONE; 
      add(new JButton("Clear Image"), gbc); 

     } 

    } 


} 
+0

@AndrewThompson乾杯;) – MadProgrammer

+0

@Haseeb Wali使用'JOptionPane' – mKorbel

+0

考慮我的編輯並給我一些指導 –

相關問題