Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class called MyJFrame to produce output similar to Figures I - IV Figur

ID: 3827844 • Letter: D

Question

Design a class called MyJFrame to produce output similar to Figures I - IV

Figure I – Create a frame that is inherited from the class JFrame. The frame must contain only a title. Size the frame according to your liking. St the background color and foreground color to your liking.

Figure II - Create a menu bar object and set it in place. Next, add menu choices onto the menu bar as shown.

Figure III – For the menu choice File, add menu items as shown in Figures III. Place separators where indicated in the Figure.

Figure IV – For the menu choice Tools, create a cascading menu for the menu choice Edit. This submenu must contain menu items as shown in the Figure.

Design a class called DisplayText that accepts two strings - the first string represents the name of a file, and the second string, the contents of the file, which must be displayed in an editable scrollable pane.

Note: when File- New is selected, the output should be similar to Figure V.

Figure V

Note: when File- ListFiles is selected, the output should be similar to Figure VI.

Figure VI

Use the class called BasicFile from assignment 3, to select and read file and load its contents as shown in Figure Figure VII.

Figure VII

Further requirements – in the class DisplayText

Write a method called selectText(). This method captures any text that is selected by the mouse.

Write a method called insertText(String, int) that inserts the text that was capture by selectText() and places the text wherever in the text you want it to be placed.

Implement the Copy – Paste option, that it can copy from one window and paste to another window.

Figure Figuerev

Explanation / Answer

// File1:

import javax.swing.*;

@SuppressWarnings("serial")
class SimpleFrame extends JFrame
{
SimpleFrame(String title)
{
super( title ); // invoke the JFrame constructor
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
}
}

public class MyJFrame
{
public static void main ( String[] args )
{
       SimpleFrame frm = new SimpleFrame("MyJFrame Demo");
   frm.setSize( 250, 250 );   
   frm.setVisible( true );   
}
}

// File2:

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

@SuppressWarnings("serial")
class SimpleFrame2 extends JFrame
{
   SimpleFrame2(String title)
{
super( title ); // invoke the JFrame constructor
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
}
}

public class MyJFrameMenu
{
public static void main ( String[] args )
{
       SimpleFrame frm = new SimpleFrame("MyJFrameMenu Demo");
   frm.setSize( 400, 400 );   
   frm.setVisible( true );

   JMenuBar menubar = new JMenuBar();

   JMenu menu = new JMenu("File");
   JMenuItem file1 = new JMenuItem("New");
   JMenuItem file2 = new JMenuItem("Open");
   JMenuItem file3 = new JMenuItem("Close");
  

  
   JMenu menu1 = new JMenu("Color");
   JMenuItem blue = new JMenuItem("blue");
   JMenuItem orange = new JMenuItem("orange");
   JMenuItem red = new JMenuItem("red");
  
   JMenu menu2 = new JMenu("Size");
   JMenuItem small = new JMenuItem("size");
   JMenuItem medium = new JMenuItem("medium");
   JMenuItem large = new JMenuItem("large");

   menu.add(file1);
   menu.add(file2);
   menu.add(file3);
  
   menu1.add(blue);
   menu1.add(orange);
   menu1.add(red);
  
   menu2.add(small);
   menu2.add(medium);
   menu2.add(large);

   menubar.add(menu);
   menubar.add(menu1);
   menubar.add(menu2);
   frm.setJMenuBar(menubar);
/*   JMenuBar mb = new JMenuBar();
   JMenu menu1 = new JMenu("Colour");
   mb.add(menu1);
   JMenu menu2 = new JMenu("Size");
   mb.add(menu2);
   frm.setJMenuBar(mb)
*/

}
}

// File3:

import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

@SuppressWarnings("serial")
class SimpleFrame3 extends JFrame
{
   SimpleFrame3(String title)
{
super(title); // invoke the JFrame constructor
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
}
}

public class MyJFrameSubMenu
{
public static void main ( String[] args )
{
       SimpleFrame frm = new SimpleFrame("MyJFrameSubMenu Demo");
   frm.setSize( 400, 400 );   
   frm.setVisible( true );
      
   // main menubar //
   JMenuBar menubar = new JMenuBar();

  
   // creating 3 main menu //
   JMenu menu1 = new JMenu("File");
   JMenu menu2 = new JMenu("Color");
   JMenu menu3 = new JMenu("Size");
  
   // further menu for menu1 //
   JMenu file1 = new JMenu("New");
   JMenu file2 = new JMenu("Open");
   JMenu file3 = new JMenu("Close");
  
   // menuitem should be created for menu2 and menu3 since no sumbmenu list needed //
   JMenuItem blue = new JMenuItem("blue");
   JMenuItem orange = new JMenuItem("orange");
   JMenuItem red = new JMenuItem("red");
  
   JMenuItem small = new JMenuItem("size");
   JMenuItem medium = new JMenuItem("medium");
   JMenuItem large = new JMenuItem("large");
  
  
   // to create further submenu items for File //
   JMenuItem menuItem = new JMenuItem("Item1");
   file2.add(menuItem);
   menuItem = new JMenuItem("Item2");
   file2.add(menuItem);
  
   menu1.add(file1);
   menu1.add(file2);
   menu1.add(file3);

   menu2.add(blue);
   menu2.add(orange);
   menu2.add(red);
  
   menu3.add(small);
   menu3.add(medium);
   menu3.add(large);

   menubar.add(menu1);
   menubar.add(menu2);
   menubar.add(menu3);
  
   frm.setJMenuBar(menubar);

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote