如何在不终止程序的情况下关闭第二个JFrame

时间:2014-08-11 19:17:17

标签: java eclipse swing jframe frame

如何在保留MainFrame的同时处理第二帧?

我有一个JFrame(CCurrencyConverterFrame),我从主框架调用。

    JMenuItem mntmCurrencyConverter = new JMenuItem("Currency Converter");
    mntmCurrencyConverter.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CCurrencyConverterFrame frame = new CCurrencyConverterFrame();
            myFrame = frame;
            JPanel contentPane = new CCurrencyConverter(myFrame);
            frame.setContentPane(contentPane);
            frame.setVisible(true);
        }
    });

在CCurrencyConverterFrame.java中,

    public CCurrencyConverterFrame() {
    setFont(new Font("Dialog", Font.BOLD, 12));
    getContentPane().setFont(new Font("Tahoma", Font.BOLD, 16));
    setTitle("Currency Converter ");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 469, 470);
    //Center
    setLocationRelativeTo(null) ;
    }

我尝试过使用JFrame.HIDE_ON_CLOSE,但它仍然会终止我的应用程序。我该怎么做才能解决这个问题?

0 个答案:

没有答案