Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.awt.*;
- import javax.swing.*;
- public class SimpleDraw {
- public static void main(String[] args) {
- JFrame frame = new JFrame("Draw something");
- frame.setBounds(30, 30, 500, 500);
- frame.setLayout(null);
- JPanel panel = new SimplePanel();
- panel.setBounds(30, 20, 350, 350);
- panel.setBackground(Color.YELLOW);
- frame.add(panel);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- }
- class SimplePanel extends JPanel {
- public void paint(Graphics g) {
- super.paint(g); //důležité třeba kvůli vykreslení pozadí
- g.setColor(Color.blue);
- g.fillOval(50, 20, 70, 90);
- g.setColor(Color.green);
- g.drawRect(80, 20, 60, 70);
- g.setColor(Color.red);
- g.drawLine(10, 20, 30, 40);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement