-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAWTUtility.java
More file actions
74 lines (61 loc) · 1.67 KB
/
AWTUtility.java
File metadata and controls
74 lines (61 loc) · 1.67 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.util;
import java.awt.Button;
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class AWTUtility {
public static Frame getFrame(String id) {
return new Frame(id);
}
public static void add(Frame frame, Component comp) {
frame.add(comp);
}
public static Button getButton(String id) {
return new Button(id);
}
public static TextField getTextField() {
return new TextField();
}
public static TextArea getTextArea() {
return new TextArea(10, 8);
}
public static void setBounds(Component comp, int x, int y, int width, int height) {
comp.setBounds(x, y, width, height);
}
public static void closeWindow(Frame frame) {
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
// By default BOLD
public static void setFontSize(Component comp, int fontSize) {
comp.setFont(new Font("font", Font.PLAIN, fontSize));
}
public static String calculate(char x, BigDecimal a, BigDecimal b) {
switch (x) {
case '+':
return a.add(b).toString();
case '-':
return a.subtract(b).toString();
case 'X':
return a.multiply(b).toString();
case '/':
return a.divide(b, 3, RoundingMode.HALF_UP).toString();
case '^':
return a.pow(Integer.valueOf(String.valueOf(b))).toString();
default:
return "";
}
}
public static Boolean nextCalIsNeeded(String input) {
return input.contains("=");
}
}