Question

Simple Java Notepad application using Swing GUI

Create a help menu with shortcut ctrl+H:
-Help menu includes two menu items: 1. About 2. Visit Homepage. Add a separator between these menu items.

1. Create a menu item which is About. Add a short cut for the menu item. It is ctrl+A.

-When a user clicks it (an action event occurs), display a show message dialog box. Display the message shown in the figure. Display information icon.

2. 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 http://www.microsoft.com.

  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.

-Set frame as 600*400.

MyNotepad File Edit Print Help About Ctri-A Visit Homepage Ctrl-V

国MyNotepad File Edit Print Help About iThis software is developed in 2019 Version is 1.0 OK

MyNotepad File Edit Print Help About Ctri-A Visit Homepage Ctrl-V
国MyNotepad File Edit Print Help About iThis software is developed in 2019 Version is 1.0 OK
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.Desktop;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import java.awt.Toolkit;
import java.net.URI;
import java.net.URL;
import javax.swing.JOptionPane;
public class MyNotepad extends JFrame implements ActionListener
{
JMenuBar menubar;
JMenu file,edit,print,help;
JMenuItem about,visit;
public MyNotepad()
{
setTitle("MyNotepad");
setSize(600,400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//create menubar
menubar=new JMenuBar();
file=new JMenu("File");
menubar.add(file); //add menus to menubar
edit=new JMenu("Edit");
menubar.add(edit);
print=new JMenu("Print");
menubar.add(print);
help=new JMenu("Help");
//set the Mnemonic
help.setMnemonic('H');
about=new JMenuItem("About");
//set shortcut CTRL+H help
KeyStroke ctrl_A = KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask());
//set the accelerator
about.setAccelerator(ctrl_A);
about.addActionListener(this);
help.add(about);
help.addSeparator();
visit=new JMenuItem("Visit Homepage");
//set shortcut CTRL+V about
KeyStroke ctrl_V = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask());
//set the accelerator
visit.setAccelerator(ctrl_V);
visit.addActionListener(this);
help.add(visit);
menubar.add(help);
setJMenuBar(menubar);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==about)
JOptionPane.showMessageDialog(this,"This software is developed in 2019\nVersion is 1.0","About",JOptionPane.INFORMATION_MESSAGE);   
else if(e.getSource()==visit)
{
try {
Desktop.getDesktop().browse(new URL("http://www.microsoft.com").toURI()); }
catch (Exception e1) { e1.printStackTrace();
}
}   
}
public static void main(String[] args)
{
new MyNotepad();
}
}
OUTPUT

p 3 )11:57 AM & koushikhp 800 MyNotepad File Edit Print Help About เข้ This software is developed in 20 Version is 1.0 ок

Add a comment
Know the answer?
Add Answer to:
Simple Java Notepad application using Swing GUI Create a help menu with shortcut ctrl+H: -Help me...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Subject: Advance application development Visual studio exercise The project is to create a simple Notepad style Tex...

    Subject: Advance application development Visual studio exercise The project is to create a simple Notepad style Text Editor. This will demonstrate the C# language basics. user interface controls and how to handle user events. Controls can be found in the Toolbox pane in its default location on the left side of the IDE, with the Control Properties pane on the right side of the IDE. Include the items on the following list in the program Create a C# Windows Forms...

  • • Add a menu bar to the program with a File menu. • In the File...

    • Add a menu bar to the program with a File menu. • In the File menu, add a submenu (JMenuItem) called About. • When the user clicks on the About menu item, display a JOptionPane message dialog that contains your name, your course, the section number, and ID. Add comments to the top of each source code file that includes your name, course number, section number, and ID. 2. In Chapter 5, you created a lottery game application. Create...

  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

  • Question 1 (Marks: 50 Develop a Java GUI application that will produce an investment report based...

    Question 1 (Marks: 50 Develop a Java GUI application that will produce an investment report based on various criteria, such as investment amount, investment type and term. On the form create two text fields, one to capture the customer name and (10) Q.1.1 another to capture the amount to invest. Also create a combo box for the user to select the investment type which will be moderate or aggressive. Finally add three radio buttons for the user to select the...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • Really need help with this. This is for my Advanced Java Programming Class. If anyone is...

    Really need help with this. This is for my Advanced Java Programming Class. If anyone is an expert in Java I would very much appreciate the help. I will provide the code I was told to open. Exercise 13-3   Use JPA to work with the library checkout system In this exercise, you'll convert the application from the previous exercise to use JPA instead of JDBC to access the database. Review the project Start NetBeans and open the project named ch13_ex3_library that's...

  • need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user...

    need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user objects. The Facebook class should have methods to list all of the users (i.e. print out their usernames), add a user,delete a user, and get the password hint for a user You will also need to create a driver program. The driver should create an instance of the Facebook class and display a menu containing five options: list users...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT