Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/simplejavacalculator/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class UI implements ActionListener {
private final Calculator calc;

private final String[] buttonValue = {"0", "1", "2", "3", "4", "5", "6",
"7", "8", "9"};
"7", "8", "9", "."};


private final Font font;
Expand Down Expand Up @@ -87,9 +87,9 @@ public UI() throws IOException {

textFont = new Font("Consolas",Font.BOLD, 24);

but = new JButton[10];
for (int i = 0; i < 10; i++) {
but[i] = new JButton(String.valueOf(i));
but = new JButton[11];
for (int i = 0; i < 11; i++) {
but[i] = new JButton(String.valueOf( buttonValue[i] ));
}
butAdd = new JButton("+");
butMinus = new JButton("-");
Expand Down Expand Up @@ -124,7 +124,7 @@ public void init() {
text.setFont(textFont);
text.setEditable(false);

for (int i = 0; i < 10; i++) {
for (int i = 0; i < 11; i++) {
but[i].setFont(font);
}
butAdd.setFont(font);
Expand Down Expand Up @@ -173,10 +173,10 @@ public void init() {
panelSub4.add(butEqual);
panelSub4.add(butCancel);
panel.add(panelSub4);

panelSub5.add(Box.createHorizontalStrut(92));

panelSub5.add(Box.createHorizontalStrut(44));
panelSub5.add(but[10]);
panelSub5.add(but[0]);
panelSub5.add(butln);
panelSub5.add(Box.createHorizontalStrut(210));
panel.add(panelSub5);

Expand All @@ -189,6 +189,7 @@ public void init() {
panelSub7.add(butCos);
panelSub7.add(butSin);
panelSub7.add(butTan);
panelSub7.add(butln);
panel.add(panelSub7);

panelSub8.add(butlog);
Expand All @@ -197,7 +198,7 @@ public void init() {
panelSub8.add(butBinary);
panel.add(panelSub8);

for (int i = 0; i < 10; i++) {
for (int i = 0; i < 11; i++) {
but[i].addActionListener(this);
}
butAdd.addActionListener(this);
Expand Down Expand Up @@ -229,7 +230,7 @@ public void actionPerformed(ActionEvent e) {
final Object source = e.getSource();
Double checkNum = null;

for (int i = 0; i < 10; i++) {
for (int i = 0; i < 11; i++) {
if (source == but[i]) {
text.replaceSelection(buttonValue[i]);
return;
Expand Down