Advertisement
makispaiktis

22. Drawing shapes and 3D

May 31st, 2022 (edited)
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Peach extends JPanel{
  6.  
  7.     // Variables
  8.     public void paintComponent(Graphics g){
  9.         super.paintComponent(g);
  10.         this.setBackground(Color.WHITE);
  11.         // Line
  12.         g.setColor(Color.BLUE);
  13.         g.drawLine(10, 25, 200, 45);
  14.         // Rectangle
  15.         g.setColor(Color.RED);
  16.         g.drawRect(10, 55, 100, 30);
  17.         // Oval
  18.         g.setColor(Color.GREEN);
  19.         g.fillOval(10, 95, 100, 30);
  20.         // 3D Rectangle
  21.         g.setColor(Color.ORANGE);
  22.         g.fill3DRect(10, 160, 100, 50, true);
  23.  
  24.     }
  25.  
  26.     // Main Function
  27.     public static void main(String[] args){
  28.         JFrame f = new JFrame("JFrame's title");
  29.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.         Peach p = new Peach();
  31.         p.setBackground(Color.WHITE);
  32.         f.add(p);
  33.         f.setSize(500, 300);
  34.         f.setVisible(true);
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement