Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Actions from Components #1

Closed
1chooo opened this issue Mar 26, 2024 · 0 comments
Closed

Separate Actions from Components #1

1chooo opened this issue Mar 26, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@1chooo
Copy link
Owner

1chooo commented Mar 26, 2024

addActionListener(new MenuItemAction());

Currently, we need to use 'if' statements to perform Actions. In the future, we should be able to separate Actions from Components, and also provide enum Actions for direct use, similar to the concept of STATUS_CODE.

Current Action Class:

package src.Actions;

import javax.swing.*;
import java.awt.event.*;
import src.Utils.StatusCode;

public class MenuItemAction extends JMenu implements ActionListener {
    public MenuItemAction() { }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("About XML Editor")) {
            aboutAction(e);
        } else if (e.getActionCommand().equals("Quit (Control + Q)")) {
            exitAction(e);
        }
    }

    private void aboutAction(ActionEvent e) {
        String message = "Hello World! This is a simple XML Editor.";
        JOptionPane.showMessageDialog(null, message);
    }

    private void exitAction(ActionEvent e) {
        System.exit(StatusCode.EXIT);
    }
}
@1chooo 1chooo added enhancement New feature or request good first issue Good for newcomers labels Mar 26, 2024
@1chooo 1chooo self-assigned this Mar 26, 2024
1chooo added a commit that referenced this issue Apr 1, 2024
@1chooo 1chooo closed this as completed Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant