CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Wei Cui
Level 39
Newark
  • 09.04.2020
  • 606views
  • 3comments

keep

Question about the task HTML Editor (part 11)
Java Multithreading,  Level 8,  Lesson 15
Resolved

11.1. Add an UndoManager undoManager field to the view. Figure out what this class is used for. Initialize the field with a new object.
11.2. In the listeners package, add an UndoListener class that implements the UndoableEditListener interface. This class will listen for edits that can undone or redone.
11.3. Add the following to the UndoListener class:
11.3.1. An UndoManager undoManager field.
11.3.2. A constructor that takes an UndoManager and initializes the corresponding field.
11.3.3. An undoableEditHappened(undoableEditEvent e) method. It should get the edit from the passed event and add it to undoManager.
11.4. Add an UndoListener undoListener field to the view, and initialize it using undoManager.
11.5. Add the following methods to the view:
11.5.1. void undo() - This method undoes the last action. Implement it using undoManager.
The method must not throw exceptions. It should only log them.
11.5.2. void redo() - This method returns the previously undone action. Implement it by analogy with the previous step.
11.5.3. Implement boolean canUndo() and boolean canRedo() methods using undoManager.
11.5.4. Implement a getter for undoListener.
11.5.5. Add and implement a void resetUndo() method that clears all edits in undoManager.

Requirements:
  • The View class must have a private UndoManager undoManager field, which must be immediately initialized.
  • The View class must have a private UndoListener undoListener field, which must be immediately initialized using the undoManager field.
  • The View class must have a getter for the UndoListener undoListener field.
  • The View class must have a public void undo() method.
  • The View class must have a public void redo() method.
  • The implementation of the View class's canUndo() method should use undoManager.
  • The implementation of the View class's canRedo() method should use undoManager.
  • The View class should have a public void resetUndo() method, which should clear all edits in undoManager.
  • The UndoListener class must be in a separate file.
  • The UndoListener class must have a private UndoManager undoManager field.
  • The UndoListener(UndoManager undoManager) must correctly initialize the undoManager field.
  • The undoableEditHappened(UndoableEditEvent e) method in the UndoListener class should get the edit from the passed event and add it to undoManager.
package com.codegym.task.task32.task3209; import javax.swing.text.html.HTMLDocument; import java.io.File; public class Controller { private View view; private HTMLDocument document; private File currentFile; public Controller(View view) { this.view = view; } public void init() {} public void exit() { System.exit(0); } public static void main(String[] args) { View view = new View(); Controller controller = new Controller(view); view.setController(controller); view.init(); controller.init(); } public static class ExceptionHandler { public static void log(Exception e) { } } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
KIN SOCHEAT
Level 34 , Phnom Penh, Cambogia
19 July 2020, 03:46
my code don't see anything yet..
0
KIN SOCHEAT
Level 34 , Phnom Penh, Cambogia
19 July 2020, 03:46
hi have you try run does it show the menu?
0
Aleksander
Level 41 , England
9 April 2020, 12:11
Line 115 - I don't know if it is a reason, but I didn't use Controller.ExceptionHandler, just normal ExceptionHandler.
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.