mnaufaldillah

TestApplet Tugas 8

Dec 13th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1.  
  2. import java.awt.*;
  3. import javax.swing.*;
  4.  
  5. /**
  6.  * Class TestApplet - write a description of the class here
  7.  *
  8.  * @author Muhammad Naufaldillah
  9.  * @version 13 Desember 2020
  10.  */
  11. public class TestApplet extends JApplet
  12. {
  13.     /**
  14.      * Paint method for applet.
  15.      *
  16.      * @param  g   the Graphics object for this applet
  17.      */
  18.     public void paint(Graphics g)
  19.     {
  20.         // simple text displayed on applet
  21.         Font f = new Font("Arial", Font.BOLD, 20);
  22.         g.setFont(f);
  23.         g.setColor(Color.GREEN);
  24.  
  25.         int xPusat = this.getSize().width/2;
  26.         int yPusat = this.getSize().height/2;
  27.         int yDasar = this.getSize().height;
  28.         int yAtas = this.getSize().height/16;
  29.  
  30.         String s = "Selamat Belajar Java Applet";
  31.         String nama = "Muhammad naufaldillah";
  32.         String identitas = "Teknik Informatika ITS";
  33.         FontMetrics fm = this.getFontMetrics(f);
  34.         int posisiX = xPusat - (fm.stringWidth(s)/2);
  35.         int posisiZ = xPusat - (fm.stringWidth(nama)/2);
  36.         int posisiQ = xPusat - (fm.stringWidth(identitas)/2);
  37.         g.drawString("Selamat Belajar java Applet", posisiX, yPusat);
  38.         g.drawString("Muhammad naufaldillah", posisiZ, yDasar);
  39.         g.drawString("Teknik Informatika ITS", posisiQ, yAtas);
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment