Advertisement
kajacx

SimplePaint

Oct 10th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package test;
  2.  
  3. import java.awt.*;
  4. import javax.swing.*;
  5.  
  6. public class SimpleDraw {
  7.    
  8.     public static void main(String[] args) {
  9.         JFrame frame = new JFrame("Draw something");
  10.         frame.setBounds(30, 30, 500, 500);
  11.         frame.setLayout(null);
  12.        
  13.         JPanel panel = new SimplePanel();
  14.         panel.setBounds(30, 20, 350, 350);
  15.         panel.setBackground(Color.YELLOW);
  16.        
  17.         frame.add(panel);
  18.        
  19.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20.         frame.setVisible(true);
  21.     }
  22.    
  23. }
  24.  
  25. class SimplePanel extends JPanel {
  26.    
  27.     public void paint(Graphics g) {
  28.         super.paint(g); //důležité třeba kvůli vykreslení pozadí
  29.        
  30.         g.setColor(Color.blue);
  31.         g.fillOval(50, 20, 70, 90);
  32.        
  33.         g.setColor(Color.green);
  34.         g.drawRect(80, 20, 60, 70);
  35.        
  36.         g.setColor(Color.red);
  37.         g.drawLine(10, 20, 30, 40);
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement