Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JPanel {
- public static void main(String[] args) {
- JFrame frame = new JFrame("Drawing Board");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(400, 400);
- frame.setVisible(true);
- MyLine line1 = new MyLine(70, 100, 120, 150, Color.BLACK);
- MyLine line2 = new MyLine(60, 80, 120, 150, Color.blue);
- MyLine line3 = new MyLine(50, 65, 120, 150, Color.BLACK);
- MyLine line4 = new MyLine(40, 25, 120, 150, Color.blue);
- MyLine line5 = new MyLine(30, 90, 120, 150, Color.BLACK);
- MyLine line6 = new MyLine(20, 130, 120, 150, Color.blue);
- frame.add(line1);
- frame.add(line2);
- frame.add(line3);
- frame.add(line4);
- frame.add(line5);
- frame.add(line6);
- }
- }
- import java.awt.*;
- import javax.swing.*;
- public class MyLine extends MyShape {
- public MyLine(int x1,int y1,int x2,int y2,Color colorOfLine){
- super(x1, y1, x2, y2, colorOfLine);
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(shapeColor);
- g.drawLine(x1, y1, x2, y2);
- }
- }
- import java.awt.*;
- import javax.swing.*;
- public abstract class MyShape extends JPanel {
- protected int x1,x2,y1,y2;
- protected Color shapeColor;
- protected MyShape(int x1,int y1,int x2,int y2,Color colorOfShape) {
- this.x1=x1;
- this.x2=x2;
- this.y1=y1;
- this.y2=y2;
- shapeColor = colorOfShape;
- }
Add Comment
Please, Sign In to add comment