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

Please do not attempt this question if you are not sure about it. Please send me

ID: 3679021 • Letter: P

Question

Please do not attempt this question if you are not sure about it. Please send me the complete Java code with OUTPUT(screen shots) only if it is working at your end.

QUESTION: Complete the following client-server program in JAVA to do the following. (You'll need to fill in the gaps completing the methods and also, make sure you are extending Applet for the client program.)

a) The server sends 1, or 2 to the client.

b) If the client receives 1, it draws a rectangle. If the client receives 2, it draws a circle.

Please use the follwoing code and provide me the complete solution after writing and testing all the methods:

Server Code:

===================================

import java.io.*;

import java.net.*;

import java.util.Scanner;

public class MyServer {

public static void main(String[] args){

    //Complete this method.

}

}

Client Code:

==========================================

import java.applet.Applet;

import java.awt.*;

import java.io.*;

import java.net.*;

public class MyClient extends Applet {

private int s;

      

public void init(){

    //Complete this method.

    setSize(400, 400);

    try{

      //You may need repaint();

      repaint();

    }catch(Exception e){

      System.out.println("Error: " + e);

      System.exit(0);

    }

}

public void paint(Graphics page){

    //Complete this method.

}

}

Explanation / Answer

import java.applet.Applet;

<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>

Here is the output of my program:
<APPLET CODE="Shape.class" WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>

/////applet code//////

import java.awt.*;

import java.io.*;

import java.net.*;

public class Shape extends Applet {

private int s;

    

public void init(){

text1 = new TextField(8);
add(text1);
text1.setText("0");
    setSize(400, 400);

    try{

      //You may need repaint();

      repaint();

    }catch(Exception e){

      System.out.println("Error: " + e);

      System.exit(0);

    }

}

public void paint(Graphics page){


   g.drawString("enter 1 for rectangle!", 50, 25);
g.drawString("enter 2 for circle!", 75, 50);
    int x=0;
          String s1;
          g.drawString("Input a number in each box ",10,50);
          try
          {
                 s1 = text1.getText();
                 x = Integer.parseInt(s1);
           }
          catch(Exception e) {}
          if(x==1)
          g.drawRect(10,10,50,100);
       else if(x==2)
        g.drawOval(10,10,50,50);
else
g.drawString("enter valid input ",10,50);
    }
}

}