Created
December 20, 2017 14:54
-
-
Save sugiartocokrowibowo/c43c7c86fe1ed1223174c495fe8c3fd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package latihan2; | |
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import javax.swing.JComponent; | |
import javax.swing.JFrame; | |
public class Main extends JFrame { | |
public Main(){ | |
initUI(); | |
} | |
private void initUI() { | |
add(new Canvas()); | |
setTitle("Computer Graphics"); | |
setSize(1024, 600); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setLocationRelativeTo(null); | |
} | |
public static void main(String[] args){ | |
EventQueue.invokeLater(new Runnable(){ | |
public void run() { | |
Main unsulbar = new Main(); | |
unsulbar.setVisible(true); | |
} | |
}); | |
} | |
public class Warna { | |
public Warna(String namaWarna, String codeWarna) { | |
this.nama = namaWarna; | |
this.code = codeWarna; | |
} | |
String nama; | |
String code; | |
} | |
public class Canvas extends JComponent { | |
public void paint(Graphics g) { | |
Graphics2D g2d = (Graphics2D) g; | |
Warna[]arrWarna ={ | |
new Warna("TURQUOISE","#1abc9c"), | |
new Warna("EMERALD","#2ecc71"), | |
new Warna("PETER RIVER","#3498db"), | |
new Warna("AMETHYST","#9b59b6"), | |
new Warna("WET ASPHALT","#34495e"), | |
new Warna("GREEN SEA","#16a085"), | |
new Warna("NEPHRITIS","#27ae60"), | |
new Warna("BELIZE HOLE","#2980b9"), | |
new Warna("WISTERIA","#8e44ad"), | |
new Warna("MIDNIGHT BLUE","#2c3e50"), | |
new Warna("SUN FLOWER","#f1c40f"), | |
new Warna("CARROT","#e67e22"), | |
new Warna("ALIZARIN","#e74c3c"), | |
new Warna("CLOUDS","#ecf0f1"), | |
new Warna("CONCRETE","#95a5a6"), | |
new Warna("ORANGE","#f39c12"), | |
new Warna("PUMPKIN","#d35400"), | |
new Warna("POMEGRANATE","#c0392b"), | |
new Warna("SILVER","#bdc3c7"), | |
new Warna("ASBESTOS","#7f8c8d")}; | |
int tinggi = (int)(this.getHeight()/4.0f); | |
int lebar = (int)(this.getWidth()/5.0f); | |
int k=0; | |
for(int i=0;i<4;i++){ | |
int yo = i*tinggi; | |
for(int j=0;j<5;j++){ | |
int xo = j*lebar; | |
g2d.setColor(Color.decode(arrWarna[k].code)); | |
g2d.fillRect(xo, yo, lebar, tinggi); | |
g2d.setColor(Color.decode("#ffffff")); | |
if(arrWarna[k].nama.equals("CLOUDS")){ | |
g2d.setColor(Color.decode("#95a5a6")); | |
} | |
g2d.drawString(arrWarna[k].nama, xo+14, yo+28); | |
k++; | |
} | |
} | |
g2d.dispose(); | |
//--------------------------------------------------------------------------------------------------- | |
}//end of paint(Graphics g) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment