Skip to content

Commit e6c11d2

Browse files
author
Arun Prasaad
committed
Refactor creation of the error label
1 parent 57cf0f0 commit e6c11d2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/main/java/ihm/Editor.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ public Editor (int rowCount, int columnCount, String name) throws IOException {
8585
createTargetButton();
8686
createEmptyButton();
8787

88-
// Status label
89-
JLabel invalid_level = new JLabel("", SwingConstants.CENTER);
90-
invalid_level.setName(Component.ERROR_LABEL.name());
91-
invalid_level.setForeground(Color.RED);
92-
invalid_level.setBounds(windowWidth, 145, 150, 20);
88+
JLabel errorLabel = createErrorLabel();
9389

9490
// Action buttons
9591
JButton save = new JButton("Save");
@@ -168,14 +164,14 @@ else if (line.length() == columnCount) {
168164
new HomeWindow();
169165
}
170166
else {
171-
invalid_level.setText("Invalid level!");
167+
errorLabel.setText("Invalid level!");
172168
}
173169
}
174170
});
175171

176172

177173
this.add(save);
178-
this.add(invalid_level);
174+
this.add(errorLabel);
179175

180176
JPanel sokobanPanel = new SokobanPanel(controller);
181177
sokobanPanel.setName(Component.SOKOBAN_PANEL.name());
@@ -294,6 +290,15 @@ private void createTargetButton() {
294290
this.add(button);
295291
}
296292

293+
private JLabel createErrorLabel() {
294+
JLabel label = new JLabel("", SwingConstants.CENTER);
295+
label.setName(Component.ERROR_LABEL.name());
296+
label.setForeground(Color.RED);
297+
label.setBounds(windowWidth, 145, 150, 20);
298+
this.add(label);
299+
return label;
300+
}
301+
297302
private void createEmptyButton() {
298303
JButton button = new JButton(new ImageIcon("img/Vide.jpg"));
299304
button.setName(Component.EMPTY_BUTTON.name());

0 commit comments

Comments
 (0)