Skip to content

Commit

Permalink
fixed importing when running from a jar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarhead20 committed Oct 19, 2022
1 parent 7d5a8a3 commit 3c71d7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/main/java/jarhead/ButtonPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.LinkedList;
Expand Down Expand Up @@ -131,8 +133,8 @@ public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
NodeManager manager = null;
try {
File file = new File(Main.class.getResource("/import.java").toURI());
Scanner reader = new Scanner(file);
InputStream stream = getClass().getClassLoader().getResourceAsStream("import.java");
Scanner reader = new Scanner(stream);
boolean discard = true;
while (reader.hasNextLine()) {
String line = reader.nextLine();
Expand Down Expand Up @@ -178,8 +180,11 @@ public void actionPerformed(ActionEvent e) {
}
}
}
} catch (URISyntaxException | FileNotFoundException uriSyntaxException) {
stream.close();
} catch (FileNotFoundException uriSyntaxException) {
uriSyntaxException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}

main.currentM = managers.size()-1;
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/jarhead/EditPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ public void actionPerformed(ActionEvent e) {
}

public void saveValues(){
Node node = getCurrentNode();
main.getCurrentManager().name = name.getText();
node.x = (Double.parseDouble(x.getText())+72)*main.scale;
node.y = (Double.parseDouble(y.getText())+72)*main.scale;
node.heading = Double.parseDouble(heading.getText());
node.setType(Node.Type.valueOf(type.getText()));
node.code = code.getText();
main.drawPanel.repaint();

if(main.currentN != -1){
Node node = getCurrentNode();
main.getCurrentManager().name = name.getText();
node.x = (Double.parseDouble(x.getText())+72)*main.scale;
node.y = (Double.parseDouble(y.getText())+72)*main.scale;
node.heading = Double.parseDouble(heading.getText());
node.setType(Node.Type.valueOf(type.getText()));
node.code = code.getText();
main.drawPanel.repaint();
}
}
public Node getCurrentNode(){
return main.getCurrentManager().get(main.currentN);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jarhead/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void loadConfig() {
try{
if(prop == null){
prop = new Properties();
InputStream stream = Main.class.getResourceAsStream("/config.properties");
InputStream stream = Main.class.getClassLoader().getResourceAsStream("config.properties");
prop.load(stream);
stream.close();
}
Expand Down

0 comments on commit 3c71d7d

Please sign in to comment.