Advertisement
thenewboston

Java Programming Tutorial - 84 - Drawing Graphics

Aug 22nd, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Color;
  3. import javax.swing.JPanel;
  4. import javax.swing.JComponent;
  5. import javax.swing.JFrame;
  6.  
  7. public class Drawing {
  8.    public static void main(String args[ ]) {
  9.       JFrame f = new JFrame("Title");
  10.       f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11.       Draws d = new Draws();
  12.       f.add(d);
  13.       f.setSize(400, 250);
  14.       f.setVisible(true);
  15.    }
  16. }
  17.  
  18. class Draws extends JPanel {
  19.    public void paintComponent(Graphics g) {
  20.       super.paintComponent(g);
  21.       this.setBackground(Color.WHITE);
  22.      
  23.       g.setColor(Color.BLUE);
  24.       g.fillRect(10, 10, 100, 30);
  25.      
  26.       g.setColor(Color.RED);
  27.       g.fillRect(10, 50, 100, 30);
  28.      
  29.       g.setColor(Color.BLACK);
  30.       g.drawString("My drawing program", 10, 90);
  31.    }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement