Advertisement
makispaiktis

20. Easy graphics - Rectangle, string

May 31st, 2022 (edited)
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 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.     public void paintComponent(Graphics g){
  8.         super.paintComponent(g);
  9.         this.setBackground(Color.WHITE);
  10.         g.setColor(Color.BLUE);
  11.         g.fillRect(25, 25, 100, 30);
  12.         g.setColor(new Color(132, 13, 13));
  13.         g.fillRect(25, 65, 100, 30);
  14.         g.setColor(Color.GREEN);
  15.         g.drawString("This is a text", 25, 120);
  16.     }
  17.  
  18.     // Main Function
  19.     public static void main(String[] args){
  20.         JFrame frame = new JFrame("JFrame's title");
  21.         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  22.         Peach p = new Peach();
  23.         frame.add(p);
  24.         frame.setSize(500, 300);
  25.         frame.setVisible(true);
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement