Question

In: Computer Science

I'm have trouble change JRadioButton and do not want to select all at the same time...

I'm have trouble change JRadioButton and do not want to select all at the same time just one at a time. if one of them is unselected, then set the font as plain. Set font size as 20.

run the program and change the font and you see what I'm talking about

also this there anyway to shorten my code

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.event.*;
import java.net.URL;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
//MyMenuFrame will use Jframe with actionlistener
public class MyMenuFrame extends JFrame implements ActionListener{

//creating the main menu items
JMenu menuEdit = new JMenu("Edit");
JMenu menuPrint = new JMenu("Print");
JMenu mnFile = new JMenu("File");
JMenu menuHelp = new JMenu("Help");


//creating the submenu items here because we are gonna use these across the code
JRadioButton subMenuItem1 = new JRadioButton("Times New Roman");
JRadioButton subMenuItem2 = new JRadioButton("Arial");
JRadioButton subMenuItem3 = new JRadioButton("Serif");
JCheckBox subMenuItem4 = new JCheckBox("Bold");
JCheckBox subMenuItem5 = new JCheckBox("Italic");

//provide scrollable view of a component
JScrollPane scrollPane;

//creating notePadArea for notepad to input the text
JTextArea notePadArea;

public MyMenuFrame() {

//setting the border layout for JFrame
this.setLayout(new BorderLayout());

// create menu bar named menuBar

JMenuBar menuBar = new JMenuBar();

this.setJMenuBar(menuBar);//adding the menubar to JFrame

// create File menu
mnFile.setMnemonic(KeyEvent.VK_F);//Alt+F

menuBar.add(mnFile);//adding the menufile

// create Open menu item

JMenuItem mntmOpen = new JMenuItem("Open");//creating the Open menu

mntmOpen.setMnemonic(KeyEvent.VK_O);//Alt+O command

mntmOpen.setActionCommand("open");//when the command equals to 'open' then the corresponding action will be performed

mntmOpen.setAccelerator(KeyStroke.getKeyStroke('O', KeyEvent.CTRL_DOWN_MASK));//respond when user clicks Ctrl+O

mntmOpen.addActionListener(this);//adding actionLister to the Menu Option Open


// create Save menu item

JMenuItem mntmSave = new JMenuItem("Save");//creating the Save menu

mntmSave.setMnemonic(KeyEvent.VK_S);//Alt+S command

mntmSave.setActionCommand("save");//when the command equals to 'save' then the corresponding action will be performed

mntmSave.setAccelerator(KeyStroke.getKeyStroke('S', KeyEvent.CTRL_DOWN_MASK));//respond when user clicks Ctrl+S

mntmSave.addActionListener(this);//adding actionLister to the Menu Option Save

// create Exit menu item

JMenuItem mntmExit = new JMenuItem("Exit");//creating the Exit menu

mntmExit.setMnemonic(KeyEvent.VK_X);//Alt+X command

mntmExit.setActionCommand("exit");//when the command equals to 'exit' then the corresponding action will be performed

mntmExit.setAccelerator(KeyStroke.getKeyStroke('X', KeyEvent.CTRL_DOWN_MASK));//respond when user clicks Ctrl+X

mntmExit.addActionListener(this);//adding actionLister to the Menu Option Exit

// add open, save and exit menu to menu-bar

mnFile.add(mntmOpen);

mnFile.addSeparator();//adding separator between open and save

mnFile.add(mntmSave);

mnFile.addSeparator();//adding separator between save and exit

mnFile.add(mntmExit);

// create Edit menu

menuEdit.setMnemonic(KeyEvent.VK_E);//creating shortcut menu when user press Alt+E

menuBar.add(menuEdit);//adding the Edit to the menubar

JMenu submenu1 = new JMenu("Color");//creating the new menu which comes under Edit
submenu1.setMnemonic(KeyEvent.VK_C);//creating shortcut menu when user press Alt+C
JMenuItem menuItem0 = new JMenuItem("Change Color");//creating submenu item called change color
menuItem0.setAccelerator(KeyStroke.getKeyStroke('C', KeyEvent.CTRL_DOWN_MASK));//it responds when user click Ctrl+C
menuItem0.setActionCommand("color");//setting the command used to call the correcponding action when user click this
menuItem0.addActionListener(this);//adding actionlistener
submenu1.add(menuItem0);//adding this menu item to submenu
menuEdit.add(submenu1);//adding this submenu to editmenu
menuEdit.addSeparator();//creating separator between Color and Font

JMenu submenu = new JMenu("Font");//creating the new menu which comes under Edit
submenu.setMnemonic(KeyEvent.VK_F);//creating shortcut menu when user press Alt+F
subMenuItem1.setMnemonic(KeyEvent.VK_T);//creating shortcut menu when user press Alt+T for Times New Roman
subMenuItem1.setActionCommand("times_new_roman");//setting the command used to call the correcponding action when user click this
subMenuItem1.addActionListener(this);//adding actionlistener
submenu.add(subMenuItem1);//adding to the submenu


subMenuItem2.setMnemonic(KeyEvent.VK_A);//creating shortcut key Alt+A
subMenuItem2.setActionCommand("arial");//respond when the command equals to arial
subMenuItem2.addActionListener(this);//adding action listener
submenu.add(subMenuItem2);//adding it to the submenu

subMenuItem3.setMnemonic(KeyEvent.VK_S);
subMenuItem3.setActionCommand("serif");
subMenuItem3.addActionListener(this);
submenu.add(subMenuItem3);

submenu.addSeparator();

subMenuItem4.setMnemonic(KeyEvent.VK_B);
subMenuItem4.setActionCommand("bold");
subMenuItem4.addActionListener(this);
submenu.add(subMenuItem4);

subMenuItem5.setMnemonic(KeyEvent.VK_I);
subMenuItem5.setActionCommand("italic");
subMenuItem5.addActionListener(this);
submenu.add(subMenuItem5);

menuEdit.add(submenu);


// create Print menu


menuPrint.setMnemonic(KeyEvent.VK_P);

menuBar.add(menuPrint);

JMenuItem menuItemPrint = new JMenuItem("Send To Printer");

menuItemPrint.setAccelerator(KeyStroke.getKeyStroke('P', KeyEvent.CTRL_DOWN_MASK));

menuItemPrint.setActionCommand("print");

menuItemPrint.addActionListener(this);

menuPrint.add(menuItemPrint);

// create Help menu

menuHelp.setMnemonic(KeyEvent.VK_H);


menuBar.add(menuHelp);

JMenuItem menuItemHelp = new JMenuItem("About");

menuItemHelp.setAccelerator(KeyStroke.getKeyStroke('A', KeyEvent.CTRL_DOWN_MASK));

menuItemHelp.setActionCommand("about");
menuItemHelp.addActionListener(this);

JMenuItem menuItemVisitHomePage = new JMenuItem("Visit Home Page");

menuItemVisitHomePage.setAccelerator(KeyStroke.getKeyStroke('V', KeyEvent.CTRL_DOWN_MASK));

menuItemVisitHomePage.setActionCommand("visithomepage");
menuItemVisitHomePage.addActionListener(this);

menuHelp.add(menuItemHelp);

menuHelp.addSeparator();

menuHelp.add(menuItemVisitHomePage);

notePadArea = new JTextArea();

// set no word wrap

notePadArea.setWrapStyleWord(false);

// create scrollable pane

scrollPane = new JScrollPane(notePadArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS , JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

this.add(scrollPane,BorderLayout.CENTER);

}


@Override

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand().equals("exit")) {

System.exit(0);

}else if (e.getActionCommand().equals("open")) {

JFileChooser file = new JFileChooser();

String fileName = "";//initial filename was empty

// show open file dialog

if (file.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {

fileName = file.getSelectedFile().getAbsolutePath();

} else {

return;

}

try(BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));) {

// load file content into text area

StringBuffer stringBuffer = new StringBuffer();//creating a string buffer for reading data from file

String lines = "";//for reading the lines from the selecting file

while((lines = bufferedReader.readLine() ) != null) {//it'll read untill the file ends

stringBuffer.append(lines).append("\n");//for every line read insert new line in stringBuffer

}

bufferedReader.close();//after reading of file done, the bufferedReader will be close

notePadArea.setText(stringBuffer.toString());//converting the read text to string and inserting this text into textArea

} catch (Exception error1) {//if any exception occures

System.out.println(error1.toString());//convert the expection into string and print it

}

} else if (e.getActionCommand().equals("save")) {//if the user click the save command then the file will gonna saved


JFileChooser file = new JFileChooser();//creating the file chooser

String fileName = "";//initial file name is empty

// show open file dialog

if (file.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {//if the user select file and clicks OK button

fileName = file.getSelectedFile().getAbsolutePath();

} else {//other wise will be closed
return;
}

try(BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileName));) {

// write editor's content to selected file.

bufferedWriter.write(notePadArea.getText());//get the text entered in textarea
bufferedWriter.flush();//clear the writer
} catch(Exception ex1) {}

} else if (e.getActionCommand().equals("color")) {

Color select_color = JColorChooser.showDialog(this, "Select a color", Color.RED);
notePadArea.setForeground(select_color);

} else if (e.getActionCommand().equals("times_new_roman")) {
if(subMenuItem1.isSelected())
notePadArea.setFont(new Font("Times New Roman", Font.PLAIN, 20));

} else if (e.getActionCommand().equals("arial")) {
if(subMenuItem2.isSelected())
notePadArea.setFont(new Font("Arial", Font.PLAIN, 20));

} else if (e.getActionCommand().equals("serif")) {
if(subMenuItem3.isSelected())
notePadArea.setFont(new Font("Serif", Font.PLAIN, 20));

} else if (e.getActionCommand().equals("bold")) {
if(subMenuItem4.isSelected()){
if(subMenuItem5.isSelected()){
notePadArea.setFont(new Font("Serif", Font.BOLD+Font.ITALIC, 12));
}else{
notePadArea.setFont(new Font("Serif", Font.BOLD, 12));
}
}else{
if(!subMenuItem5.isSelected())
notePadArea.setFont(new Font("Serif", Font.PLAIN, 12));
}

} else if (e.getActionCommand().equals("italic")) {

if(subMenuItem5.isSelected()){
if(subMenuItem4.isSelected()){
notePadArea.setFont(new Font("Serif", Font.BOLD+Font.ITALIC, 12));
}else{
notePadArea.setFont(new Font("Serif", Font.ITALIC, 12));
}
}else{
if(!subMenuItem4.isSelected())
notePadArea.setFont(new Font("Serif", Font.PLAIN, 12));
}

} else if (e.getActionCommand().equals("print")) {

int output = JOptionPane.showConfirmDialog(this, "Do you want to print the File","Confirmation", JOptionPane.YES_NO_OPTION);
if(output==0){
JOptionPane.showMessageDialog(this, "The file is successfully printed","Confirmation", JOptionPane.INFORMATION_MESSAGE);
}
} else if (e.getActionCommand().equals("changecolor")){
System.out.println("Color clicked");
}
else if (e.getActionCommand().equals("about")) {

JOptionPane.showMessageDialog(this, "This software is developed in 2019\nVersion is 1.0","About", JOptionPane.INFORMATION_MESSAGE);

} else if (e.getActionCommand().equals("visithomepage")) {

openWebpage("http://www.microsoft.com");

}

}

private void openWebpage (String urlString) {

try {

Desktop.getDesktop().browse(new URL(urlString).toURI());

}

catch (Exception e) {

e.printStackTrace();
}
}
}

import javax.swing.JFrame;
public class MyMenuFrameTest {
public static void main(String[] args) {
MyMenuFrame frame = new MyMenuFrame();
frame.setTitle("MyNotepad");
//for the title of the box
frame.setSize(600, 400);
//for the size of the box
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);
}
}

Solutions

Expert Solution

I AM NOT ABLE TO SHOW OUTPUT, AS JAVA IS NOT ALLOWING ME TO CAPTURE THE SCREEN

PLEASE RUN THIS, THE RADIOBUTTON AND CHECKBOX SELECTION BUG IS NOW FIXED

import java.awt.*;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.event.*;
import java.net.URL;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
//MyMenuFrame will use Jframe with actionlistener
class MyMenuFrame extends JFrame implements ActionListener{

//creating the main menu items
JMenu menuEdit = new JMenu("Edit");
JMenu menuPrint = new JMenu("Print");
JMenu mnFile = new JMenu("File");
JMenu menuHelp = new JMenu("Help");


//creating the submenu items here because we are gonna use these across the code
JRadioButton subMenuItem1 = new JRadioButton("Times New Roman");
JRadioButton subMenuItem2 = new JRadioButton("Arial");
JRadioButton subMenuItem3 = new JRadioButton("Serif");
JCheckBox subMenuItem4 = new JCheckBox("Bold");
JCheckBox subMenuItem5 = new JCheckBox("Italic");

//provide scrollable view of a component
JScrollPane scrollPane;

//creating notePadArea for notepad to input the text
JTextArea notePadArea;

public MyMenuFrame() {

//setting the border layout for JFrame
this.setLayout(new BorderLayout());

// create menu bar named menuBar

JMenuBar menuBar = new JMenuBar();

this.setJMenuBar(menuBar);//adding the menubar to JFrame

// create File menu
mnFile.setMnemonic(KeyEvent.VK_F);//Alt+F

menuBar.add(mnFile);//adding the menufile

// create Open menu item

JMenuItem mntmOpen = new JMenuItem("Open");//creating the Open menu

mntmOpen.setMnemonic(KeyEvent.VK_O);//Alt+O command

mntmOpen.setActionCommand("open");//when the command equals to 'open' then the corresponding action will be performed

mntmOpen.setAccelerator(KeyStroke.getKeyStroke('O', KeyEvent.CTRL_DOWN_MASK));//respond when user clicks Ctrl+O

mntmOpen.addActionListener(this);//adding actionLister to the Menu Option Open


// create Save menu item

JMenuItem mntmSave = new JMenuItem("Save");//creating the Save menu

mntmSave.setMnemonic(KeyEvent.VK_S);//Alt+S command

mntmSave.setActionCommand("save");//when the command equals to 'save' then the corresponding action will be performed

mntmSave.setAccelerator(KeyStroke.getKeyStroke('S', KeyEvent.CTRL_DOWN_MASK));//respond when user clicks Ctrl+S

mntmSave.addActionListener(this);//adding actionLister to the Menu Option Save

// create Exit menu item

JMenuItem mntmExit = new JMenuItem("Exit");//creating the Exit menu

mntmExit.setMnemonic(KeyEvent.VK_X);//Alt+X command

mntmExit.setActionCommand("exit");//when the command equals to 'exit' then the corresponding action will be performed

mntmExit.setAccelerator(KeyStroke.getKeyStroke('X', KeyEvent.CTRL_DOWN_MASK));//respond when user clicks Ctrl+X

mntmExit.addActionListener(this);//adding actionLister to the Menu Option Exit

// add open, save and exit menu to menu-bar

mnFile.add(mntmOpen);

mnFile.addSeparator();//adding separator between open and save

mnFile.add(mntmSave);

mnFile.addSeparator();//adding separator between save and exit

mnFile.add(mntmExit);

// create Edit menu

menuEdit.setMnemonic(KeyEvent.VK_E);//creating shortcut menu when user press Alt+E

menuBar.add(menuEdit);//adding the Edit to the menubar

JMenu submenu1 = new JMenu("Color");//creating the new menu which comes under Edit
submenu1.setMnemonic(KeyEvent.VK_C);//creating shortcut menu when user press Alt+C
JMenuItem menuItem0 = new JMenuItem("Change Color");//creating submenu item called change color
menuItem0.setAccelerator(KeyStroke.getKeyStroke('C', KeyEvent.CTRL_DOWN_MASK));//it responds when user click Ctrl+C
menuItem0.setActionCommand("color");//setting the command used to call the correcponding action when user click this
menuItem0.addActionListener(this);//adding actionlistener
submenu1.add(menuItem0);//adding this menu item to submenu
menuEdit.add(submenu1);//adding this submenu to editmenu
menuEdit.addSeparator();//creating separator between Color and Font

ActionListener sm1 = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
subMenuItem1.setSelected(true);
subMenuItem2.setSelected(false);
subMenuItem3.setSelected(false);
notePadArea.setFont(new Font("Times New Roman", Font.PLAIN, 20));
}
};

ActionListener sm2 = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
subMenuItem2.setSelected(true);
subMenuItem1.setSelected(false);
subMenuItem3.setSelected(false);
notePadArea.setFont(new Font("Arial", Font.PLAIN, 20));

}
};

ActionListener sm3 = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
subMenuItem3.setSelected(true);
subMenuItem2.setSelected(false);
subMenuItem1.setSelected(false);
notePadArea.setFont(new Font("Serif", Font.PLAIN, 20));

}
};

JMenu submenu = new JMenu("Font");//creating the new menu which comes under Edit
submenu.setMnemonic(KeyEvent.VK_F);//creating shortcut menu when user press Alt+F
subMenuItem1.setMnemonic(KeyEvent.VK_T);//creating shortcut menu when user press Alt+T for Times New Roman
subMenuItem1.setActionCommand("times_new_roman");//setting the command used to call the correcponding action when user click this
subMenuItem1.addActionListener(sm1);//adding actionlistener
submenu.add(subMenuItem1);//adding to the submenu


subMenuItem2.setMnemonic(KeyEvent.VK_A);//creating shortcut key Alt+A
subMenuItem2.setActionCommand("arial");//respond when the command equals to arial
subMenuItem2.addActionListener(sm2);
submenu.add(subMenuItem2);//adding it to the submenu

subMenuItem3.setMnemonic(KeyEvent.VK_S);
subMenuItem3.setActionCommand("serif");
subMenuItem3.addActionListener(sm3);
submenu.add(subMenuItem3);

submenu.addSeparator();

subMenuItem4.setMnemonic(KeyEvent.VK_B);
subMenuItem4.setActionCommand("bold");
subMenuItem4.addActionListener(this);
submenu.add(subMenuItem4);

subMenuItem5.setMnemonic(KeyEvent.VK_I);
subMenuItem5.setActionCommand("italic");
subMenuItem5.addActionListener(this);
submenu.add(subMenuItem5);

menuEdit.add(submenu);


// create Print menu


menuPrint.setMnemonic(KeyEvent.VK_P);

menuBar.add(menuPrint);

JMenuItem menuItemPrint = new JMenuItem("Send To Printer");

menuItemPrint.setAccelerator(KeyStroke.getKeyStroke('P', KeyEvent.CTRL_DOWN_MASK));

menuItemPrint.setActionCommand("print");

menuItemPrint.addActionListener(this);

menuPrint.add(menuItemPrint);

// create Help menu

menuHelp.setMnemonic(KeyEvent.VK_H);


menuBar.add(menuHelp);

JMenuItem menuItemHelp = new JMenuItem("About");

menuItemHelp.setAccelerator(KeyStroke.getKeyStroke('A', KeyEvent.CTRL_DOWN_MASK));

menuItemHelp.setActionCommand("about");
menuItemHelp.addActionListener(this);

JMenuItem menuItemVisitHomePage = new JMenuItem("Visit Home Page");

menuItemVisitHomePage.setAccelerator(KeyStroke.getKeyStroke('V', KeyEvent.CTRL_DOWN_MASK));

menuItemVisitHomePage.setActionCommand("visithomepage");
menuItemVisitHomePage.addActionListener(this);

menuHelp.add(menuItemHelp);

menuHelp.addSeparator();

menuHelp.add(menuItemVisitHomePage);

notePadArea = new JTextArea();

// set no word wrap

notePadArea.setWrapStyleWord(false);

// create scrollable pane

scrollPane = new JScrollPane(notePadArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS , JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

this.add(scrollPane,BorderLayout.CENTER);

}


@Override

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand().equals("exit")) {

System.exit(0);

}else if (e.getActionCommand().equals("open")) {

JFileChooser file = new JFileChooser();

String fileName = "";//initial filename was empty

// show open file dialog

if (file.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {

fileName = file.getSelectedFile().getAbsolutePath();

} else {

return;

}

try(BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));) {

// load file content into text area

StringBuffer stringBuffer = new StringBuffer();//creating a string buffer for reading data from file

String lines = "";//for reading the lines from the selecting file

while((lines = bufferedReader.readLine() ) != null) {//it'll read untill the file ends

stringBuffer.append(lines).append("\n");//for every line read insert new line in stringBuffer

}

bufferedReader.close();//after reading of file done, the bufferedReader will be close

notePadArea.setText(stringBuffer.toString());//converting the read text to string and inserting this text into textArea

} catch (Exception error1) {//if any exception occures

System.out.println(error1.toString());//convert the expection into string and print it

}

} else if (e.getActionCommand().equals("save")) {//if the user click the save command then the file will gonna saved


JFileChooser file = new JFileChooser();//creating the file chooser

String fileName = "";//initial file name is empty

// show open file dialog

if (file.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {//if the user select file and clicks OK button

fileName = file.getSelectedFile().getAbsolutePath();

} else {//other wise will be closed
return;
}

try(BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileName));) {

// write editor's content to selected file.

bufferedWriter.write(notePadArea.getText());//get the text entered in textarea
bufferedWriter.flush();//clear the writer
} catch(Exception ex1) {}

} else if (e.getActionCommand().equals("color")) {

Color select_color = JColorChooser.showDialog(this, "Select a color", Color.RED);
notePadArea.setForeground(select_color);

} else if (e.getActionCommand().equals("times_new_roman")) {
if(subMenuItem1.isSelected())
notePadArea.setFont(new Font("Times New Roman", Font.PLAIN, 20));

} else if (e.getActionCommand().equals("arial")) {
if(subMenuItem2.isSelected())
notePadArea.setFont(new Font("Arial", Font.PLAIN, 20));

} else if (e.getActionCommand().equals("serif")) {
if(subMenuItem3.isSelected())
notePadArea.setFont(new Font("Serif", Font.PLAIN, 20));

} else if (e.getActionCommand().equals("bold")) {
if(subMenuItem4.isSelected()){
if(subMenuItem5.isSelected()){
notePadArea.setFont(new Font("Serif", Font.BOLD+Font.ITALIC, 12));
}else{
notePadArea.setFont(new Font("Serif", Font.BOLD, 12));
}
}else{
if(!subMenuItem5.isSelected())
notePadArea.setFont(new Font("Serif", Font.PLAIN, 12));
}

} else if (e.getActionCommand().equals("italic")) {

if(subMenuItem5.isSelected()){
if(subMenuItem4.isSelected()){
notePadArea.setFont(new Font("Serif", Font.BOLD+Font.ITALIC, 12));
}else{
notePadArea.setFont(new Font("Serif", Font.ITALIC, 12));
}
}else{
if(!subMenuItem4.isSelected())
notePadArea.setFont(new Font("Serif", Font.PLAIN, 12));
}

} else if (e.getActionCommand().equals("print")) {

int output = JOptionPane.showConfirmDialog(this, "Do you want to print the File","Confirmation", JOptionPane.YES_NO_OPTION);
if(output==0){
JOptionPane.showMessageDialog(this, "The file is successfully printed","Confirmation", JOptionPane.INFORMATION_MESSAGE);
}
} else if (e.getActionCommand().equals("changecolor")){
System.out.println("Color clicked");
}
else if (e.getActionCommand().equals("about")) {

JOptionPane.showMessageDialog(this, "This software is developed in 2019\nVersion is 1.0","About", JOptionPane.INFORMATION_MESSAGE);

} else if (e.getActionCommand().equals("visithomepage")) {

openWebpage("http://www.microsoft.com");

}

}

