| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package frames;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- @SuppressWarnings("serial")
- public class MenuBar extends JMenuBar{
- public MenuBar(){
- initialize();
- }
-
- private void initialize(){
- JMenu fileMenu = new JMenu("File");
- JMenu editMenu = new JMenu("Edit");
- JMenu viewMenu = new JMenu("View");
- JMenu helpMenu = new JMenu("Help");
- this.add(fileMenu);
- this.add(editMenu);
- this.add(viewMenu);
- this.add(helpMenu);
-
- JMenuItem newAction = new JMenuItem("New");
- JMenuItem openAction = new JMenuItem("Open");
- JMenuItem exitAction = new JMenuItem("Exit");
- JMenuItem cutAction = new JMenuItem("Cut");
- JMenuItem copyAction = new JMenuItem("Copy");
- JMenuItem pasteAction = new JMenuItem("Paste");
-
- fileMenu.add(newAction);
- newAction.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("You have clicked on the new action");
- }
- });
- fileMenu.add(openAction);
- openAction.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("You have clicked on the open action");
- }
- });
- fileMenu.addSeparator();
- fileMenu.add(exitAction);
- exitAction.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.exit(0);
- }
- });
- editMenu.add(cutAction);
- cutAction.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("You have clicked on the cut action");
- }
- });
- editMenu.add(copyAction);
- copyAction.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("You have clicked on the copy action");
- }
- });
- editMenu.add(pasteAction);
- pasteAction.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("You have clicked on the paste action");
- }
- });
- }
-
- }
|