Skip to content

Commit afbec14

Browse files
committed
adds fix for Eclipse using /bin/ for getCodeBase()
1 parent dc85fad commit afbec14

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sources/net.sf.j2s.java.core/src/a2s/Applet.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.awt.Graphics;
44
import java.awt.HeadlessException;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
57

68
import javax.swing.JApplet;
79
import javax.swing.JPanel;
@@ -57,4 +59,23 @@ protected void paintMe(Graphics g) {
5759
System.out.println("paintMe has not been implemented!");
5860
}
5961

62+
63+
/**
64+
* fix for applet running in Eclipse, which unfortunately uses /bin/ for the codeBase
65+
*
66+
*/
67+
@Override
68+
public URL getCodeBase() {
69+
String codeBase = super.getCodeBase().toString();
70+
if (codeBase.endsWith("/bin/")) {
71+
String appletPath = this.getClass().getName();
72+
codeBase += appletPath.substring(0, appletPath.lastIndexOf(".") + 1).replace('.', '/');
73+
}
74+
try {
75+
return new URL(codeBase);
76+
} catch (MalformedURLException e) {
77+
return null;
78+
}
79+
80+
}
6081
}

0 commit comments

Comments
 (0)