private void openWebpage (String urlString) {

try {

Desktop.getDesktop().browse(new URL(urlString).toURI());

}

catch (Exception e) {

e.printStackTrace();
}
}
}


class MyMenuFrameTest {
public static void main(String[] args) {
MyMenuFrame frame = new MyMenuFrame();
frame.setTitle("MyNotepad");
//for the title of the box
frame.setSize(600, 400);
//for the size of the box
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);
}
}

THE CHANGE IS :


Related Solutions

I'm having trouble understanding a CS assignment. I would appreciate it if you all code do...
I'm having trouble understanding a CS assignment. I would appreciate it if you all code do this for me. The template for the lab is below which you must use. You're only supposed to create/edit the product function. The assignment has to be written in asm(Mips) You will need to create a NOS table and use the structure below and write a function called product. The structure used in this program is: struct Values { short left; short right; int...
Over and over I'm getting into the same trouble, so I'd like to ask for some...
Over and over I'm getting into the same trouble, so I'd like to ask for some help. I need to solve some basic electrodynamics problem, involving magnetic fields, moving charges or currents. But I forgot all this rules about "where the magnetic field should go if the current flows up". I vaguely remember that it about hands or fingers or books or guns, and magnetic field should go somewhere along something, while current should flow along something else... But it...
MICROBIOLOGY: I'm having trouble understanding the role of thermal death time and thermal death point in...
MICROBIOLOGY: I'm having trouble understanding the role of thermal death time and thermal death point in proper sterilization. Can someone please explain the role of both in proper sterilization?
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator is 0 it throws the ZeroDenominatorException and the catch catches to guarantee that the denominator is never 0. /** * The main class is the driver for my Rational project. */ public class Main { /** * Main method is the entry point to my code. * @param args The command line arguments. */ public static void main(String[] args) { int numerator, denominator =...
I'm having trouble understanding the following code (a snippet of a code). What does it do?...
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms. def partition(list,first,last): piv = list[first] lmark = first+1 rmark = last done = False while not done: while lmark <= rmark and list[lmark]<=piv: lmark=lmark+1 while list[rmark]>=piv and rmark>=lmark: rmark=rmark-1 if rmark<lmark: done = True else: temp = list[lmark] list[lmark]=list[rmark] list[rmark]=temp temp = list[first] list[first]=list[rmark] list[rmark]=temp return rmark
1. Discuss why all people do not have the same time preference for money 2. You...
1. Discuss why all people do not have the same time preference for money 2. You have finally graduated from college and are doing a little retirement planning. You plan to retire in 40 years. At that time you want to have a million dollars in savings. If you can receive 5% interest annually on a savings account, what is the fixed amount you have to save each month? How much would you have to save if the money was...
I have a group project (Cost Benefit Analysis / ROI) that I'm having trouble with two...
I have a group project (Cost Benefit Analysis / ROI) that I'm having trouble with two parts- Competitive Analysis & Conclusion The topic is - To develop training programs internally instead of sending employees to external training providers Company Type - Healthcare organization Competitive Analysis: Summarize the experience other companies are having with this type of investment *This is what I had in mind but need further help please: How are other potential health organizations dealing with having a new...
hello, I'm having trouble understanding how to do these two problems could you show me a...
hello, I'm having trouble understanding how to do these two problems could you show me a step by step. 1)Eight sprinters have made it to the Olympic finals in the 100-meter race. In how many different ways can the gold, silver, and bronze medals be awarded? 2)Suppose that 34% of people own dogs. If you pick two people at random, what is the probability that they both own a dog? Give your answer as a decimal (to at least 3...
1. Why do drugs not have the same effect on all patients?
1. Why do drugs not have the same effect on all patients?
Management's Time Horizon. Do shareholder wealth maximization and skateholder capitalism have the same time-horizon for the...
Management's Time Horizon. Do shareholder wealth maximization and skateholder capitalism have the same time-horizon for the strategic managerial, and financial objetives of the firm? How do they differ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT