-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenus.java
144 lines (116 loc) · 4.56 KB
/
Menus.java
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
public class Menus extends JPanel{
private JLabel operationLabel = new JLabel("Clique no botão");
private final Border blackBorder = BorderFactory.createLineBorder(Color.black);
private final JFrame window = new JFrame("MatiMagic");
private float[] operator;
private int centerLabel = 70;
JButton confirmButton = new JButton("Confirmar Resultado");
JNumberField resultLabel = new JNumberField(12);
private boolean programStarted = false;
private int centerField = 310;
private SpinnerModel fractionValor = new SpinnerNumberModel(1, 1, 6, 1);
public JSpinner numberSpinner = new JSpinner(fractionValor);
public JButton newOperationButton = new JButton("Nova Operação");
private int fractionDigits = 1;
private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
public Menus(){
this.newOperationButton();
this.fractionValorButton();
this.introText("Operações matemáticas para a mulher mais linda do mundo!");
this.addOperationLabel();
this.addResultLabel();
this.window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.window.setSize(450, 450);
this.window.setLocationRelativeTo(null);
this.window.setLayout(null);
this.window.setVisible(true);
this.window.setResizable(false);
}
private void introText(String text){
JLabel textApr = new JLabel(text);
JLabel operation = new JLabel();
textApr.setFont(new Font("Arial", Font.BOLD,15));
textApr.setBounds(5, 20, 450, 20);
this.window.add(textApr);
}
private void addResultLabel(){
int yPosition = 250;
JLabel resultInfo = new JLabel("Resultado da Operação:");
resultInfo.setFont(new Font("Arial", Font.BOLD,15));
resultInfo.setBounds(this.centerLabel, yPosition, 300, 20);
resultLabel.setBorder(blackBorder);
resultLabel.setBounds(260, yPosition, 100, 20);
resultLabel.setEditable(false);
this.window.add(resultLabel);
this.window.add(resultInfo);
}
public void setResultEditable(){
this.resultLabel.setEditable(true);
}
private void fractionValorButton(){
int yPosition = 200;
JLabel fractionInfo = new JLabel("Número de casas após a vírgula:");
fractionInfo.setFont(new Font("Arial", Font.BOLD,15));
fractionInfo.setBounds(70, yPosition, 300, 20);
numberSpinner.setBorder(blackBorder);
numberSpinner.setBounds(310, yPosition, 30, 20);
this.window.add(fractionInfo);
this.window.add(numberSpinner);
}
private void newOperationButton(){
newOperationButton.setBounds(60, 350, 300, 40);
this.window.add(newOperationButton);
}
private void addResultButton(){
this.confirmButton.setBounds(60, 300, 300, 40);
this.window.add(confirmButton);
this.window.repaint();
}
public void loadFullProgram(){
this.addResultButton();
}
private void addOperationLabel(){
operationLabel.setBounds(105, 90, 200, 50);
operationLabel.setFont(new Font("Arial", Font.BOLD,15));
operationLabel.setHorizontalAlignment(SwingConstants.CENTER);
operationLabel.setBorder(this.blackBorder);
this.window.add(operationLabel);
}
public void loadOperation(BigDecimal[] operation, char operator){
String firstTerm = String.valueOf(operation[0]);
String secondTerm = String.valueOf(operation[1]);
operationLabel.setText(firstTerm + ' ' + operator + ' ' + secondTerm);
}
public void setNotEditable(){
this.resultLabel.setEditable(false);
this.newOperationButton.setEnabled(false);
this.confirmButton.setEnabled(false);
this.numberSpinner.setEnabled(false);
}
public void setEditable(){
this.resultLabel.setEditable(true);
this.newOperationButton.setEnabled(true);
this.confirmButton.setEnabled(true);
this.numberSpinner.setEnabled(true);
}
public boolean isEnabled(){
return this.numberSpinner.isEnabled();
}
public void setProgramStarted(boolean valor){
this.programStarted = valor;
}
public boolean isProgramStarted(){
return this.programStarted;
}
public void setFractionDigits(int n){
this.fractionDigits = n;
}
public int getFractionDigits(){
return this.fractionDigits;
}
}