Created
December 20, 2017 14:50
-
-
Save sugiartocokrowibowo/f6f32eae11077cf8bc3f77ae15ea700e 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 latihan5; | |
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Font; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import java.awt.RenderingHints; | |
import java.awt.font.TextAttribute; | |
import java.text.AttributedString; | |
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(1000, 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; | |
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); | |
rh.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY); | |
g2d.setRenderingHints(rh); | |
int tinggi = 320; | |
int lebar = 240; | |
int cx = (int) ((this.getWidth()*0.5)-(lebar*0.5)); | |
int cy = (int) ((this.getHeight()*0.5)-(tinggi*0.5)); | |
g2d.setColor(Color.decode("#f39c12")); | |
g2d.fillArc(cx, cy, lebar, tinggi, 0, 180); | |
g2d.setColor(Color.decode("#e74c3c")); | |
g2d.fillRect(cx, (int) (cy-25+tinggi*0.5), lebar, 25); | |
lebar = (int) (1.7*lebar); | |
tinggi = 25; | |
g2d.setColor(Color.decode("#f39c12")); | |
g2d.fillRoundRect((int) (cx-(lebar-240)*0.5), (int) (cy+320*0.5), lebar, tinggi, 25, 25); | |
g2d.setFont(new Font("Neuropol X Rg", Font.PLAIN, 50)); | |
g2d.drawString("Topi Jerami", (int) (cx-(lebar-240)*0.5)+30, (int) (cy+320*0.5)+80); | |
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