Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawFigure extends JPanel {
- int type;
- int length, width, height, radius;
- public DrawFigure() {
- super();
- type = 5;
- }
- public DrawFigure(int myType, int myWidth, int myLength, int myHeight) { // Box and Rectangle
- super();
- type = myType;
- length = myLength;
- width = myWidth;
- height = myHeight;
- }
- public DrawFigure(int x, int y, int myType, int myWidth, int myLength, int myHeight) {
- super();
- type = myType;
- length = myLength;
- width = myWidth;
- height = myHeight;
- }
- public DrawFigure(int myType, int myRadius, int myHeight) {
- super();
- type = myType;
- radius = myRadius;
- height = myHeight;
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- if (type == 1) { // Draw Rectangle
- g.drawRect(50, 110, width, length);
- } else if (type == 2) { // Draw Box
- g.draw3DRect(50, 110, length, width, true);
- /*
- g.setColor(Color.GREEN);
- g.fillRect(50, 110, width, height);
- g.setColor(Color.BLACK);
- g.drawLine(50, 110, length, height);
- */
- return;
- } else if(type == 3) { // Draw Circle
- // You will need one draw command to make a circle
- g.setColor(Color.RED);
- g.drawOval(50, 110, radius, radius);
- return;
- } else if(type == 4) { // Draw Cylinder
- g.setColor(Color.BLACK);
- g.drawOval(135, 65, radius, radius - radius / 2);
- // Base
- g.setColor(Color.RED);
- g.fillOval(135, 65 + height, radius, radius / 2);
- g.setColor(Color.BLACK);
- g.drawLine(135, 65 + height + (height /4), 135, 135);
- g.setColor(Color.BLACK);
- g.drawLine(135 + radius, 65 + height + (height /4), 135 + radius, 135);
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement