ini dia, source code yang akan saya bagikan hasil pekerjaan Ujian Praktik Pemrograman 2 Semester 2
Maaf program yang saya buat pas ujian ini memang sangat sederhana,, hehee.. mungkin buat latian teman-teman saja. semoga bisa membantu .. :
Classnya adalah UAS_Java.java .
import java.awt.*;
import java.awt.geom.*;
import javax.swing.JFrame;
/**
*
* @author HardhikaST16
*/
public class UAS_Java extends JFrame{
public static void main(String[] args){
new UAS_Java();
}
public UAS_Java() {
super("Something");
setSize(600, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Bunder k = new Bunder();
add(k);
show();
}
class Bunder extends Canvas implements Runnable{
Thread runner;
int i =0;
Dimension area = new Dimension(300,300);
Color warna1 = Color.WHITE;
Color warna2 = Color.RED;
Color warna3 = Color.BLACK;
Color warna4 = Color.YELLOW;
Color warna5 = Color.ORANGE;
Color warna6 = Color.BLUE;
Color warna7 = Color.GREEN;
Color warna8 = Color.pink;
Color warna9 = Color.MAGENTA;
Color warna10 = Color.LIGHT_GRAY;
Color warna11 = Color.CYAN;
Color warna12 = Color.DARK_GRAY;
Color temp;
public void paint(Graphics g) {
g.fillRect(10, 45, 365, 5);
g.drawString("HARDIKA DWI HERMAWAN", 10, 65);
g.drawString("PENDIDIKAN TEKNIK INFORMATIKA", 10, 85);
g.drawString("NIM. 11520241004 KELAS E1", 10, 105);
//SETENGAH LINGKARAN
g.setColor(warna10);
g.fillArc(230, 170, 60, 60, 0, 180);
//ATAS ROUND
g.setColor(warna3);
g.drawRoundRect(200, 200, 120, 80, 20, 20);
g.drawRoundRect(199, 199, 122, 82, 19, 21);
g.setColor(warna4);
g.fillRoundRect(200, 200, 120, 80, 20, 20);
//KOTAK TENGAH MERAH
g.setColor(warna3);
g.drawRect(220, 220, 80, 40);
g.setColor(warna3);
g.drawRect(219, 219, 82, 42);
g.setColor(warna3);
g.drawRect(218, 218, 83, 43);
g.setColor(warna2);
g.fillRect(220, 220, 80, 20);
g.setColor(warna3);
g.drawRect(220, 220, 80, 40);
//KOTAK TENGAHPUTIH
g.setColor(warna1);
g.fillRect(220, 240, 80, 20);
//POLIGON 7 TITIK
int [] X = {60, 200, 300, 460, 460, 520,60};
int [] Y = {300, 280, 280, 300, 380, 400,400};
g.setColor(warna5);
g.fillPolygon(X, Y, 7);
g.drawPolygon(X, Y, 7);
g.setColor(warna2);
//BALING EKOR
g.setColor(warna7);
g.fillArc(500, 380, 40, 40, 90, -45);
g.fillArc(500, 380, 40, 40, 270, -45);
//GARIS TENGAH
g.setColor(warna1);
g.drawLine(125, 330, 260,300 );
g.drawLine(380, 330, 260,300 );
g.drawLine(125, 370, 380,370 );
//LINGKARAN 2 KIRI
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 180, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 90, 45);
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 90, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 0, 45);
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 0, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 180, 45);
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 270, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 270, 45);
//LINGKARAN 2 KANAN
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 180, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 90, 45);
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 90, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 0, 45);
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 0, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 180, 45);
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 270, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 270, 45);
//SETENGAH LINGKARAN KIRI
g.setColor(warna2);
g.fillArc(20, 300, 100, 100, 90, 180);
//BALING BAWAH
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 180, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 90, 45);
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 90, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 0, 45);
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 0, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 180, 45);
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 270, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 270, 45);
start();
}
private void start(){
if (runner==null){
runner = new Thread(this);
runner.start();
}
}
@Override
public void run() {
while(true) {
try{
runner.sleep(50);
} catch(Exception e){}
if(i % 2 == 0){
temp = warna6;
warna6 = warna7;
warna7 = temp;
temp = warna8;
warna8 = warna9;
warna9 = temp;
temp = warna10;
warna10 = warna11;
warna11 = warna12;
warna12 = temp;
}
i++;
repaint();
}
}
}
}
Maaf program yang saya buat pas ujian ini memang sangat sederhana,, hehee.. mungkin buat latian teman-teman saja. semoga bisa membantu .. :
Classnya adalah UAS_Java.java .
import java.awt.*;
import java.awt.geom.*;
import javax.swing.JFrame;
/**
*
* @author HardhikaST16
*/
public class UAS_Java extends JFrame{
public static void main(String[] args){
new UAS_Java();
}
public UAS_Java() {
super("Something");
setSize(600, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Bunder k = new Bunder();
add(k);
show();
}
class Bunder extends Canvas implements Runnable{
Thread runner;
int i =0;
Dimension area = new Dimension(300,300);
Color warna1 = Color.WHITE;
Color warna2 = Color.RED;
Color warna3 = Color.BLACK;
Color warna4 = Color.YELLOW;
Color warna5 = Color.ORANGE;
Color warna6 = Color.BLUE;
Color warna7 = Color.GREEN;
Color warna8 = Color.pink;
Color warna9 = Color.MAGENTA;
Color warna10 = Color.LIGHT_GRAY;
Color warna11 = Color.CYAN;
Color warna12 = Color.DARK_GRAY;
Color temp;
public void paint(Graphics g) {
g.fillRect(10, 45, 365, 5);
g.drawString("HARDIKA DWI HERMAWAN", 10, 65);
g.drawString("PENDIDIKAN TEKNIK INFORMATIKA", 10, 85);
g.drawString("NIM. 11520241004 KELAS E1", 10, 105);
//SETENGAH LINGKARAN
g.setColor(warna10);
g.fillArc(230, 170, 60, 60, 0, 180);
//ATAS ROUND
g.setColor(warna3);
g.drawRoundRect(200, 200, 120, 80, 20, 20);
g.drawRoundRect(199, 199, 122, 82, 19, 21);
g.setColor(warna4);
g.fillRoundRect(200, 200, 120, 80, 20, 20);
//KOTAK TENGAH MERAH
g.setColor(warna3);
g.drawRect(220, 220, 80, 40);
g.setColor(warna3);
g.drawRect(219, 219, 82, 42);
g.setColor(warna3);
g.drawRect(218, 218, 83, 43);
g.setColor(warna2);
g.fillRect(220, 220, 80, 20);
g.setColor(warna3);
g.drawRect(220, 220, 80, 40);
//KOTAK TENGAHPUTIH
g.setColor(warna1);
g.fillRect(220, 240, 80, 20);
//POLIGON 7 TITIK
int [] X = {60, 200, 300, 460, 460, 520,60};
int [] Y = {300, 280, 280, 300, 380, 400,400};
g.setColor(warna5);
g.fillPolygon(X, Y, 7);
g.drawPolygon(X, Y, 7);
g.setColor(warna2);
//BALING EKOR
g.setColor(warna7);
g.fillArc(500, 380, 40, 40, 90, -45);
g.fillArc(500, 380, 40, 40, 270, -45);
//GARIS TENGAH
g.setColor(warna1);
g.drawLine(125, 330, 260,300 );
g.drawLine(380, 330, 260,300 );
g.drawLine(125, 370, 380,370 );
//LINGKARAN 2 KIRI
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 180, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 90, 45);
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 90, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 0, 45);
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 0, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 180, 45);
g.setColor(warna6);
g.fillArc(110, 330, 40, 40, 270, -45);
g.setColor(warna7);
g.fillArc(110, 330, 40, 40, 270, 45);
//LINGKARAN 2 KANAN
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 180, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 90, 45);
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 90, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 0, 45);
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 0, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 180, 45);
g.setColor(warna6);
g.fillArc(360, 330, 40, 40, 270, -45);
g.setColor(warna7);
g.fillArc(360, 330, 40, 40, 270, 45);
//SETENGAH LINGKARAN KIRI
g.setColor(warna2);
g.fillArc(20, 300, 100, 100, 90, 180);
//BALING BAWAH
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 180, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 90, 45);
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 90, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 0, 45);
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 0, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 180, 45);
g.setColor(warna9);
g.fillArc(220, 430, 90, 90, 270, -45);
g.setColor(warna8);
g.fillArc(220, 430, 90, 90, 270, 45);
start();
}
private void start(){
if (runner==null){
runner = new Thread(this);
runner.start();
}
}
@Override
public void run() {
while(true) {
try{
runner.sleep(50);
} catch(Exception e){}
if(i % 2 == 0){
temp = warna6;
warna6 = warna7;
warna7 = temp;
temp = warna8;
warna8 = warna9;
warna9 = temp;
temp = warna10;
warna10 = warna11;
warna11 = warna12;
warna12 = temp;
}
i++;
repaint();
}
}
}
}
0 komentar:
Posting Komentar