-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathGeometryUI.java
More file actions
59 lines (49 loc) · 1.93 KB
/
Copy pathGeometryUI.java
File metadata and controls
59 lines (49 loc) · 1.93 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package ui;
import DatatypesAndVariables.files.FileWriterMain;
import oop.Geometry;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GeometryUI {
JFrame myFrame = new JFrame("Geometry");
JFrame myRectFrame = new JFrame("Rectangle");
JButton btnTriangle = new JButton("Area of Triangle");
JButton btnSquare = new JButton("Area of Square");
JButton btnRectangle = new JButton("Area of Rectangle");
JButton calcCircumference = new JButton("Area of Rectangle");
JTextField radius = new JTextField("Radius");
public void drawUI(){
myFrame.setLayout(new GridLayout(3,1));
myFrame.add(btnTriangle);
myFrame.add(btnSquare);
myFrame.add(btnRectangle);
myFrame.setSize(200, 300);
myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myFrame.setVisible(true);
btnRectangle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
drawCircumference();
JOptionPane.showMessageDialog(null,"Calculate Area of Rectangle");
}
});
}
public void drawCircumference(){
myRectFrame.setLayout(new GridLayout(2, 1));
myRectFrame.add(radius);
myRectFrame.add(calcCircumference);
myRectFrame.setSize(200, 300);
myRectFrame.setVisible(true);
Geometry geometry = new Geometry();
FileWriterMain fileWriterMain = new FileWriterMain();
calcCircumference.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
float area = geometry.areaOfSquare(Float.parseFloat(radius.getText()));
fileWriterMain.writeData("Area Of Square with length: "
+radius.getText()+" is "+ area);
}
});
}
}