Changes were done
This commit is contained in:
2018-02-17 22:06:26 +01:00
8 changed files with 256 additions and 164 deletions

View File

@ -89,12 +89,11 @@ public class GUI implements ActionListener {
this.updatePlayers();
}
public void addProfile(String name) {
this.profiles.addItem(name);
}
public void removeProfile(int index) {
this.profiles.removeItemAt(index);
public void updateProfiles() {
this.profiles.removeAllItems();
for (Profile profile : Profile.getProfiles()) {
this.profiles.addItem(profile.getName());
}
}
/**
@ -400,7 +399,11 @@ public class GUI implements ActionListener {
trayIcon = new TrayIcon(trayImage, "Minecraft Server Launcher", popup);
trayIcon.setImageAutoSize(true);
ActionListener exitListener= e -> {
Profile.getCurrent().save();
try {
Profile.getCurrent().save();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
System.exit(0);
};
@ -432,7 +435,11 @@ public class GUI implements ActionListener {
e1.printStackTrace();
}
} else {
Profile.getCurrent().save();
try {
Profile.getCurrent().save();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
stop();
System.exit(0);
}
@ -453,7 +460,11 @@ public class GUI implements ActionListener {
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Profile.getCurrent().save();
try {
Profile.getCurrent().save();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
stop();
System.exit(0);
}
@ -532,7 +543,11 @@ public class GUI implements ActionListener {
} else if (e.getSource() == mntmStory) {
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/");
} else if (e.getSource() == btnStartServer) {
Profile.getCurrent().save();
try {
Profile.getCurrent().save();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
Executors.newSingleThreadExecutor().execute(Server::startServers);
} else if (e.getSource() == btnStopServer) {
stop();
@ -545,13 +560,19 @@ public class GUI implements ActionListener {
backup();
} else if (e.getSource() == addProfile) {
Profile.addProfile(JOptionPane.showInputDialog("Profile name: "));
updateProfiles();
} else if (e.getSource() == delProfile) {
Object selected = profiles.getSelectedItem();
if (selected != null) {
Profile.removeProfile(selected.toString());
updateProfiles();
}
} else if (e.getSource() == profiles) {
changeProfile();
try {
changeProfile();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
} else if (e.getSource() == btnKick) {
if (selectedServerValue != null && selectedPlayerValue != null) {
Profile.getCurrent().sendCommand(selectedServerValue, "kick " + selectedPlayerValue);
@ -589,7 +610,7 @@ public class GUI implements ActionListener {
/**
* Saves the previous profile and loads data from the new profile.
*/
private void changeProfile() {
private void changeProfile() throws FileNotFoundException {
Profile.getCurrent().save();
Object current = this.profiles.getSelectedItem();
if (current != null) {

View File

@ -1,8 +1,5 @@
package net.knarcraft.serverlauncher.userinterface;
import net.knarcraft.serverlauncher.profile.Collection;
import net.knarcraft.serverlauncher.profile.Profile;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import java.awt.BorderLayout;