JAVA APPLET

Java Applet, Java FX

Applet merupakan program yang dapat dihasilkan oleh bahasa pemrograman Java selain program aplikasi dekstop dan server. Applet java harus dijalankan melalui web browser, misalnya di Microsoft internet explorer, Mozila Firefox, Google Chrome, atau browser yang lainnya.
Applet Java dapat disertakan di dalam dokumen HTML. 




import java.awt.*;
public class TesApplet extends java.applet.Applet{
 
    public void paint(Graphics g){
        Font f = new Font("SansSerif", Font.BOLD, 20);
        g.setFont(f);
        g.setColor(Color.BLUE);
 
        int xPusat = this.getSize().width/2;
        int yPusat = this.getSize().height/2;
 
        String s = "Selamat Belajar Java Applet";
        FontMetrics fm = this.getFontMetrics(f);
        int posisiX = xPusat - (fm.stringWidth(s)/2);
        g.drawString("Selamat Belajar java Applet", posisiX, yPusat);
    }
}


JavaFX adalah library yang digunakan untuk membangun Rich Internet Applications


import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.util.Random;
 
/**
 * Write a description of JavaFX class FortuneTeller here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class FortuneTeller extends Application
{
    Text fortune = new Text("");
    String[] fortunes = {"Test javaFx"};
       
    @Override
    public void start(Stage stage) throws Exception
    {
       VBox box=new VBox();
       box.setPadding(new Insets(20));
       box.setSpacing(20);
       box.setAlignment(Pos.CENTER);
       
       Text title=new Text("Hello Fortune Teller");
       title.setFont(Font.font("SanSerif",36));
       box.getChildren().add(title);
       
       Button button = new Button("Klik JavaFx");
       box.getChildren().add(button);
       
       button.setOnAction(this::buttonClick);
       
       Scene scene=new Scene(box,500,250);
       stage.setTitle("Hello JavaFx");
       stage.setScene(scene);
       stage.show();
       
    }
 
    /**
     * This will be executed when the button is clicked
     * It increments the count by 1
     */
    private void buttonClick(ActionEvent event)
    {
       Random rand = new Random();
       fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
    }
}

Comments

Popular posts from this blog

Buffon Itu Masih Ada

Neymar’s Father Rubbishes Report of Barca-Santos Agreement