Last active
December 20, 2017 14:58
-
-
Save sugiartocokrowibowo/55699b764d633266e7a18b81c565d593 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 latihan3; | |
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Font; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
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; | |
int[]data = {42,26,16,50,18,2,8,15,23,26,46,30,35,41,15,25,20,25}; | |
int xo,yo,y1 = this.getHeight()-50; | |
int tinggi,lebar=(int)((this.getWidth()-100)/(double)data.length); | |
for(int i=0;i<data.length;i++){ | |
tinggi = data[i]*10; | |
yo = y1 - tinggi; | |
xo = 50+(i*lebar)+2; | |
g2d.setColor(Color.decode("#add8e6")); | |
g2d.fillRect(xo, yo, lebar-4, tinggi); | |
g2d.setColor(Color.BLACK); | |
g2d.setFont(new Font("Arial", Font.PLAIN, 16)); | |
g2d.drawString(""+data[i], xo+lebar/2-10, y1+18); | |
} | |
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