Skip to content

Commit a92df57

Browse files
committed
Blank textboxes default their respective measurement to 0 instead of showing the pop-up error
1 parent 580862f commit a92df57

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/MainFrame.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,26 @@ public MainFrame() {
7171
@Override
7272
public void actionPerformed(ActionEvent e) {
7373
if (e.getSource() == resizeButton || e.getSource() == widthTextField || e.getSource() == heightTextField) {
74+
String widthText = widthTextField.getText();
75+
String heightText = heightTextField.getText();
76+
7477
try {
75-
widthSize = Integer.parseInt(widthTextField.getText().replaceAll("\\s", ""));
76-
heightSize = Integer.parseInt(heightTextField.getText().replaceAll("\\s", ""));
78+
if (!widthText.isBlank()) {
79+
widthSize = Integer.parseInt(widthText.replaceAll("\\s", ""));
80+
} else {
81+
widthSize = 0;
82+
}
83+
84+
if (!heightText.isBlank()) {
85+
heightSize = Integer.parseInt(heightText.replaceAll("\\s", ""));
86+
} else {
87+
heightSize = 0;
88+
}
89+
7790
this.setSize(widthSize, heightSize);
7891
} catch (NumberFormatException exception) {
7992
JOptionPane.showMessageDialog(this, String.format(
80-
"Empty textfields/textboxes, letters, decimals, symbols, or numbers larger than %s are not allowed!",
93+
"Letters, decimals, symbols, or numbers larger than %s are not allowed!",
8194
Integer.MAX_VALUE), "CANNOT RESIZE!", JOptionPane.ERROR_MESSAGE);
8295
}
8396
} else if (e.getSource() == resizable) {

0 commit comments

Comments
 (0)