-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSaveButton.java
26 lines (25 loc) · 947 Bytes
/
SaveButton.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.io.*;
import javax.swing.*;
/**
* Write a description of class SaveButton here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SaveButton extends Tool
{
public void edited() {
JFileChooser filechooser = new JFileChooser();
if (filechooser.showSaveDialog(null)==JFileChooser.APPROVE_OPTION) {
File selected = filechooser.getSelectedFile();
String ext = "";
if (selected.getAbsolutePath().lastIndexOf(".")>-1) ext = selected.getAbsolutePath().substring(selected.getAbsolutePath().lastIndexOf("."));
if (!ext.equals(".pe") && !ext.equals(".lev")) {
selected = new File(selected.getAbsolutePath()+".pe");
}
LevelFile lvlFile = new LevelFile(selected, getWorld());
lvlFile.save();
}
}
}