Skip to content

Commit c394ec3

Browse files
author
Arun Prasaad
committed
Refactor creation of the quit button
1 parent f08a69c commit c394ec3

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/main/java/ihm/Editor.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,9 @@ public Editor (int rowCount, int columnCount, String name) throws IOException {
101101
back.setName(Component.BACK_BUTTON.name());
102102
back.setBounds(windowWidth + 20, 210, 110, 30);
103103

104-
JButton quit = new JButton("Quit");
105-
quit.setName(Component.QUIT_BUTTON.name());
106-
quit.setBounds(windowWidth + 20, 250, 110, 30);
107-
108-
109-
110-
104+
createQuitButton(name);
111105

112-
quit.addActionListener(new ActionListener() {
113-
@Override
114-
public void actionPerformed(ActionEvent e) {
115-
try {
116-
File level_drop = new File(new File(".").getCanonicalPath() + "/levels/" + name + ".txt");
117-
level_drop.delete();
118-
} catch (IOException e1) {
119-
LOGGER.log(Level.SEVERE, "Error while deleting level file: " + name, e1);
120-
}
121-
System.exit( 0 );
122-
}
123-
});
124-
back.addActionListener(new ActionListener() {
106+
back.addActionListener(new ActionListener() {
125107
@Override
126108
public void actionPerformed(ActionEvent e) {
127109
dispose();
@@ -229,7 +211,6 @@ else if (line.length() == columnCount) {
229211

230212

231213
this.add(save);
232-
this.add(quit);
233214
this.add(back);
234215
this.add(invalid_level);
235216

@@ -244,6 +225,26 @@ else if (line.length() == columnCount) {
244225
this.setVisible( true );
245226
}
246227

228+
private void createQuitButton(String name) {
229+
JButton quit = new JButton("Quit");
230+
quit.setName(Component.QUIT_BUTTON.name());
231+
quit.setBounds(windowWidth + 20, 250, 110, 30);
232+
233+
quit.addActionListener(new ActionListener() {
234+
@Override
235+
public void actionPerformed(ActionEvent e) {
236+
try {
237+
File level_drop = new File(new File(".").getCanonicalPath() + "/levels/" + name + ".txt");
238+
level_drop.delete();
239+
} catch (IOException e1) {
240+
LOGGER.log(Level.SEVERE, "Error while deleting level file: " + name, e1);
241+
}
242+
System.exit(0);
243+
}
244+
});
245+
this.add(quit);
246+
}
247+
247248
private void createPlayerButton() {
248249
JButton button = new JButton(new ImageIcon("img/Joueur.jpg"));
249250
button.setName(Component.PLAYER_BUTTON.name());

0 commit comments

Comments
 (0)