0% found this document useful (0 votes)
15 views5 pages

Import Javax

Uploaded by

hnr.uninstall
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Import Javax

Uploaded by

hnr.uninstall
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

import javax.swing.

*;

import java.awt.*;

import java.awt.geom.*;

public class GeometricRocket2D extends JPanel {

@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);

Graphics2D g2d = (Graphics2D) g;

// Menggambar badan roket

g2d.setColor(Color.RED);

g2d.fill(new Rectangle2D.Double(100, 100, 60, 150)); // Badan utama

// Menggambar hidung roket

g2d.setColor(Color.GRAY);

g2d.fill(new Polygon(new int[]{80, 130, 180}, new int[]{100, 50, 100}, 3)); // Hidung

// Menggambar sayap roket

g2d.setColor(Color.DARK_GRAY);

g2d.fill(new Polygon(new int[]{100, 80, 100}, new int[]{250, 300, 300}, 3)); // Sayap kiri

g2d.fill(new Polygon(new int[]{160, 180, 160}, new int[]{250, 300, 300}, 3)); // Sayap kanan

// Menggambar jendela roket

g2d.setColor(Color.CYAN);

g2d.fill(new Ellipse2D.Double(120, 140, 20, 20)); // Jendela

// Menggambar api di bagian bawah


g2d.setColor(Color.ORANGE);

g2d.fill(new Polygon(new int[]{100, 130, 160}, new int[]{250, 350, 250}, 3)); // Api

public static void main(String[] args) {

JFrame frame = new JFrame();

frame.setSize(300, 400);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new GeometricRocket2D());

frame.setVisible(true);

import javax.swing.*;

import java.awt.*;

import java.awt.geom.*;

import java.awt.event.*;

public class AnimatedRocket2D extends JPanel implements ActionListener {

private double rocketY = 400; // Posisi awal roket

private Timer timer;

public AnimatedRocket2D() {

timer = new Timer(50, this); // Timer untuk animasi

timer.start();

@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;

// Menggambar latar belakang langit

g2d.setColor(new Color(135, 206, 235)); // Warna langit biru muda

g2d.fillRect(0, 0, getWidth(), getHeight());

// Menggambar awan

g2d.setColor(Color.WHITE);

g2d.fill(new Ellipse2D.Double(50, 50, 100, 60)); // Awan kiri besar

g2d.fill(new Ellipse2D.Double(80, 40, 120, 70)); // Awan kiri kecil

g2d.fill(new Ellipse2D.Double(200, 80, 130, 80)); // Awan kanan besar

g2d.fill(new Ellipse2D.Double(230, 70, 150, 90)); // Awan kanan kecil

// Menggambar roket

g2d.setColor(new Color(255, 69, 0)); // Warna oranye

g2d.fill(new RoundRectangle2D.Double(110, rocketY, 80, 160, 20, 20)); // Badan utama

// Menggambar hidung roket

g2d.setColor(new Color(169, 169, 169)); // Warna abu-abu gelap

g2d.fill(new Polygon(new int[]{100, 150, 200}, new int[]{(int) rocketY, (int) rocketY - 60, (int)
rocketY}, 3)); // Hidung

// Menggambar sayap roket

g2d.setColor(new Color(105, 105, 105)); // Warna abu-abu lebih gelap

g2d.fill(new Polygon(new int[]{110, 90, 110}, new int[]{(int) rocketY + 160, (int) rocketY + 220, (int)
rocketY + 220}, 3)); // Sayap kiri

g2d.fill(new Polygon(new int[]{190, 210, 190}, new int[]{(int) rocketY + 160, (int) rocketY + 220, (int)
rocketY + 220}, 3)); // Sayap kanan

// Menggambar jendela roket


g2d.setColor(new Color(173, 216, 230)); // Warna biru muda

g2d.fill(new Ellipse2D.Double(140, rocketY + 50, 40, 40)); // Jendela

// Menggambar api di bagian bawah

g2d.setColor(new Color(255, 140, 0)); // Warna oranye api

g2d.fill(new Polygon(new int[]{110, 150, 190}, new int[]{(int) rocketY + 160, (int) rocketY + 280, (int)
rocketY + 160}, 3)); // Api

@Override

public void actionPerformed(ActionEvent e) {

// Menggerakkan roket ke atas

rocketY -= 5;

if (rocketY + 160 < 0) {

rocketY = getHeight(); // Mengulangi dari bawah jika sudah keluar dari layar

repaint();

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {

JFrame frame = new JFrame();

frame.setSize(400, 600);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new AnimatedRocket2D());

frame.setVisible(true);

}
});

You might also like