mercredi 6 octobre 2021

Looking at YouTube and google I created Code for a simple Jpanel with Button However What the videos don't tell me is what Design patterns am i using

I created an application which allows instantiating shapes which can be circle rectangle or anything and used sorting technqiu (Bubble Sort) to sort the six shapes based on interfaces.

The problem is I am not familiar with Design patterns and what patterns are being used- I am new so i followed youtube videos and played around with it and it worked.

I have 1 main class where I have MAIN : JButton btnLoadShapes, btnSortShapes;

    btnLoadShapes = new JButton("Load Shapes");
    btnLoadShapes.setBounds(150, 10, 150, 30);
    
    btnSortShapes = new JButton("Sort Shapes");
    btnSortShapes.setBounds(310, 10, 150, 30);
    
    
    JPanel panelShapes = new JPanel() {
        public void paintComponent(Graphics g) {
            Graphics2D g2d = (Graphics2D) g;

and i have created 3 different classes Circle Rectangle and Square - from which i call for recatngle = shape.getC(); For example public class Circle { private int x, y, width, height;

public Circle(int x, int y, int width, int height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}

public int getX() {
    return x;
}

public void setX(int x) {
    this.x = x;
}

public int getY() {
    return y;
}

public void setY(int y) {
    this.y = y;
}

public int getWidth() {
    return width;
}

public void setWidth(int width) {
    this.width = width;
}

public int getHeight() {
    return height;
}

public void setHeight(int height) {
    this.height = height;
}

}

Now the lastly I created 2 more classes called Shape and Sorting where in shape i intiated public shape s = new Square with dimensions and set getters and setters and lastly i used sorting technique.

Can someone help me understand what are the design patterns that are being used here? ( I assume that Factory method is being used = since i defined main (* interface) and created subclasses ( Shapes rectangle circle) to instantiate.

Sorry if i sound out the place- I am just trying to understand and learn it.

Aucun commentaire:

Enregistrer un commentaire