Lagi - lagi grafika komputer.. Postingan ini adalah source code untuk membuat sebuah pemandangan yang sangat amat simple (dilihat) namun coding di dalamnya begitu ruwet -_-
Oke langsung aja, seperti biasa, buat frame terlebih dahulu dengan nama Main.java ..Berikut codingnya :
package javaapplication7;
public class Main {
public static void main(String[] args) {
javax.swing.JFrame frame = new javax.swing.JFrame("Fitri Apriani : Pemandangan");
frame.setSize (500,500);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new coba2 ());
frame.setVisible(true);
}
}
Setelah itu bikin class baru, ini adalah lembar kerja kita.. New Class nya saya beri nama coba2.java *nama bisa kamu sesuaikan dengan keinginanmu, tetapi harus sama dengan yang akan di extend pada Main.java.
So, check this out !!
package javaapplication7;
import java.awt.Color;
import java.awt.geom.QuadCurve2D;
public class coba2 extends javax.swing.JComponent {
public void paint (java.awt.Graphics g){
java.awt.Graphics2D g2 = (java.awt.Graphics2D)g;
java.awt.GradientPaint gp2 = new java.awt.GradientPaint(40,40,Color.white,40,100,Color.blue);
g2.setPaint (gp2);
g2.fillRect(0,0,1000,200);//langit
java.awt.GradientPaint gp = new java.awt.GradientPaint(100,80,Color.blue,100,180,Color.GREEN);
g2.setPaint(gp);
g2.fill(new QuadCurve2D.Double(0,200,100,10,200,200));//Gunung
g2.setColor (Color.YELLOW);
g2.fillOval(300, 80, 50, 50);
g2.drawOval (300,80,50,50); // matahari
java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(20,20, java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D big = bi.createGraphics();
big.setColor (Color.blue);
big.fillRect(0, 0, 20, 20);
big.setColor (Color.white);
big.drawArc(0, 0, 10, 10, 180, 180);
big.drawArc(10, 0, 10, 10, 180, 180);
big.drawArc(20, 0, 10, 10, 180, 180);
big.drawArc(30, 0, 10, 10, 180, 180);
java.awt.Rectangle r = new java.awt.Rectangle(0,0,20,20);
java.awt.TexturePaint tp = new java.awt.TexturePaint(bi, r);
g2.setPaint (tp);
g2.fillRect(200, 200, 800,250);
java.awt.GradientPaint gp3 = new java.awt.GradientPaint(300,300,Color.green,300,200,Color.green);
g2.setPaint (gp3);
g2.fillRect (0,200,200,250);//laut kiri
g2.setColor (Color.green);//gelomboang pemisah
g2.fillArc(175, 200, 50, 50, 270, 180);
g2.fillArc(175, 250, 50, 50, 270, 180);
g2.fillArc(175, 300, 50, 50, 270, 180);
g2.fillArc(175, 350, 50, 50, 270, 180);
g2.fillArc(175, 400, 50, 50, 270, 180);
g2.setColor (Color.WHITE);//LAYAR PERAHU
int []a = {290,330,360};
int []b = {290,200,290};
g2.fillPolygon(a,b,3);
g2.drawPolygon (a,b,3);
g2.setColor (Color.BLACK);
g2.drawLine(290,290,330,200);
g2.drawLine(330,200,360,290);
g2.drawLine(360,290,290,290);
g2.drawLine(330,200,330,290); //GARIS TENGAH LAYAR PERAHU
g2.setColor (Color.WHITE);//kapal
int []x ={300,295,360,355};
int []y ={320,300,300,320};
g2.fillPolygon (x,y,4);
g2.drawPolygon(x,y,4);
}
}
Silahkan Run project kamu, dan lihat hasilnya akan tampak seperti penampakan gambar di bawah ini :
Semoga sukses ~
*jangan lupa tinggalkan jejak komentar :D
Read more »
Oke langsung aja, seperti biasa, buat frame terlebih dahulu dengan nama Main.java ..Berikut codingnya :
package javaapplication7;
public class Main {
public static void main(String[] args) {
javax.swing.JFrame frame = new javax.swing.JFrame("Fitri Apriani : Pemandangan");
frame.setSize (500,500);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new coba2 ());
frame.setVisible(true);
}
}
Setelah itu bikin class baru, ini adalah lembar kerja kita.. New Class nya saya beri nama coba2.java *nama bisa kamu sesuaikan dengan keinginanmu, tetapi harus sama dengan yang akan di extend pada Main.java.
So, check this out !!
package javaapplication7;
import java.awt.Color;
import java.awt.geom.QuadCurve2D;
public class coba2 extends javax.swing.JComponent {
public void paint (java.awt.Graphics g){
java.awt.Graphics2D g2 = (java.awt.Graphics2D)g;
java.awt.GradientPaint gp2 = new java.awt.GradientPaint(40,40,Color.white,40,100,Color.blue);
g2.setPaint (gp2);
g2.fillRect(0,0,1000,200);//langit
java.awt.GradientPaint gp = new java.awt.GradientPaint(100,80,Color.blue,100,180,Color.GREEN);
g2.setPaint(gp);
g2.fill(new QuadCurve2D.Double(0,200,100,10,200,200));//Gunung
g2.setColor (Color.YELLOW);
g2.fillOval(300, 80, 50, 50);
g2.drawOval (300,80,50,50); // matahari
java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(20,20, java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D big = bi.createGraphics();
big.setColor (Color.blue);
big.fillRect(0, 0, 20, 20);
big.setColor (Color.white);
big.drawArc(0, 0, 10, 10, 180, 180);
big.drawArc(10, 0, 10, 10, 180, 180);
big.drawArc(20, 0, 10, 10, 180, 180);
big.drawArc(30, 0, 10, 10, 180, 180);
java.awt.Rectangle r = new java.awt.Rectangle(0,0,20,20);
java.awt.TexturePaint tp = new java.awt.TexturePaint(bi, r);
g2.setPaint (tp);
g2.fillRect(200, 200, 800,250);
java.awt.GradientPaint gp3 = new java.awt.GradientPaint(300,300,Color.green,300,200,Color.green);
g2.setPaint (gp3);
g2.fillRect (0,200,200,250);//laut kiri
g2.setColor (Color.green);//gelomboang pemisah
g2.fillArc(175, 200, 50, 50, 270, 180);
g2.fillArc(175, 250, 50, 50, 270, 180);
g2.fillArc(175, 300, 50, 50, 270, 180);
g2.fillArc(175, 350, 50, 50, 270, 180);
g2.fillArc(175, 400, 50, 50, 270, 180);
g2.setColor (Color.WHITE);//LAYAR PERAHU
int []a = {290,330,360};
int []b = {290,200,290};
g2.fillPolygon(a,b,3);
g2.drawPolygon (a,b,3);
g2.setColor (Color.BLACK);
g2.drawLine(290,290,330,200);
g2.drawLine(330,200,360,290);
g2.drawLine(360,290,290,290);
g2.drawLine(330,200,330,290); //GARIS TENGAH LAYAR PERAHU
g2.setColor (Color.WHITE);//kapal
int []x ={300,295,360,355};
int []y ={320,300,300,320};
g2.fillPolygon (x,y,4);
g2.drawPolygon(x,y,4);
}
}
Silahkan Run project kamu, dan lihat hasilnya akan tampak seperti penampakan gambar di bawah ini :
Semoga sukses ~
*jangan lupa tinggalkan jejak komentar :D