From c45c0ad70cdf23a3db6fb0fd8c6a936f2bd110c7 Mon Sep 17 00:00:00 2001 From: Matthew Biegel Date: Thu, 12 Mar 2026 14:44:49 -0400 Subject: [PATCH] Implement drop-down menu in SimpleEditor Added a drop-down menu with File, Edit, Search, and Help options, including menu items for new, open, save, and exit functionalities. --- src/simpleUi/SimpleEditor.java | 69 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/simpleUi/SimpleEditor.java b/src/simpleUi/SimpleEditor.java index ad3c015..c65cafa 100644 --- a/src/simpleUi/SimpleEditor.java +++ b/src/simpleUi/SimpleEditor.java @@ -4,6 +4,7 @@ import javax.swing.*; import javax.swing.text.*; +//ui improvements needed, drop down menu /* * Concrete implementation of the Editor interface, @@ -36,7 +37,7 @@ public SimpleEditor(String title) { * @return none */ private void init() { - area.setLineWrap(true); + area.setLineWrap(true); area.setWrapStyleWord(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -78,7 +79,71 @@ private String getNumbers() { content1.add(buttonRow, BorderLayout.SOUTH); frame.setContentPane(content1); - } + + //adding drop down menu + + // 1. Create the Menu Bar + JMenuBar menuBar = new JMenuBar(); + + // 2. Create a Menu (e.g., File) + JMenu fileMenu = new JMenu("File"); + JMenu editMenu = new JMenu("Edit"); + JMenu searchMenu = new JMenu("Search"); + JMenu helpMenu = new JMenu("Info"); + + // 3. Create Menu Items + JMenuItem newItem = new JMenuItem("New"); + JMenuItem openItem = new JMenuItem("Open"); + JMenuItem saveItem = new JMenuItem("Save"); + JMenuItem exitItem = new JMenuItem("Exit"); + + // 4. Add items to the file menu + fileMenu.add(newItem); + fileMenu.add(saveItem); + fileMenu.add(openItem); + fileMenu.addSeparator(); // Adds a visual line + fileMenu.add(exitItem); + + editMenu.add(new JMenuItem("Undo")); + editMenu.add(new JMenuItem("Redo")); + editMenu.add(new JMenuItem("Clear")); + + searchMenu.add(new JMenuItem("Find")); + searchMenu.add(new JMenuItem("Replace")); + searchMenu.add(new JMenuItem("Highlight Matches")); + + + // 5. Add menu to the bar, and bar to the frame + menuBar.add(fileMenu); + menuBar.add(editMenu); + menuBar.add(searchMenu); + menuBar.add(helpMenu); + frame.setJMenuBar(menuBar); + + + JMenuItem helpItem = new JMenuItem("Help"); + + helpItem.addActionListener(e -> { + JOptionPane.showMessageDialog( + frame, + "Welcome to the our Text Editor!\n\n" + + "File:\nOpen and save text and java files.\n\n" + + "Edit:\nUndo, redo, and clear text.\n\n" + + "Search:\nFind words and replace text.\n\n" + + "Use the buttons or menus to perform actions.\n\n" + + "Brought to you by: Matthew Biegel, Robert Conti, \nMichael McGrath, Rui Li, Luke Padilla \n 2026", + "Help", + JOptionPane.INFORMATION_MESSAGE + ); + }); + + helpMenu.add(helpItem); + menuBar.add(helpMenu); + + // 6. Add logic to the items (optional but recommended) + exitItem.addActionListener(e -> System.exit(0)); + } + @Override protected void uiShow() { SwingUtilities.invokeLater(() -> frame.setVisible(true));