Skip to content

Commit 8834205

Browse files
authored
Merge pull request #236 from BobHanson/hanson1
Hanson1
2 parents c00bd94 + f07c632 commit 8834205

File tree

13 files changed

+1100
-812
lines changed

13 files changed

+1100
-812
lines changed
-2.89 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20220713221322
1+
20220914134307
-2.89 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20220713221322
1+
20220914134307
-2.26 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/javajs/util/DF.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static String formatDecimal(double value, int decimalDigits) {
8585
value = -value;
8686
int n;
8787
if (decimalDigits < 0) {
88-
decimalDigits = -1-decimalDigits;
88+
decimalDigits = -decimalDigits;
8989
if (decimalDigits > formattingStrings.length)
9090
decimalDigits = formattingStrings.length;
9191
if (value == 0)
@@ -103,7 +103,7 @@ public static String formatDecimal(double value, int decimalDigits) {
103103
String s = ("" + d).toUpperCase();
104104
int i1 = s.indexOf("E");
105105
String sf;
106-
if (i1 < 0) {
106+
if (i1 < 0) {
107107
sf = "" + value;
108108
} else {
109109
n = PT.parseInt(s.substring(i1 + (s.indexOf("E+") == i1 ? 2 : 1))) + n;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package test;
2+
3+
import java.beans.PropertyChangeEvent;
4+
import java.beans.PropertyChangeListener;
5+
6+
import javax.swing.JDesktopPane;
7+
import javax.swing.JDialog;
8+
import javax.swing.JFrame;
9+
import javax.swing.JOptionPane;
10+
import javax.swing.SwingUtilities;
11+
12+
import javajs.async.SwingJSUtils;
13+
14+
public class DialogsTest extends JFrame {
15+
16+
private class PCLPane extends JDesktopPane implements PropertyChangeListener {
17+
@Override
18+
public void propertyChange(PropertyChangeEvent evt) {
19+
String name = evt.getPropertyName();
20+
System.out.println(name);
21+
if (name.equals("value")) {
22+
handlePropEvent(evt.getNewValue());
23+
}
24+
}
25+
}
26+
27+
DialogsTest() {
28+
setDefaultCloseOperation(EXIT_ON_CLOSE);
29+
setBounds(0, 0, 800, 600);
30+
setVisible(true);
31+
// For JavaScript, we need a property change listener.
32+
setContentPane(new PCLPane());
33+
34+
JOptionPane pane = new JOptionPane("I'm a banana");
35+
JDialog dialog = pane.createDialog(getContentPane(), "Hello!");
36+
dialog.setVisible(true);
37+
if (/** @j2sNative false && */
38+
true)
39+
report("done");
40+
// JavaScript continues....
41+
}
42+
43+
public void handlePropEvent(Object newValue) {
44+
System.out.println("value was " + newValue);
45+
report("done");
46+
}
47+
48+
private void report(String string) {
49+
System.out.println(string);
50+
JOptionPane.showMessageDialog(this, "I'm a Banana");
51+
System.out.println("ok");
52+
53+
}
54+
55+
public static void main(String[] args) {
56+
SwingUtilities.invokeLater(DialogsTest::new);
57+
}
58+
59+
}

sources/net.sf.j2s.java.core/src/test/Test_Double.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,31 @@ public static void main(String[] args) {
3939
System.out.println((PT.toDouble(-0.999999f)) + " " + (1d-0.999999d)
4040
+ " " + 0.000001d
4141
+ " " + (double) -0.999999f);
42+
System.out.println(DF.formatDecimal(123456f, -4));
43+
System.out.println(DF.formatDecimal(999999f, -4));
44+
45+
System.out.println(PT.sprintf("%4.0e", "d", new Object[]{1.2345678e-4}));
46+
System.out.println(DF.formatDecimal(0.123456f, -1));
47+
System.out.println(DF.formatDecimal(0.999999f, -4));
48+
System.out.println(String.format("%4.0e",0.12345));
49+
System.out.println(String.format("%4.3e",0.12345));
50+
System.out.println(String.format("%4.3f",0.12345));
51+
System.out.println(DF.formatDecimal(0.12345, -4));
52+
System.out.println(DF.formatDecimal(0.12345, 4));
53+
54+
55+
assert(DF.formatDecimal(123456f, -4).equals("1.235E+5"));
56+
assert(DF.formatDecimal(999999f, -4).equals("1.000E+6"));
57+
58+
assert(PT.sprintf("%4.0e", "d", new Object[]{1.2345678e-4}).equals("1E-4"));
59+
assert(DF.formatDecimal(0.123456f, -1).equals("1E-1"));
60+
assert(DF.formatDecimal(0.999999f, -4).equals("1.000E+0"));
61+
assert(String.format("%4.0e",0.12345).equals("1e-01"));
62+
assert(String.format("%4.3e",0.12345).equals("1.235e-01"));
63+
assert(String.format("%4.3f",0.12345).equals("0.123"));
64+
assert(DF.formatDecimal(0.12345, -4).equals("1.235E-1"));
65+
assert(DF.formatDecimal(0.12345, 4).equals("0.1235"));
66+
4267
assert(DF.formatDecimal(-0.999999f, -4).equals("-1.000E+0"));
4368
assert(DF.formatDecimal(9.999999f, -4).equals("1.000E+1"));
4469
assert(DF.formatDecimal(9.999999f, 4).equals("10.0000"));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package test;
2+
3+
public class Test_Error extends Test_{
4+
5+
public static void main(String[] args) {
6+
7+
new Test_Error().testError();
8+
9+
try {
10+
//throw new NullPointerException("testing NPE");
11+
/**
12+
* @j2sNative asdlj()
13+
*/
14+
} catch (Throwable e) {
15+
e.printStackTrace();
16+
}
17+
System.out.println("Test_Error OK");
18+
}
19+
20+
private void testError() {
21+
Error x;
22+
x = new LinkageError("test");
23+
x.printStackTrace();
24+
x = new Error("test");
25+
x.printStackTrace();
26+
}
27+
}

sources/net.sf.j2s.java.core/src/test/Test_Inner.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public String getString() {
3535
return "Test_Inner";
3636
}
3737

38-
class Test_Abstract_a extends Test_ {
38+
public class Test_Abstract_a extends Test_ {
3939

40-
void testing() {
40+
public void testing() {
4141
System.out.println("this is " + a);
4242
assert (a == "a string");
4343
System.out.println(showt2());
@@ -73,17 +73,38 @@ public String showt2() {
7373
}
7474

7575

76+
public void testDollar(Test_Abstract_a abs) {
77+
78+
}
79+
7680
public static void main(String[] args) {
7781
Test_Inner inner = new Test_Inner(6) {};
82+
try {
83+
System.out.println(inner.getClass().getMethod("testDollar", new Class<?>[] {Test_Abstract_a.class}).getName());
84+
} catch (NoSuchMethodException | SecurityException e) {
85+
// TODO Auto-generated catch block
86+
e.printStackTrace();
87+
}
7888
inner.showt2();
7989
new Test_Inner(3) {}.showt2();
8090
System.out.println(inner.t_test);
8191
System.out.println("new Test_Inner(){}.t_test=" + new Test_Inner(7) {}.t_test);
8292
Test_Abstract_a abs = inner.new Test_Abstract_a();
83-
System.out.println(new Test_Abstract_a[] {abs}.getClass().getName());
84-
abs.testing();
93+
String s = abs.getClass().getName();
94+
String s1 = new Test_Abstract_a[] {abs}.getClass().getName();
95+
System.out.print("checking inner$");
96+
assert(s.equals("test.Test_Inner$Test_Abstract_a"));
97+
assert(s1.equals("[Ltest.Test_Inner$Test_Abstract_a;"));
98+
System.out.println(" ok");
8599
new Test_Inner(8) {}.new Test_Abstract_a().testing();
86100

101+
try {
102+
System.out.println(abs.getClass().getMethod("testing", new Class<?>[] {}).getName());
103+
} catch (NoSuchMethodException | SecurityException e) {
104+
// TODO Auto-generated catch block
105+
e.printStackTrace();
106+
}
107+
87108

88109
System.out.println("Test_Inner OK");
89110
}

0 commit comments

Comments
 (0)