Sabtu, 16 Agustus 2025

JAVA - Shape Text Color

 




/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package shapes;


import java.awt.*;

import java.applet.*;


public class Shapes extends Applet

{   

    Font titleFont = new Font("Serif",Font.BOLD,16);


    public void init() 

{  

setBackground(Color.white);     

    }


public void stop() 

{ } 

  

    public void paint(Graphics g) 

{  

g.setFont(titleFont);

g.drawString("Shapes and Colors",80,40); 


// tell g to change the color

g.setColor(new Color(255,50,100)); 

g.setFont(new Font("Arial", Font.ITALIC,30));

g.drawString("Hello World!!", 60, 100);


// draw a rectangle (x0,y0,width,height); 

int x0 = 80, y0 = 150, width = 120, height = 50;

g.setColor(Color.blue); 

g.drawRect(x0,y0,width,height); 

g.setColor(Color.red); 

// fill a rectangle with rounded corners

g.fillRoundRect(x0+5,y0+5,width-10,height-10,30,30); 


// draw an oval

x0 = 80; y0 = 220; width = 120; height = 50;

g.setColor(Color.black); 

g.drawOval(x0,y0,width,height);

g.setColor(new Color(0,255,0)); 

g.setFont(new Font("Arial", Font.PLAIN,30));

g.drawString("Got it",x0+20,y0+height*3/4);


// draw a polygon for the boundary of applet

int[] x = {0,290,290,0};

int[] y = {0,0,290,290};

g.setColor(Color.blue);

g.drawPolygon(x,y,4);   

    }

}




Tidak ada komentar: