Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Color;
- import javax.swing.JPanel;
- import javax.swing.JComponent;
- import javax.swing.JFrame;
- public class Drawing {
- public static void main(String args[ ]) {
- JFrame f = new JFrame("Title");
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Draws d = new Draws();
- f.add(d);
- f.setSize(400, 250);
- f.setVisible(true);
- }
- }
- class Draws extends JPanel {
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- this.setBackground(Color.WHITE);
- g.setColor(Color.BLUE);
- g.fillRect(10, 10, 100, 30);
- g.setColor(Color.RED);
- g.fillRect(10, 50, 100, 30);
- g.setColor(Color.BLACK);
- g.drawString("My drawing program", 10, 90);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement