You are on page 1of 11

NO 1

/**
* Write a description of class UjianNomor1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

public class UjianNomor1 extends JFrame


{
public UjianNomor1(){
setTitle("Ujian");
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}

public void paint(Graphics g)


{
//bingkai

g.drawRoundRect(25,150,450,150,55,55);

//garis horizontal tengah


Graphics2D g2d = (Graphics2D)g;
Shape s = new Line2D.Double(170,225,330,225);
g2d.draw(s);

//garis vertikal atas


s = new Line2D.Double(250,165,250,215);
g2d.draw(s);

//garis vertikal bawah 1


s = new Line2D.Double(165,235,165,285);
g2d.draw(s);

//garis vertikal bawah 2


s = new Line2D.Double(335,235,335,285);
g2d.draw(s);

//kotak kanan
s = new Rectangle2D.Double(165,165,50,50);
g2d.draw(s);

//kotak kiri
s = new Rectangle2D.Double(285,165,50,50);
g2d.draw(s);

//bulat dalam kotak kanan


s = new Ellipse2D.Double(175,175,30,30);
g2d.draw(s);

//bulat dalam kotak kiri


s = new Ellipse2D.Double(295,175,30,30);
g2d.draw(s);

//segitiga tengah bawah


int x1[] = {205,295,250};
int y1[] = {230,230,295};
int point = x1.length;
s = new Polygon(x1,y1,point);
g2d.draw(s);

//segitiga kanan atas


int x2[] = {70,120,95};
int y2[] = {210,210,165};
point = x2.length;
s = new Polygon(x2,y2,point);
g2d.draw(s);

//segitiga kanan bawah


int x3[] = {70,120,95};
int y3[] = {240,240,285};
point = x3.length;
s = new Polygon(x3,y3,point);
g2d.draw(s);

//bulat kanan atas


s = new Ellipse2D.Double(380,165,50,50);
g2d.draw(s);
//bulat kanan bawah
s = new Ellipse2D.Double(380,240,50,50);
g2d.draw(s);

//arc kiri atas


s = new Arc2D.Double(35,160,100,100,110,75,0);
g2d.draw(s);

//arc kiri bawah


s = new Arc2D.Double(45,190,100,100,0,-75,0);
g2d.draw(s);

//arc kanan atas


s = new Arc2D.Double(365,160,100,100,5,75,0);
g2d.draw(s);

//arc kanan bawah


s = new Arc2D.Double(345,190,100,100,180,75,0);
g2d.draw(s);
}
public static void main(String[] arr)
{
UjianNomor1 frame = new UjianNomor1();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
NO 2

/**
* Write a description of class UjianNomor2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class UjianNomor2 extends JFrame
{
public UjianNomor2(){
setTitle("Ujian");
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}

public void paint(Graphics g)


{
//bingkai
Graphics2D g2d = (Graphics2D)g;

//--------------------- GAMBAR A ----------------------//


Shape s = new Rectangle2D.Double(20,100,200,200);
g2d.draw(s);

//bulat tengah
s = new Ellipse2D.Double(35,115,170,170);
Area a1 = new Area(s);

//pemotong 1 kotak atas


Shape s1 = new Rectangle2D.Double(40,110,60,60);
Area a2 = new Area(s1);

//pemotong 2 bulat atas


Shape s2 = new Ellipse2D.Double(150,100,80,80);
Area a3 = new Area(s2);

//pemotong 3 bulat bawah


Shape s3 = new Ellipse2D.Double(10,220,80,80);
Area a4 = new Area(s3);

//pemotong 4 kotak bawah


Shape s4 = new Rectangle2D.Double(160,220,60,60);
Area a5 = new Area(s4);

//kotak atas
Shape s5 = new Rectangle2D.Double(45,120,40,40);
g2d.draw(s5);
//bulat atas
s5 = new Ellipse2D.Double(170,120,40,40);
g2d.draw(s5);

//bulat bawah
s5 = new Ellipse2D.Double(30,240,40,40);
g2d.draw(s5);

//kotak bawah
s5 = new Rectangle2D.Double(170,230,40,40);
g2d.draw(s5);

//bulat tengah
s5 = new Ellipse2D.Double(100,180,40,40);
g2d.draw(s5);

a1.subtract(a2);
a1.subtract(a3);
a1.subtract(a4);
a1.subtract(a5);
g2d.draw(a1);
//---------------------- GAMBAR B -------------------//

Shape s6 = new Rectangle2D.Double(240,100,200,200);


g2d.draw(s6);

//kotak besar
Shape s7 = new Rectangle2D.Double(275,170,120,70);
Area b1 = new Area(s7);

//penambah 1 kotak atas 1


Shape s8 = new Rectangle2D.Double(305,140,5,60);
Area b2 = new Area(s8);

//penambah 2 kotak atas 2


Shape s9 = new Rectangle2D.Double(355,140,5,60);
Area b3 = new Area(s9);

//penambah 3 bulat atas


Shape s10 = new Ellipse2D.Double(310,155,45,45);
Area b4 = new Area(s10);

//penambah 4 kotak kanan


Shape s11 = new Rectangle2D.Double(390,185,45,5);
Area b5 = new Area(s11);

//penambah 5 bulat bawah kanan


Shape s12 = new Ellipse2D.Double(347,220,45,45);
Area b6 = new Area(s12);

//penambah 6 bulat bawah kiri


Shape s13 = new Ellipse2D.Double(278,220,45,45);
Area b7 = new Area(s13);

//penambah 7 bulat kiri


Shape s14 = new Ellipse2D.Double(258,200,50,20);
Area b8 = new Area(s14);

//bulat atas
Shape s15 = new Ellipse2D.Double(315,160,35,35);
g2d.draw(s15);

//bulat bawah kanan


s15 = new Ellipse2D.Double(352,225,35,35);
g2d.draw(s15);

//bulat bawah kiri


s15 = new Ellipse2D.Double(283,225,35,35);
g2d.draw(s15);

//bulat bawah kiri


s15 = new Ellipse2D.Double(280,175,20,30);
g2d.draw(s15);

//bulat tengah
s15 = new Ellipse2D.Double(315,200,30,30);
g2d.draw(s15);

//kotak tengah
s15 = new Rectangle2D.Double(355,180,15,30);
g2d.draw(s15);

b1.add(b2);
b1.add(b3);
b1.add(b4);
b1.add(b5);
b1.add(b6);
b1.add(b7);
b1.add(b8);
g2d.draw(b1);

}
public static void main(String[] arr)
{
UjianNomor2 frame = new UjianNomor2();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
NO 3

/**
* Write a description of class UjianNomor3 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class UjianNomor3 extends JFrame
{
public UjianNomor3(){
setTitle("Ujian");
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}

public void paint(Graphics g)


{
Graphics2D g2 = (Graphics2D)g;
Shape s1 = new Ellipse2D.Double(20,0,60,60);
Shape s2 = new Ellipse2D.Double(140,0,60,60);
Shape s3 = new Ellipse2D.Double(60,40,100,100);
Shape s4 = new Ellipse2D.Double(20,120,60,60);
Shape s5 = new Ellipse2D.Double(140,120,60,60);
Shape s6 = new Rectangle2D.Double(80,60,60,60);
Shape s7 = new Rectangle2D.Double(10,20,200,20);
Shape s8 = new Rectangle2D.Double(10,140,200,20);
Area a1 = new Area(s1); Area a2 = new Area(s2);
Area a3 = new Area(s3); Area a4 = new Area(s4);
Area a5 = new Area(s5); Area a6 = new Area(s6);
Area a7 = new Area(s7); Area a8 = new Area(s8);
a3.exclusiveOr(a1); a3.exclusiveOr(a2);
a3.exclusiveOr(a4); a3.exclusiveOr(a5);
a3.subtract(a6); a3.exclusiveOr(a7);
a3.exclusiveOr(a8);
g2.fill(a3);
}
public static void main(String[] arr)
{
UjianNomor3 frame = new UjianNomor3();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

You might also like