Anda di halaman 1dari 6

Nama : Sausan Syahirah

NIM: 09021381722100

Kelas: Tibil 4B

/*

* 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 grafkomm;

import java.awt.Color;

import java.awt.EventQueue;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.geom.AffineTransform;

import javax.swing.JFrame;

import javax.swing.JPanel;

import java.util.Scanner;

/**

* @author Personal

*/

class SurfaceScaling extends JPanel {

private void doDrawing(Graphics g) {

Graphics2D g2d = (Graphics2D) g.create();

g2d.setColor(new Color(125, 150, 150));

g2d.fillRect(20, 20, 80, 50);

AffineTransform tx1 = new AffineTransform();


tx1.translate(110, 22);

tx1.scale(0.5, 0.5);

g2d.setTransform(tx1);

g2d.fillRect(0, 0, 80, 50);

AffineTransform tx2 = new AffineTransform();

tx2.translate(170, 20);

tx2.scale(1.5, 1.5);

g2d.setTransform(tx2);

g2d.fillRect(0, 0, 80, 50);

g2d.dispose();

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

doDrawing(g);

class SurfaceRotation extends JPanel {

private void doDrawing(Graphics g) {

Graphics2D rotation = (Graphics2D) g.create();

rotation.setPaint(new Color(100, 150, 150));


rotation.fillRect(20, 20, 80, 50);

rotation.translate(180, -50);

rotation.rotate(Math.PI/4);

rotation.fillRect(80, 80, 80, 50);

rotation.dispose();

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

doDrawing(g);

class SurfaceTranslation extends JPanel {

private void doDrawing(Graphics g) {

Graphics2D transaltion = (Graphics2D) g.create();

transaltion.setPaint(new Color(200, 150, 150));

transaltion.fillRect(20, 20, 80, 50);

transaltion.translate(150, 50);

transaltion.fillRect(20, 20, 80, 50);

transaltion.dispose();

@Override

public void paintComponent(Graphics g) {


super.paintComponent(g);

doDrawing(g);

public class tugas extends JFrame {

public tugas() {

Scanner data = new Scanner (System.in);

System.out.println("1. Translasi");

System.out.println("2. Scaling");

System.out.println("3. Rotasi");

System.out.print("Masukkan pilihan : ");

String pilihan = data.nextLine();

if(pilihan.equals("Translasi") || pilihan.equals("1")){

initUITranslation();

}else

if(pilihan.equals("Scaling") || pilihan.equals("2")){

initUIScale();

}else

if(pilihan.equals("Rotasi") || pilihan.equals("3")){

initUIRotation();

}else{

System.out.println("Salah pilihan");

System.exit(0);

private void initUITranslation() {


add(new SurfaceTranslation());

setTitle("Translation");

setSize(300, 200);

setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

private void initUIScale() {

add(new SurfaceScaling());

setTitle("Scaling");

setSize(350, 200);

setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

private void initUIRotation() {

setTitle("Rotation");

add(new SurfaceRotation());

setSize(300, 200);

setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

public static void main(String[] args) {


EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

tugas ex = new tugas();

ex.setVisible(true);

});