QuestionQuestion

Transcribed TextTranscribed Text

3 QUESTIONS 1.Write a simple Notepad application. (20 pts). a.The title of the frame is “MyNotepad”. b.Create and add border layout. c.Create a text area to display contents. Add the text area to the centerof the border layout. d.Create a menu bar. e.Create a file menu. Set mnemonic for file menu. It is “F”. File menuincludes three menu items. f.Add a separator between each menu item in the file menu. 4 i. Open 1. Add a short cut for the menu item. It is ctrl+O. a. Use this syntax: MenuItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); 2. When a user clicks it (an action event occurs) a file chooser is created, and an open dialog box is opened. The user selects a text file to open it and then clicks “Open” or the user can click on “Cancel”. Use try block with resources. (Hint: add catch block automatically, click add catch clause). 5 ii. Save 1. Add a short cut for the menu item. It is ctrl+S. 2. When a user clicks it (an action event occurs) a file chooser is created, and a save dialog box is opened. The user writes the name of text file to save it and then clicks “Save” or the user can click on “Cancel”. User try block with resources. (Hint: add catch block automatically, click add catch clause). iii. Exit 1. Add a short cut for the menu item. It is ctrl+X. 2. When a user clicks it (an action event occurs), it terminates the application. g. Create edit menu. Set mnemonic for file menu. It is “D”. Edit menu includes two menus: Color and Font. h. Add a separator between each sub menu. 6 i. Create color menu. Set mnemonic for file menu. It is “C”. i. Create change color menu item. Add a short cut for the menu item. It is ctrl+C. ii. When a user clicks change color, a color chooser is opened, and the user selects a color. By default, red color is selected. Then, the color of the text is changed. 7 j. Create font menu. Set mnemonic for file menu. It is “F”. i. This menu includes three radio button menu items: Times New Roman, Arial, Serif. (Hint: you also need a button group). When a user selects one of these fonts (an action event occurs), the font of the text will change. Set font size as 20. ii. This menu includes also two check box menu items: Bold, Italic. A User can select both, only bold one, italic one, or unselect any of them (an item event occurs). Based on the user selection, set the font. (Hint: if one of them is unselected, set the font as plain). Set font size as 20. iii. Add a separator between radio button menu items and check box menu items. 8 k. Create Print menu. Set mnemonic for print menu. It is “P”. i. Printer menu includes one menu item: Send to Printer. Add a short cut for the menu item. It is ctrl+P. ii. When a user clicks it (an action event occurs), display an Option Dialog. Display the message in the figure. If the user clicks “Ok”, display a message dialog box (set information icon). Display the message in the figure. If the user clicks cancel, make the current frame as visible. 9 l. Create a help menu. Set mnemonic for help menu. It is “H”. m. Help menu includes two menu items: About, Visit Homepage. Add a separator between these menu items. i. Create a menu item which is about. Add a short cut for the menu item. It is ctrl+A. 10 1.When a user clicks it (an action event occurs), displaya show message dialog box. Display the messageshown in the figure. Display information icon. ii.Create a menu item which is visit homepage. Add a short cut for the menu item. It is ctrl+V.1.When a user clicks it (an action event occurs), the user will be navigated to microsoft. website 2.For the navigation, create a static method (copy it): public static void openWebpage (String urlString) { try { Desktop.getDesktop().browse(new URL(urlString).toURI()); } catch (Exception e) { e.printStackTrace(); } } Then in the action performed method, call this static method and provide the url String. n.When it is necessary, import the necessary classes and interfaces. o.Set frame as 600*400.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.awt.*;
import java.awt.event.*;
import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
import java.awt.event.KeyEvent;
import java.io.*;
import java.net.URL;
import java.nio.file.*;
import java.util.logging.*;
import javax.swing.*;


/**
*
* @author
*/
public class Notepad extends JFrame {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
       Notepad n = new Notepad();

    }

    //-----------------------------------------------------
   
    // class attributes
    private JTextArea displayContent;

    // file menu
    private String[] fileItemNames = {
       "Open", "Save", "Exit"
    };
    private int[] fileKeyEvents = {
       KeyEvent.VK_O, KeyEvent.VK_S, KeyEvent.VK_X
    };

    // edit menu
    private String[] editItemNames = {
       "Color", "Font"
    };
    private int[] editKeyEvents = {
       KeyEvent.VK_C, KeyEvent.VK_F
    };

    private String[] editFontNames = {
       "Times New Roman", "Arial", "Serif"
    };
    private int[] editFontNameKeyEvents = {
       KeyEvent.VK_T, KeyEvent.VK_A, KeyEvent.VK_S
    };

    private MyJRadioButtonMenuItem[] fontJRadioButtonMenuItems;
    private ButtonGroup fontButtonGroup;

    private String[] editFontTypes = {
       "Bold", "Italic"
    };
    private int[] editFontTypeKeyEvents = {
       KeyEvent.VK_B, KeyEvent.VK_I
    };
    private MyJCheckBoxMenuItem[] fontCheckBoxMenuItems;

    // help menu
    private String[] helpItemNames = {
       "About", "Visit Homepage"
    };
    private int[] helpKeyEvents = {
       KeyEvent.VK_A, KeyEvent.VK_V
    };

    //
    private int fontStyle = Font.PLAIN;
    private int fontSize = 12;
    private String fontName...
$60.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats