构造函数WindowEvent(WelcomeWindow,int)未定义

时间:2016-05-23 23:48:44

标签: java constructor jframe

尝试为我的Windowalthough java实现一个close方法给我一个

“构造函数WindowEvent(WelcomeWindow,int)未定义”:ERROR

行给出错误“WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);

你能帮帮我吗

public class WelcomeWindow {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    WelcomeWindow window = new WelcomeWindow();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public WelcomeWindow() {
        initialize();
    }


    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 248, 357);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{86, 0, 79, 0};
        gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
        gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
        gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
        frame.getContentPane().setLayout(gridBagLayout);

        JButton btnNewButton = new JButton("Shop");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {

            }
        });
        GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
        gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
        gbc_btnNewButton.gridx = 1;
        gbc_btnNewButton.gridy = 2;
        frame.getContentPane().add(btnNewButton, gbc_btnNewButton);

        JButton btnNewButton_1 = new JButton("Manage Store");
        GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
        gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
        gbc_btnNewButton_1.gridx = 1;
        gbc_btnNewButton_1.gridy = 3;
        frame.getContentPane().add(btnNewButton_1, gbc_btnNewButton_1);

        JButton btnManageUsers = new JButton("Manage Users");
        GridBagConstraints gbc_btnManageUsers = new GridBagConstraints();
        gbc_btnManageUsers.insets = new Insets(0, 0, 0, 5);
        gbc_btnManageUsers.gridx = 1;
        gbc_btnManageUsers.gridy = 5;
        frame.getContentPane().add(btnManageUsers, gbc_btnManageUsers);
    }
    public void close(){
        WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
    }

}

1 个答案:

答案 0 :(得分:1)

您尝试用于“WindowEvent”的构造函数如下:

WindowEvent(Window source, int id)

所以为了使用你,“WelcomeWindow”类应该继承自

java.awt.Window

由于你没有覆盖Window构造函数,我猜你没有这样做。

此处继续参考:Java7 Docs