Advertisement
Wan_ich1

gk

Sep 21st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Insets;
  6.  
  7. import javax.swing.JPanel;
  8. import javax.swing.JFrame;
  9.  
  10. import java.util.Random;
  11.  
  12. public class Geometri extends JPanel {
  13.  
  14.   public void paintComponent(Graphics g) {
  15.       super.paintComponent(g);
  16.  
  17.       Graphics2D g2d = (Graphics2D) g;
  18.  
  19.       g2d.setColor(Color.blue);
  20.  
  21.       Dimension size = getSize();
  22.       Insets insets = getInsets();
  23.  
  24.       int w =  size.width - insets.left - insets.right;
  25.       int h =  size.height - insets.top - insets.bottom;
  26.  
  27.       //menggambar garis
  28.       g2d.drawLine(0,130,170,130);
  29.  
  30.       //menggambar rectangle outline
  31.       g2d.drawRect(0,0,50,50);
  32.  
  33.       //menggambar rectangle fill
  34.       g2d.fillRect(60,0,50,50);
  35.  
  36.       //mengubah warna
  37.       g2d.setColor(Color.red);
  38.  
  39.       //menggambar oval outline
  40.       g2d.drawOval(0,60,50,50);
  41.  
  42.       //menggambar oval fill
  43.       g2d.fillOval(60,60,50,50);
  44.  
  45.   }
  46.  
  47.   public static void main(String[] args) {
  48.  
  49.       JFrame frame = new JFrame("Geometri");
  50.       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  51.       frame.add(new Geometri());
  52.       frame.setSize(250, 200);
  53.       frame.setLocationRelativeTo(null);
  54.       frame.setVisible(true);
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement