Assume the existence of an interface, ActionListener, with the following method: – actionPerformed: void-returning, accepts no parameters Define a class, GUIApplication, that implements the above interface and has the following members:- an instance variable, doc, of type Document-a constructor that accepts a Document parameter used to initialize the instance variable-an implementation of the actionPerformed method that invokes the method, save, with the document instance variable as the receiver and sends the message “document saved” to System.out

3
Assume the existence of an interface, ActionListener, with the following method: – actionPerformed: void-returning, accepts no parameters Define a class, GUIApplication, that implements the above interface and has the following members:- an instance variable, doc, of type Document-a constructor that accepts a Document parameter used to initialize the instance variable-an implementation of the actionPerformed method that invokes the method, save, with the document instance variable as the receiver and sends the message “document saved” to System.out

LANGUAGE: JAVA

CHALLENGE:

Assume the existence of an interface, ActionListener, with the following method: – actionPerformed: void-returning, accepts no parameters Define a class, GUIApplication, that implements the above interface and has the following members:- an instance variable, doc, of type Document-a constructor that accepts a Document parameter used to initialize the instance variable-an implementation of the actionPerformed method that invokes the method, save, with the document instance variable as the receiver and sends the message “document saved” to System.out

SOLUTION:

public class GUIApplication implements ActionListener{
  private Document doc;

  public GUIApplication(Document document){
    doc = document;
  }
  public void actionPerformed(){
    doc.save();
    System.out.println("document saved");
  }
}

3 comments

  • Derek says:

    it should be:

    public class GUIApplication implements ActionListener{
    private Document doc;

    public GUIApplication( Document a){
    doc = a;
    }
    public void actionPerformed(){
    doc.save();
    System.out.print(“document saved”);
    }
    }

  • Basil says:

    it should be

    public class GUIApplication implements ActionListener{
    private Document doc;

    public GUIApplication( Document a){
    doc = a;
    }
    public void actionPerformed(){
    doc.save();
    System.out.println(“document saved”);
    }
    }

  • j p says:

    Use this:

    public class GUIApplication implements ActionListener {
    private Document doc;

    public GUIApplication(Document document) {
    doc = document;
    }

    public void actionPerformed() {
    doc.save();
    System.out.println(“document saved”);
    }
    }

Add comment