-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddCylinderCard.java
More file actions
43 lines (38 loc) · 1.12 KB
/
Copy pathAddCylinderCard.java
File metadata and controls
43 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package lab2.gui.dialog.addshape;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import lab2.shapes.plump.Prism;
import lab2.shapes.flat.Circle;
import lab2.shapes.plump.Shape3D;
class AddCylinderCard extends AddShapeCard {
private JTextField sizea, sizeh;
public AddCylinderCard() {
this.setLayout(new GridLayout(2, 2));
this.add(new JLabel("Radius:"));
sizea = new JTextField();
this.add(sizea);
this.add(new JLabel("Height:"));
sizeh = new JTextField();
this.add(sizeh);
}
public String getTitle() {
return "Cylinder";
}
public Shape3D getValue() {
double a, h;
try {
a = Double.parseDouble(sizea.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Radius value is invalid", "Error", JOptionPane.ERROR_MESSAGE);
return null;
}
try {
h = Double.parseDouble(sizeh.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Height value is invalid", "Error", JOptionPane.ERROR_MESSAGE);
return null;
}
return new Prism(new Circle(a), h);
}
}