Guest User

Untitled

a guest
Nov 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public class Main extends JPanel {
  2. public static void main(String[] args) {
  3. JFrame frame = new JFrame("Drawing Board");
  4. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  5. frame.setSize(400, 400);
  6. frame.setVisible(true);
  7. MyLine line1 = new MyLine(70, 100, 120, 150, Color.BLACK);
  8. MyLine line2 = new MyLine(60, 80, 120, 150, Color.blue);
  9. MyLine line3 = new MyLine(50, 65, 120, 150, Color.BLACK);
  10. MyLine line4 = new MyLine(40, 25, 120, 150, Color.blue);
  11. MyLine line5 = new MyLine(30, 90, 120, 150, Color.BLACK);
  12. MyLine line6 = new MyLine(20, 130, 120, 150, Color.blue);
  13. frame.add(line1);
  14. frame.add(line2);
  15. frame.add(line3);
  16. frame.add(line4);
  17. frame.add(line5);
  18. frame.add(line6);
  19. }
  20. }
  21.  
  22. import java.awt.*;
  23. import javax.swing.*;
  24.  
  25. public class MyLine extends MyShape {
  26.  
  27. public MyLine(int x1,int y1,int x2,int y2,Color colorOfLine){
  28. super(x1, y1, x2, y2, colorOfLine);
  29. }
  30. public void paintComponent(Graphics g) {
  31. super.paintComponent(g);
  32. g.setColor(shapeColor);
  33. g.drawLine(x1, y1, x2, y2);
  34. }
  35. }
  36.  
  37. import java.awt.*;
  38. import javax.swing.*;
  39.  
  40. public abstract class MyShape extends JPanel {
  41. protected int x1,x2,y1,y2;
  42. protected Color shapeColor;
  43. protected MyShape(int x1,int y1,int x2,int y2,Color colorOfShape) {
  44. this.x1=x1;
  45. this.x2=x2;
  46. this.y1=y1;
  47. this.y2=y2;
  48. shapeColor = colorOfShape;
  49. }
Add Comment
Please, Sign In to add comment