Question

In: Computer Science

3. For this week’s assignment, you are asked to modify the above Java program to include...

3. For this week’s assignment, you are asked to modify the above Java program to include the following: - When the user clicks on the help menu, a drop-down list will appear with an item called About, then when the user clicks on it, the window will show some instructions about the functionality of the menu, e.g, what the edit menu does, etc. - When the user clicks on the File menu, a drop-down list will appear with one item called Show Picture, and when the user clicks on it, a picture of your choice will appear

import javax.swing.*;


public class MenuFrame extends JFrame {


public MenuFrame() {


setTitle("Menu Frame");

setSize(500, 500);

MenuListenerExample myMenu = new MenuListenerExample();


setJMenuBar(myMenu);

setLayout(null);

add(myMenu.textArea);


}


public static void main(String[] args) {

MenuFrame frame = new MenuFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}


}


import javax.swing.*;

import java.awt.event.*;



public class MenuListenerExample extends JMenuBar {


JMenu fileMenu, editMenu, helpMenu;

JMenuItem cut, copy, paste, selectAll,about,showPicture;

JTextArea textArea,textArea1;


public MenuListenerExample() {


cut = new JMenuItem("cut");

copy = new JMenuItem("copy");

paste = new JMenuItem("paste");

selectAll = new JMenuItem("selectAll");

about=new JMenuItem("about");

showPicture=new JMenuItem("show");

textArea = new JTextArea();

textArea1 = new JTextArea();


cut.addActionListener(new MenuAction());

copy.addActionListener(new MenuAction());

paste.addActionListener(new MenuAction());

selectAll.addActionListener(new MenuAction());

about.addActionListener(new MenuAction());

showPicture.addActionListener(new MenuAction());


fileMenu = new JMenu("File");

editMenu = new JMenu("Edit");

helpMenu = new JMenu("Help");


editMenu.add(cut);

editMenu.add(copy);

editMenu.add(paste);

editMenu.add(selectAll);

helpMenu.add(about);

fileMenu.add(showPicture);

add(fileMenu);

add(editMenu);

add(helpMenu);


textArea.setBounds(30, 30, 430, 400);

textArea1.setBounds(30, 30, 430, 400);


}


private class MenuAction implements ActionListener {


public void actionPerformed(ActionEvent e) {

if (e.getSource() == cut) {

textArea.cut();

}

if (e.getSource() == paste) {

textArea.paste();

}

if (e.getSource() == copy) {

textArea.copy();

}

if (e.getSource() == selectAll) {

textArea.selectAll();

}

if (e.getSource() == about) {

JFrame frame = new JFrame("about");

textArea1.setText("This is simple Notepad Application\n"+"1.File : It has show picture option\n"

+"Edit : It has three option cut,copy,selectall\n"+

"help : It has about option which show function\n");

textArea1.setEditable(false);

frame.add(textArea1);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}


Replace if statements and use the switch statement


i need output show pictures in file menu

Image path is

C:\\Users\\DGL2\\Desktop\\3840.jpg_wh860.jpg

Solutions

Expert Solution

package menu;

import javax.swing.*;

public class MenuFrame extends JFrame
{
   private static final long serialVersionUID = 1L;

   public MenuFrame()
   {
       setTitle("Menu Frame");
       setSize(500, 500);
       MenuListenerExample myMenu = new MenuListenerExample();
       setJMenuBar(myMenu);
       setLayout(null);
       add(myMenu.textArea);
   }

   public static void main(String[] args)
   {
       MenuFrame frame = new MenuFrame();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
       frame.setLocationRelativeTo(null);
   }
}

-------------------------------------------------------------------------------------------------------------

package menu;

import javax.swing.*;

import java.awt.event.*;

public class MenuListenerExample extends JMenuBar
{
   private static final long serialVersionUID = 1L;
   JMenu fileMenu, editMenu, helpMenu;
   JMenuItem cut, copy, paste, selectAll,about,showPicture;
   JTextArea textArea,textArea1;
   JFrame frame;
  
   public MenuListenerExample()
   {
       cut = new JMenuItem("cut");
       copy = new JMenuItem("copy");
       paste = new JMenuItem("paste");
       selectAll = new JMenuItem("selectAll");
       about=new JMenuItem("about");
       showPicture=new JMenuItem("Show Picture");
       textArea = new JTextArea();
       textArea1 = new JTextArea();

       cut.addActionListener(new MenuAction());
       copy.addActionListener(new MenuAction());
       paste.addActionListener(new MenuAction());
       selectAll.addActionListener(new MenuAction());
       about.addActionListener(new MenuAction());
       showPicture.addActionListener(new MenuAction());

       fileMenu = new JMenu("File");
       editMenu = new JMenu("Edit");
       helpMenu = new JMenu("Help");

       editMenu.add(cut);
       editMenu.add(copy);
       editMenu.add(paste);
       editMenu.add(selectAll);
       helpMenu.add(about);
       fileMenu.add(showPicture);
       add(fileMenu);
       add(editMenu);
       add(helpMenu);
      
       textArea.setBounds(30, 30, 430, 400);
       textArea1.setBounds(30, 30, 430, 400);
   }
   private class MenuAction implements ActionListener
   {
       public void actionPerformed(ActionEvent e)
       {
           if (e.getSource() == cut)
           {
               textArea.cut();
           }
           if (e.getSource() == paste)
           {
               textArea.paste();
           }
           if (e.getSource() == copy)
           {
               textArea.copy();
           }
           if (e.getSource() == selectAll)
           {
               textArea.selectAll();
           }
           if (e.getSource() == about)
           {
               frame = new JFrame("About");
               textArea1.setText("This is simple Notepad Application\n"+
               " 1.File : It has show picture option\n"
                       +" 2. Edit : It has three option cut,copy,selectall\n"+
                       " 3. help : It has about option which show function\n");
               textArea1.setEditable(false);
               frame.add(textArea1);
               frame.pack();
               frame.setVisible(true);
               frame.setLocationRelativeTo(null);
              
           }
           if (e.getSource() == showPicture)
           {
               frame = new JFrame("My Image");
               JLabel img = new JLabel();
               img.setIcon(new ImageIcon("F:/OnlinePrograms/tiger.jpg"));
               frame.add(img);
               frame.pack();
               frame.setVisible(true);
               frame.setLocationRelativeTo(null);
           }

       }
   }
}

Note: Highlighted part is the modified code

Sample Output:


Related Solutions

For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following: An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method. Two concrete classes...
In this programming assignment, you are asked to write a multi-threaded program using JAVA to compute...
In this programming assignment, you are asked to write a multi-threaded program using JAVA to compute the sum of an arithmetic series from 1 to 200 using pthreads.   The main thread is responsible for creating two child threads The first child thread should compute the partial sum of the series from 1 to 100 and the second computes the partial sum of another series from 101 to 200. The main thread should accumulate the partial sums computed by the child...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
In java Modify your finished guessNumber.java program to include a random number generator to generate the...
In java Modify your finished guessNumber.java program to include a random number generator to generate the guessed number (from 1 to 10). use the Random class to generate a random number between a range of integers. In your program include an if … then statement to check if the number you entered is bigger or smaller than the guessed number, and display a message. Also included is a counter to keep track on how many times the user has guessed,...
For this week’s assignment, you will write a program class that has two subroutines and a...
For this week’s assignment, you will write a program class that has two subroutines and a main routine. The program should be a part of the ‘Firstsubroutines’ class and you should name your project Firstsubroutines if you are using Netbeans. Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards,...
please complete the following program in c++: In this homework assignment you will modify the program...
please complete the following program in c++: In this homework assignment you will modify the program you have developed in Homework Assignment 1 by implementing the following: 1- Your program will ask the user to choose to either Compute and Display Surface Areas of Hemispheres and their Average (Choice 1) or to Compute and Display Volumes of Hemispheres and their Average (Choice 2). The program will only perform the chosen operation. (Hint: use a character variable to read the character...
For this week’s lab assignment, you will write a program called lab9.c. You will write a...
For this week’s lab assignment, you will write a program called lab9.c. You will write a program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output. The two prototypes should be the following: int btod(int size, char inputBin[size]); int dtob(int inputDec); The algorithm for the main() function should be the following: 1. Declare needed variables 2. Prompt user to enter a binary number 3. Use...
Java Programming For this assignment, you should modify only the User.java file. Make sure that the...
Java Programming For this assignment, you should modify only the User.java file. Make sure that the InsufficientFundsException.java file is in the same folder as your User.java File. To test this program you will need to create your own "main" function which can import the User, create an instance and call its methods. One of the methods will throw an exception in a particular circumstance. This is a good reference for how throwing exceptions works in java. I would encourage you...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
You are to modify your payroll program from the last assignment to take the new copy...
You are to modify your payroll program from the last assignment to take the new copy of the payroll file called DeweyCheatemAndHow.txt which has the fields separated by a comma to use as input to your program and produce a file that lists all the salaried employee and their gross pay, then each hourly employee and their gross pay and finally each piece rate employee and their gross pay . You are to process all the entries provided in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT