Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- /**
- * Class TestApplet - write a description of the class here
- *
- * @author Muhammad Naufaldillah
- * @version 13 Desember 2020
- */
- public class TestApplet extends JApplet
- {
- /**
- * Paint method for applet.
- *
- * @param g the Graphics object for this applet
- */
- public void paint(Graphics g)
- {
- // simple text displayed on applet
- Font f = new Font("Arial", Font.BOLD, 20);
- g.setFont(f);
- g.setColor(Color.GREEN);
- int xPusat = this.getSize().width/2;
- int yPusat = this.getSize().height/2;
- int yDasar = this.getSize().height;
- int yAtas = this.getSize().height/16;
- String s = "Selamat Belajar Java Applet";
- String nama = "Muhammad naufaldillah";
- String identitas = "Teknik Informatika ITS";
- FontMetrics fm = this.getFontMetrics(f);
- int posisiX = xPusat - (fm.stringWidth(s)/2);
- int posisiZ = xPusat - (fm.stringWidth(nama)/2);
- int posisiQ = xPusat - (fm.stringWidth(identitas)/2);
- g.drawString("Selamat Belajar java Applet", posisiX, yPusat);
- g.drawString("Muhammad naufaldillah", posisiZ, yDasar);
- g.drawString("Teknik Informatika ITS", posisiQ, yAtas);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment