比如:FileChooser       aa=new       JFileChooser();   
          int       option=aa.showOpenDialog(this);//程序在这里就停下来,等待你的操作;   
              ..................//上面只要操作不结束,这里的代码就不会被执行 现在我想实现在JFrame的main函数里面加载一个JPanel   bb;在bb里面有2个按钮,一些文本框。   
假设main() 
{   
      this.add(bb);//这时候面板出来,我想程序想上面那样停下来等待,等待面板里面对按钮的操作   
      ..............//这里的代码,我想在等上面的bb面板的操作结束才执行   

请问怎么实现?谢谢了

解决方案 »

  1.   

    这个功能很简单,以下是我以前搞的一个例子:package PDFupload;import java.io.File;
    import javax.swing.JFileChooser;public class openSourceAction 
    {
    static final String newline = "\n"; public static void openDialog()
    {
    final int returnVal = doWithFrame.getFc().showOpenDialog(doWithFrame.getFrame()); if (returnVal == JFileChooser.CANCEL_OPTION) 
    {
    return;
    }
    if(returnVal == JFileChooser.APPROVE_OPTION) 
    {
    File file = null;
    file = doWithFrame.getFc().getSelectedFile(); 
    doWithFrame.getContent().append("打开目录: " + file.getAbsolutePath() + "." + newline);
    contentContainer.setSrcDir(file.getAbsolutePath());
    }
    if(!contentContainer.getBookInfoProportey()) 
    {
    doWithFrame.getContent().append("读取目录的属性文件失败!" + newline);
    }
    else 
    {
    doWithFrame.getSaveSourceButton().setEnabled(true); 
    // update.setEnabled(true);
    doWithFrame.getProgressBar().setValue(0);


    public static void openSave()
    {
    final int returnVal = doWithFrame.getFc().showOpenDialog(doWithFrame.getFrame()); if (returnVal == JFileChooser.CANCEL_OPTION) 
    {
    return;
    }
    if (returnVal == JFileChooser.APPROVE_OPTION) 
    {
    File file = null;
    file = doWithFrame.getFc().getSelectedFile();
    doWithFrame.getContent().append("您选择的保存目录: " + file.getAbsolutePath() + "." + newline);
    contentContainer.setSaveDir(file.getAbsolutePath());   
    doWithFrame.getOpenButton().setEnabled(false);
    doWithFrame.getUploadButton().setEnabled(true); 
    }
    }}
    个人认为你还是得学会看jdk文档,不然很难有所进步。
    好好学习,天天向上。
      

  2.   

    我不知道说什么,你可能没有看清楚我的意思,我不要对话框弹出来,我想用JPanel实现模态对话框那样,对话框出来等待别人操作,下面的代码在对话框操作结束以后才被执行。
      

  3.   

    你可以先创建一条线程,此线程包含你要控制运行的代码.然后给BUTTON加一个LISTNER.在ACTIONFORMED中实现这条线程,这样你就可以用BUTTON控制那段代码了
      

  4.   

    假设main()   
    {       
              //这里新起线程显示面板并负责唤醒此线程
                this.add(bb);//这时候面板出来,我想程序想上面那样停下来等待,等待面板里面对按钮的操作
               Thread.currentThread().interrupt();
           
                ..............//这里的代码,我想在等上面的bb面板的操作结束才执行       
    }   
      

  5.   

    其实要达到你的目的,最简单的方法是:在你的窗口的构造方法里,就到   this.add(bb);为止,然后,你在你面板的面板上定义它最后(完成其他事情之后)触发一个事件,在事件处理方法里再做你窗口里需要做的后面的事情。