如何实现:
在主页面中点击某个操作后,弹出一个只显示“正在保存”和一个滚动条,不能执行其他的操作的窗口;
等后台程序执行完毕后,关闭弹出的窗口,并且显示“保存完成”的对话框;
点击对话框上的“确定”按钮后,刷新主页面。弹出那个显示“正在保存”窗口的目的是在执行后台程序时,主页面上的按钮是不可用的,因为后台程序有一个接受远程机器发送的Socket数据包的线程操作。
如何实现上述功能?小弟一点实现思路也没有,高分送出,望各位高手多多指导

解决方案 »

  1.   

    呵呵,我是个超级菜鸟,没有写过程序,不过我知道Swing包里的JProgressBar 和ProgressMonitor可以实现你要的功能
      

  2.   

    JDK带有的Demo中有一个Notepad.jar的例子,在保存文件、打开文件的时候都是实现了你的要求的。
      

  3.   

    //这个不是JFrame是JWindow
    import java.awt.Color;
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.JWindow;
    import javax.swing.border.LineBorder;public class WindowTest extends JFrame
    {
    class ToolTipWindow extends JWindow implements Runnable
    {
    private final class MouseAdapterL extends MouseAdapter
    {
    public void mouseReleased(MouseEvent e)
    {
    maybeShowPopup(e);
    } private void maybeShowPopup(MouseEvent e)
    {
    if (e.isPopupTrigger())
    {
    popup.show(e.getComponent(), e.getX(), e.getY());
    }
    } public void mousePressed(MouseEvent e)
    {
    p1 = e.getPoint();
    } JPopupMenu popup; MouseAdapterL(JPopupMenu popupMenu)
    {
    popup = popupMenu;
    } public void mouseEntered(MouseEvent e)
    {
    super.mouseEntered(e);
    mouseEntered = true;
    } public void mouseExited(MouseEvent e)
    {
    super.mouseExited(e);
    mouseEntered = false;
    }
    } public void run()
    {
    StringBuffer buffer = new StringBuffer("       永远在最前面的窗口");
    int index = 0;
    int len = buffer.length();
    StringBuffer buffer2 = new StringBuffer(len);
    while (true)
    {
    if (!mouseEntered)
    {
    index = ((++index) % len);
    buffer2.setLength(0);
    buffer2.append(buffer.substring(index));
    buffer2.append(buffer.substring(0, index));
    label.setText(buffer2.toString());
    }
    try
    {
    Thread.sleep(200);
    }
    catch (InterruptedException e)
    {
    e.printStackTrace();
    }
    }
    } private JLabel label; Point p1; public ToolTipWindow(JFrame frame)
    {
    super(frame);
    getContentPane().add(getLabel());
    setLocation(100, 10);
    setSize(400, 20);
    setVisible(true);
    } JPopupMenu popup; private boolean mouseEntered; protected JLabel getLabel()
    {
    if (label == null)
    {
    label = new JLabel("       永远在最前面的窗口");
    label.setBorder(new LineBorder(Color.WHITE, 2, true));
    // Create the popup menu.
    popup = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem("A popup menu item");
    popup.add(menuItem);
    label.addMouseMotionListener(new MouseMotionAdapter()
    {
    public void mouseDragged(MouseEvent e)
    {
    setLocation(getLocation().x + e.getPoint().x - p1.x, getLocation().y + e.getPoint().y - p1.y);
    }
    });
    label.addMouseListener(new MouseAdapterL(popup));
    }
    return label;
    }
    } /**
     * Launch the application
     * 
     * @param args
     */
    public static void main(String args[])
    {
    try
    {
    WindowTest frame = new WindowTest();
    ToolTipWindow win = frame.new ToolTipWindow(frame);
    win.toFront();
    (new Thread(win)).start();
    frame.setVisible(true);
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    } /**
     * Create the frame
     */
    public WindowTest()
    {
    super();
    setBounds(100, 100, 500, 375);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    //
    }
    }
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;/*
     * ProgressBarDemo2.java is a 1.4 application that requires these files:
     *   LongTask.java
     *   SwingWorker.java
     */
    public class ProgressBarDemo2 extends JPanel
                                  implements ActionListener {
        public final static int ONE_SECOND = 1000;    private JProgressBar progressBar;
        private Timer timer;
        private JButton startButton;
        private LongTask task;
        private JTextArea taskOutput;
        private String newline = "\n";    public ProgressBarDemo2() {
            super(new BorderLayout());
            task = new LongTask();        //Create the demo's UI.
            startButton = new JButton("Start");
            startButton.setActionCommand("start");
            startButton.addActionListener(this);        progressBar = new JProgressBar(0, task.getLengthOfTask());
            progressBar.setValue(0);        //We call setStringPainted, even though we don't want the
            //string to show up until we switch to determinate mode,
            //so that the progress bar height stays the same whether
            //or not the string is shown.
            progressBar.setStringPainted(true); //get space for the string
            progressBar.setString("");          //but don't paint it        taskOutput = new JTextArea(5, 20);
            taskOutput.setMargin(new Insets(5,5,5,5));
            taskOutput.setEditable(false);        JPanel panel = new JPanel();
            panel.add(startButton);
            panel.add(progressBar);        add(panel, BorderLayout.PAGE_START);
            add(new JScrollPane(taskOutput), BorderLayout.CENTER);
            setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));        //Create a timer.
            timer = new Timer(ONE_SECOND, new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    progressBar.setValue(task.getCurrent());
                    String s = task.getMessage();
                    if (s != null) {
                        if (progressBar.isIndeterminate()) {
                            progressBar.setIndeterminate(false);
                            progressBar.setString(null); //display % string
                        }
                        taskOutput.append(s + newline);
                        taskOutput.setCaretPosition(
                                taskOutput.getDocument().getLength());
                    }
                    if (task.isDone()) {
                        Toolkit.getDefaultToolkit().beep();
                        timer.stop();
                        startButton.setEnabled(true);
                        progressBar.setValue(progressBar.getMinimum());
                        progressBar.setString(""); //hide % string
                    }
                }
            });
        }    /**
         * Called when the user presses the start button.
         */
        public void actionPerformed(ActionEvent evt) {
            progressBar.setIndeterminate(true);
            startButton.setEnabled(false);
            task.go();
            timer.start();
        }    /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);        //Create and set up the window.
            JFrame frame = new JFrame("ProgressBarDemo2");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        //Create and set up the content pane.
            JComponent newContentPane = new ProgressBarDemo2();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);        //Display the window.
            frame.pack();
            frame.setVisible(true);
        }    public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }