【发布时间】:2016-05-17 21:10:57
【问题描述】:
我有一个包含按钮的第一帧。按下按钮时,我调用不同类的 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
在 Action1 类的 actionPerformed() 中。我在那里创建了另一个框架,如下所示
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() 中,frame2 的内容在方法 launchJob() 执行后变得可见。我想在我的函数 launchJob() 开始执行之前显示(使可见)frame2 的内容。您能否建议我哪里出错或其他替代方法。谢谢你。
【问题讨论】:
标签: java swing user-interface awt java-7