我有第一個框架包含一個按鈕。按下按鈕,我調用不同類的actionPerformed()方法。Java Swing:在不同類的ActionPerformed()中創建框架
JButton compress = new JButton("Submit");
compress.addActionListener(new Action1(inp,out,frame1)); // inp,out are textboxes and frame1 is 1st frame containing textboxes and JButton
在actionPerformed()類的Action1中。我已創建另一幀有如下
static class Action1 implements ActionListener {
JTextField input_path,out_path;
JFrame prev;
public Action1(JTextField inp,JTextField out,JFrame jf)
{
input_path = inp;
out_path = out;
prev = jf;
}
public void actionPerformed (ActionEvent e) {
prev.dispose();
try{
drawFrame();
// launch the compression job
launchJob(input_path.getText(),out_path.getText());
}
catch(IOException io){
io.printStackTrace();
}
}
public void drawFrame()
{
JFrame frame2 = new JFrame("New Frame");
JPanel panel = new JPanel();
frame2.setSize(400,300);
frame2.setLocation(500, 300);
JLabel label = new JLabel(" in Progress...");
panel.add(label);
frame2.add(panel);
frame2.setVisible(true);
}
}
但在的actionPerformed()時,幀2的內容物的方法launchJob之後得到可見()被執行。我想在我的函數launchJob()開始執行之前顯示(顯示)frame2的內容。你能否建議我哪裏出錯或有其他選擇。謝謝。
請參閱[使用多個JFrames,好/壞實踐?](http://stackoverflow.com/q/9554636/418556) –