20-CS-4003-001 Organization of Programming Languages Fall 2017
Lab Assignment 4

Lambda calculus, Type theory, Formal semantics, Program analysis

Reflection

Due: 29 September, 2017 (submit instructions: here)

Rationale:
    To study a powerful and intriguing aspect of modern computer languages
 
Lab Problem:
Recall reflection example number 3 consisting of a client and server where the client sends class bytes of a JFrame containing a method public void init() to the server which creates an object of the transmitted class and executes that method on that object using reflection. Observe that all of the client's JFrame examples are required to specify dimensions via setSize() and become visible via setVisible (look at Weather.java and Sudoku.java).

This assignment requires modifying Transmitter.java and/or Receiver.java to accept JFrame classes where the calls to setVisible and setSize in init are not required and a JFrame object is displayed via the constructor instead of via init.

Note: a finicky student, who understands the assignment completely and has successfully completed it, has asked me to tell you that to test your solution you will have to change init method in the Weather and Sudoku classes to constructors without setSize or setVisible. I thought this was obvious, especially considering the examples immediately following this note, and apologize if that omission made the assignment lose clarity. Actually, I wonder whether the student just wants to intimidate me - which is impossible.

For example, currently Weather.java looks like this:

   import ...

   public class Weather extends JFrame implements ActionListener {
      ...

      public void init () {
         ...

         setSize(700,300);
         setVisible(true);
      }

      public void actionPerformed (ActionEvent evt) {
         ...
      }
   }
but the modifications will allow Weather.java to look like this:
   import ...

   public class Weather extends JFrame implements ActionListener {
      ...
	
      public Weather () {
         ...
      }

      public void actionPerformed (ActionEvent evt) {
         ...
      }
   }
Sizing and visibility will be established by invoking setSize and setVisible on the superclass of Weather which is the JFrame class. To get a class's superclass do something like this:
   Class <?> frame = cls.getSuperclass();
then to get the setSize method do something like this:
   Method sz = frame.getMethod("setSize", new Class <?> [] { ... });
and to invoke the method do something like this:
   sz.invoke(obj, new Object [] { ... });
where obj is the JFrame object to be displayed. The parameters of Object[] are width and height which are to be set by the user in JTextFields of the Receiver.