How to make it in java ? This is the code ..
package tugas_1;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author alircute
* Game Programming Task
* 21th March 2012
*/
public class Gambar extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2= (Graphics2D) g;
//Make the window
g2.setColor(Color.BLACK);
g2.fillRect(400, 0, 400, 400);
g2.setColor(Color.CYAN);
g2.fillRect(400, 0, 400, 10);
g2.fillRect(400, 195, 400, 10);
g2.fillRect(400, 390, 400, 10);
g2.fillRect(400, 0, 10, 400);
g2.fillRect(600, 0, 10, 400);
//Make the moon
g2.setColor(Color.yellow);
Shape b1 = new Ellipse2D.Double(680, 60, 60, 70);
Shape b2 = new Ellipse2D.Double(670,70,45,45);
Shape m1 = new Ellipse2D.Double(705, 80, 10, 20);
Shape m3 = new Ellipse2D.Double(705, 85, 8, 15);
Shape m2 = new Ellipse2D.Double(715, 80, 10, 20);
Shape m4 = new Ellipse2D.Double(715, 85, 8, 15);
Area r11 = new Area(b2);
Area a11 = new Area(b1);
a11.subtract(r11);
g2.fill(a11);
g2.setColor(Color.BLACK);
g2.draw(m1);
g2.draw(m2);
g2.setColor(Color.WHITE);
g2.fill(m1);
g2.fill(m2);
g2.setColor(Color.BLUE);
g2.fill(m3);
g2.fill(m4);
g2.setColor(Color.BLACK);
g2.fillRect(700, 108, 20, 5);
//Question mark
g2.setFont(new Font("Times New Roman", 1, 24));
g2.setColor(Color.WHITE);
g2.drawString("?", 700, 50);
g2.drawString("?", 670, 80);
g2.drawString("?", 740, 80);
//Make a people
g2.setColor(Color.BLUE);
g2.fillRoundRect(120, 250, 200, 300, 35, 35);
g2.setColor(Color.yellow);
g2.fillRoundRect(200, 220, 30, 50,35,35);
g2.setColor(Color.GREEN);
Shape kepala = new Ellipse2D.Double(155, 100, 120, 150);
g2.fill(kepala);
g2.setColor(Color.WHITE);
g2.fillOval(185, 130, 20, 40);
g2.fillOval(225, 130, 20, 40);
g2.setColor(Color.BLACK);
g2.fillOval(190, 150, 15, 20);
g2.fillOval(225, 150, 15, 20);
Shape mulut = new Ellipse2D.Double(190, 195, 50, 30);
Shape lidah = new Ellipse2D.Double(190, 205, 50, 30);
g2.setColor(Color.RED);
g2.fill(mulut);
Area lidahnya = new Area(lidah);
Area m = new Area(mulut);
m.subtract(lidahnya);
g2.setColor(Color.BLACK);
g2.fill(m);
//Make a notebook
g2.setColor(Color.DARK_GRAY);
g2.fillRoundRect(45, 295, 350, 250, 15, 15);
g2.setColor(Color.DARK_GRAY);
RoundRectangle2D rd=new RoundRectangle2D.Double(45, 545, 350, 20, 15, 15);
g2.fill(rd);
//Make an Apple Logo but I deliberate reserve it
Shape e1 = new Ellipse2D.Double(200,320,40,40);
Shape e2 = new Ellipse2D.Double(220,330,40,40);
Shape e3 = new Ellipse2D.Double(160,370,45,45);
Shape s1 = new Ellipse2D.Double(180, 360, 60, 70);
Shape s2 = new Ellipse2D.Double(210, 360, 50, 70);
Area d1 = new Area(e1);
Area d2 = new Area(e2);
Area r1 = new Area(e3);
Area a2 = new Area(s2);
Area a1 = new Area(s1);
a1.subtract(r1);
a1.add(a2);
d2.intersect(d1);
a1.add(d2);
g2.setColor(Color.LIGHT_GRAY);
g2.draw(a1);
g2.fill(a1);
g2.setFont(new Font("Arial", 1, 32));
g2.setColor(Color.MAGENTA);
g2.drawString("http://www.mabok-coding.com", 10, 650);
}
//The main method
public static void main(String[] args) {
Gambar gambarQ=new Gambar();
gambarQ.setVisible(true);
JFrame f=new JFrame("Alir Emang Oke");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.getContentPane().add(gambarQ);
f.setSize(800,800);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
You can download the source at http://www.4shared.com/rar/CqIe7nal/Java_Graphic2D.html
0 comments:
Post a Comment
Please leave a comment