Created
September 20, 2017 13:43
-
-
Save sugiartocokrowibowo/d45bc8aa50f7a17e6c438866f577f242 to your computer and use it in GitHub Desktop.
Class sederhana untuk menggambar kotak menggunakan Java
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
| 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("Simple Java 2D"); | |
| setSize(800, 600); | |
| setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
| setLocationRelativeTo(null); | |
| } | |
| public static void main(String[] args){ | |
| EventQueue.invokeLater(new Runnable(){ | |
| public void run() { | |
| Main ex = new Main(); | |
| ex.setVisible(true); | |
| } | |
| }); | |
| } | |
| public class Canvas extends JComponent { | |
| public void paint(Graphics g) { | |
| Graphics2D g2d = (Graphics2D) g; | |
| g2d.setColor(Color.decode("#3498db")); | |
| g2d.fillRect(100, 100, 200, 200); | |
| 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