Advertisement
Guest User

Canberk

a guest
Apr 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. //public class Canberk extends JFrame{
  5. public class Main extends Canvas{
  6.  
  7.     final int TITLE_BAR_HEIGHT = 20;
  8.     int x, y, radius;
  9.     int dx, dy;
  10.  
  11.     public Main(){
  12.  
  13.         this.x = 20;
  14.         this.y = 50;
  15.         this.radius = 100;
  16.         this.dx = 1;
  17.         this.dy = 1;
  18.  
  19.         JFrame frame = new JFrame();
  20.  
  21.         frame.setSize(640, 640);
  22.         frame.setTitle("Shapes");
  23.         frame.setVisible(true);
  24.         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  25.     }
  26.  
  27.     public void paint(Graphics g) {
  28.         super.paint(g);
  29.  
  30.         g.clearRect(0, 0, getWidth(), getHeight());
  31.         g.setColor(Color.BLUE);
  32.         g.drawOval((getWidth()-radius)/2 , (getHeight()-
  33.                 radius+TITLE_BAR_HEIGHT)/2, radius, radius);
  34.  
  35.         g.setColor(Color.MAGENTA);
  36.         g.drawRect((getWidth()-150)/3, ((getHeight()-150+TITLE_BAR_HEIGHT)/3),
  37.                 radius, radius);
  38.  
  39.         g.setColor(Color.MAGENTA);
  40.         g.drawRect(((getWidth()-80)/3)*2,
  41.                 (getHeight()-150+TITLE_BAR_HEIGHT)/3, radius, radius);
  42.             }
  43.  
  44.     public static void main(String[] args) {
  45.         new Main();
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement