Question

In: Computer Science

Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...

Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.  

Solutions

Expert Solution

Hi, Please find below the following Java applet code to draw the required circle and text on screen.

This code is writtten & compiled on Eclipse IDE.

Each segment in code has explanation on why we are using the given syntax and how we are using it.

Please find below the java code:

package applet;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JApplet;

public class Applet extends JApplet{
        
        public void paint(Graphics g) {
                
                /*
                 * First we are setting the size of screen as 400 x 400. 
                 * By default it will be full screen
                 */
                setSize(400, 400);
                
                /*
                 * Now, first we are drawing a circle with black color.
                 * So, first we are setting a color as black.
                 * then using function drawOval(int x, int y, int width, int height), we are drawing circle.
                 * Here (x,y) are coordinates from where we are goint to start to draw our circle with given width and height.
                 */
                g.setColor(Color.BLACK);
                g.drawOval(50,50,300,300);
                
                /*
                 * Now, we are filling the circle drawn above. We can directly use fillOval method to draw a color filled 
                 * circle, but it will not create an outline to the circle. That's why we are first drawing the circle &
                 * then filling it.
                 * 
                 * Here, first we are setting the color as yellow.
                 * Then we are filling the color with slightly less dimension then of circle. If we will take same dimension
                 * as of circle, then yellow color will override the circle boundry
                 */
                g.setColor(Color.YELLOW);
                g.fillOval(51,51,299,299);
                
                /*
                 * To write a text, first we are setting the required font and size using Font class.
                 * Then we are setting text color as Black.
                 * Now, using method drawString(int x, int y). we are writing string.
                 * (x,y) are the coordinates from where we want to start our text.
                 * In our case. it is near to center of circle.
                 */
                Font f1 = new Font("Arial",Font.BOLD,24);
                g.setFont(f1);
                g.setColor(Color.BLACK);
                g.drawString("Go", 180, 200);
                
        }
}

When you will run above code, following picture will be drawn on screen:

Let us know in comments if you have any doubt related to provided solution.


Related Solutions

Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.   answer within 25 min plzzz
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax. I need this answer ASAP PLZ.
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.  
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this...
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT