import javax.swing.JEditorPane;
import java.io.FileNotFoundException;

public class MessagePane extends JEditorPane{

   public MessagePane(){

      super("text/html","");
      welcomeUser();
   }

   public void testProgress(){

      try {
        FriendLoader fl = new FriendLoader();
        fl.setMessagePane(this);
         Class friend = fl.getFriend();
         String name = (String)friend.getMethod("getName",null).invoke
                               (friend.newInstance(),null);
         if (name == null){
            stringNotReturned();
         } else greetFriend(name);
      }
      catch (NoSuchMethodException e) {
         methodNotFound();
      }
      catch(ClassCastException e){
         stringNotReturned();
      }
      catch (NullPointerException e){
         classNotFound();
      }
      catch (Exception e){
         e.printStackTrace();
         unexpectedHappened();
      }
   }

   private void welcomeUser(){
     setText("<center> <b> <font color='blue'> "+
       " In this assignment you need to write the code to <br> " +
       " make the following code compile and run:</font> <br><br>"+
       "<font color='black'> <code>Friend friend = new Friend();<br>"+
       "String name = Friend.getName();</code></font> <br><br>"+
       "<font color='green'> You will create a Friend class <br>" +
       " that contains the method called above and returns <br>" +
       " a value of the appropriate type. </font><br><br>"+
       "<font color='red'>Press the button below to check your progress</font>"+
       "</b></center>");
   }

   private void greetFriend(String name){
     setText("<center> <b> <font color='blue'> "+
       " Hello, " + name +". </font> <br><br> <br>" +
       "<font color='green'>Congratulations on solving your first<br>"+
       "programming assignment.</font>" +
       "</b></center>");
   }

   void classNotFound(){
setText("<center> <b> <font color='blue'> "+
       " The first thing that the client class will do is to  <br> " +
       " construct a Friend class with the following code:</font> <br><br>"+
       "<font color='black'><code> Friend friend = new Friend();</code><br> <br>"+
       "<font color='red'> You will first need to create a Friend class. <br>" +
       " Start by creating, saving, and compiling Friend.java <br>" +
       " In the same directory as HelloWorld.jar.  </font><br><br>"+
       "<font color='blue'>The Template for this class is:</font><br><br>"+
  "<font color='black'><code>public class <em> classname </em>{}</code></font>" +
       "</b></center>");
   }

   private void methodNotFound(){
     setText("<center> <b> <font color='green'> "+
       " Good job. You've now created the Friend class. </font> <br><br> " +
       "<font color='blue'>Once the client class has an instance of <br>" +
       " the class Friend it will try to invoke the method <br>" +
       " getName() with the following code.</font> <br><br>"+
       "<font color='black'><code> String name = friend.getName();</code><br> <br>"+
       "<font color='red'> You need to create a method in the Friend class. <br>" +
       " <ul><li> what type must the method return</li>" +
       " <li> what is the method name and </li> " +
       "<li>what parameters must the method take.</li></ul></font>" +
       "<font color='black'>The template for a method that takes no parameter is:<br>"+
  "<code>public <em>  returnType methodname </em>{}</code></font>" +
       "</b></center>");
   }

   private void stringNotReturned(){
     setText("<center> <b> <font color='red'> "+
       " Your method must return a String. </font> <br><br> " +
       "<font color='blue'>Once the client class has an instance of <br>" +
       " the class Friend it will try to invoke the method <br>" +
       " getName() with the following code.</font> <br><br>"+
       "<font color='black'><code> String name = friend.getName();</code><br> <br>"+
       "<font color='red'> You need to create a method in the Friend class. <br>" +
       " <ul><li> what type must the method return</li>" +
       " <li> what is the method name and </li> " +
       "<li>what parameters must the method take.</li></ul></font>" +
       "<font color='black'>The template for a method that takes no parameter is:<br>"+
  "<code>public <em>  returnType methodname </em>{}</code></font>" +
       "</b></center>");
   }

   private void unexpectedHappened(){ //...
   }
}