Skip to content

Commit ce2702a

Browse files
hansonrhansonr
authored andcommitted
tests
1 parent e59b691 commit ce2702a

File tree

8 files changed

+269
-211
lines changed

8 files changed

+269
-211
lines changed
185 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/javax/swing/JDialog.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,18 @@
3333
import java.awt.Container;
3434
import java.awt.Dialog;
3535
import java.awt.Frame;
36-
import java.awt.JSDialog;
37-
import java.awt.JSFrame;
3836
import java.awt.Graphics;
3937
import java.awt.GraphicsConfiguration;
4038
import java.awt.HeadlessException;
39+
import java.awt.JSDialog;
40+
import java.awt.JSFrame;
4141
import java.awt.LayoutManager;
4242
import java.awt.Window;
4343
import java.awt.event.WindowEvent;
4444
import java.awt.event.WindowListener;
4545

4646
import javax.swing.plaf.UIResource;
4747

48-
import swingjs.JSUtil;
49-
import swingjs.plaf.JSComponentUI;
50-
5148
// BH: Added rootPane.addNotify(); // builds a peer for the root pane
5249

5350
/**

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

Lines changed: 101 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@
4141
public class TApp2 extends Applet {
4242

4343
TextArea ta;
44-
45-
private void addButtonTest() {
46-
for (int i = 0; i < 4; i++) {
47-
for (int j = 0; j < 4; j++) {
48-
Button b = new Button("XyX");
49-
Label l = new Label("XyX", Label.CENTER);
50-
setLBBounds((Component) b, (Component) l, i, j);
51-
}
52-
}
44+
45+
private void addButtonTest() {
46+
for (int i = 0; i < 4; i++) {
47+
for (int j = 0; j < 4; j++) {
48+
Button b = new Button("XyX");
49+
Label l = new Label("XyX", Label.CENTER);
50+
setLBBounds((Component) b, (Component) l, i, j);
51+
}
52+
}
5353
}
5454

55-
private void setLBBounds(Component b, Component l, int i, int j) {
55+
private void setLBBounds(Component b, Component l, int i, int j) {
5656
int x = 40 + i * 170;
5757
int y = 350 + j * 40;
5858
int w = 70 + i * 10;
@@ -61,19 +61,21 @@ private void setLBBounds(Component b, Component l, int i, int j) {
6161
l.setBounds(x + 105, y, w - 30, h);
6262
b.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10 + i * 3));
6363
l.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10 + i * 3));
64-
l.setBackground(Color.cyan);
64+
l.setBackground(Color.cyan);
6565
add(b);
6666
add(l);
6767
}
6868

69+
long t;
70+
6971
public void init() {
7072
setSize(800, 600);
7173
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
7274
setBackground(Color.yellow);
7375
setLayout(null);
74-
76+
7577
addButtonTest();
76-
78+
7779
JPanel panel = new JPanel();
7880
panel.setBounds(10, 10, 100, 150);
7981
add(panel);
@@ -94,7 +96,7 @@ public void focusGained(FocusEvent e) {
9496
public void focusLost(FocusEvent e) {
9597
System.out.println("tf " + e.paramString());
9698
}
97-
99+
98100
});
99101
panel.add(tf);
100102
// Label label = new Label("blue", Label.RIGHT);
@@ -111,9 +113,11 @@ public void focusLost(FocusEvent e) {
111113
//
112114
// // the scrolling to the bottom is only with TextArea, not JTextArea
113115
// and then only if the append is AFTER the add
114-
ta = new TextArea("A text\nwith some\nlines and\n no content.");
116+
ta = new TextArea("Averyveryveryveryveryveryveryverylongword\n" + "Averyveryveryveryveryveryveryverylongword\n"
117+
+ "Averyveryveryveryveryveryveryverylongword\n" + "Averyveryveryveryveryveryveryverylongword\n"
118+
+ "A text\nwith some\nlines and\n no content.", 40, 40, TextArea.SCROLLBARS_VERTICAL_ONLY);
115119
add(ta);
116-
ta.setBounds(200, 70, 200,200);
120+
ta.setBounds(200, 70, 200, 200);
117121
ta.setFont(new Font(Font.DIALOG, Font.BOLD, 20));
118122
ta.appendText("A text\nwith some\nlines and\n no content.");
119123
ta.addFocusListener(new FocusListener() {
@@ -127,79 +131,113 @@ public void focusGained(FocusEvent e) {
127131
public void focusLost(FocusEvent e) {
128132
System.out.println("ta " + e.paramString());
129133
}
130-
134+
131135
});
132136

133-
134137
// TextArea ta = new TextArea("A text\nwith some\nlines and\n no content.");
135138
// JScrollPane sp = new JScrollPane(ta);
136139
// sp.setBounds(200, 70, 100, 80);
137140
// add(sp);
138141

139-
140-
// ta.getSelectionEnd();
142+
// ta.getSelectionEnd();
141143
ta.setBackground(Color.red);
142144
Scrollbar sb = new Scrollbar(0, 30, 0, 0, 100);
143145
sb.setBounds(300, 20, 100, 20);
144146
add(sb);
147+
sb.setBackground(Color.white); // can be set after!
145148
sb.addAdjustmentListener(new AdjustmentListener() {
146149

147150
@Override
148151
public void adjustmentValueChanged(AdjustmentEvent e) {
149-
System.out.println("TApp2 sb value " + e.getValue());
152+
long time = System.currentTimeMillis();
153+
System.out.println("TApp2 sb value " + e.getValue() + " " + (time - t));
154+
t = time;
150155
}
151-
156+
152157
});
153158

154-
sb.setBackground(Color.blue);
155159
sb.setForeground(Color.red);
160+
161+
162+
163+
addMouseListener(new MouseListener() {
164+
165+
@Override
166+
public void mouseClicked(MouseEvent e) {
167+
System.out.println(">>>>mouseClicked: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e);
168+
}
169+
170+
@Override
171+
public void mouseEntered(MouseEvent e) {
172+
// TODO Auto-generated method stub
173+
174+
}
175+
176+
@Override
177+
public void mouseExited(MouseEvent e) {
178+
// TODO Auto-generated method stub
179+
180+
}
181+
182+
@Override
183+
public void mousePressed(MouseEvent e) {
184+
System.out.println(">>>>mousePressed: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e);
185+
}
186+
187+
@Override
188+
public void mouseReleased(MouseEvent e) {
189+
System.out.println(">>>>mouseReleased: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e);
190+
}
191+
192+
});
193+
156194
new TestGraphic(this).testGraphic();
157195
}
158-
159-
static class TestGraphic{
160-
private TApp2 tApp2;
161196

162-
public TestGraphic(TApp2 tApp2) {
163-
this.tApp2 = tApp2;
197+
static class TestGraphic {
198+
private TApp2 tApp2;
199+
200+
public TestGraphic(TApp2 tApp2) {
201+
this.tApp2 = tApp2;
164202
}
165203

166-
static {
167-
ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
168-
}
204+
static {
205+
ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
206+
}
169207

170-
void testGraphic() {
171-
Button b = new Button("g");
172-
b.setBounds(300,300,40,20);
173-
// images are created only when a button is displayable
174-
Image i1 = b.createImage(100, 100);
175-
System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1);
176-
assert(i1 == null);
177-
tApp2.add(b);
178-
i1 = b.createImage(100, 100);
179-
System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1);
180-
b.setFont(new Font(Font.SERIF, Font.BOLD, 10));
181-
Graphics g = i1.getGraphics();
182-
Font f = g.getFont();
183-
System.out.println(f);
184-
185-
// font/background/foreground are set when the graphic is created
186-
Font f0 = new Font(Font.DIALOG, Font.PLAIN, 30);
187-
b.setFont(f0);
188-
b.setBackground(Color.red);
189-
b.setForeground(Color.green);
190-
g = i1.getGraphics();
191-
b.setFont(new Font(Font.SERIF, Font.BOLD, 10));
192-
b.setBackground(Color.white);
193-
b.setForeground(Color.black);
194-
System.out.println("img font=" + g.getFont());
195-
System.out.println("img bg=" + ((Graphics2D) g).getBackground());
196-
System.out.println("img fg=" + g.getColor());
197-
assert(g.getFont().equals(f0));
198-
assert(g.getColor() == Color.green);
199-
assert(((Graphics2D) g).getBackground() == Color.red);
200-
System.out.println("Tapp2 OK");
208+
void testGraphic() {
209+
Button b = new Button("g");
210+
b.setBounds(300, 300, 40, 20);
211+
// images are created only when a button is displayable
212+
Image i1 = b.createImage(100, 100);
213+
System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1);
214+
assert (i1 == null);
215+
tApp2.add(b);
216+
i1 = b.createImage(100, 100);
217+
System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1);
218+
b.setFont(new Font(Font.SERIF, Font.BOLD, 10));
219+
Graphics g = i1.getGraphics();
220+
Font f = g.getFont();
221+
System.out.println(f);
222+
223+
// font/background/foreground are set when the graphic is created
224+
Font f0 = new Font(Font.DIALOG, Font.PLAIN, 30);
225+
b.setFont(f0);
226+
b.setBackground(Color.red);
227+
b.setForeground(Color.green);
228+
g = i1.getGraphics();
229+
b.setFont(new Font(Font.SERIF, Font.BOLD, 10));
230+
b.setBackground(Color.white);
231+
b.setForeground(Color.black);
232+
System.out.println("img font=" + g.getFont());
233+
System.out.println("img bg=" + ((Graphics2D) g).getBackground());
234+
System.out.println("img fg=" + g.getColor());
235+
assert (g.getFont().equals(f0));
236+
assert (g.getColor() == Color.green);
237+
assert (((Graphics2D) g).getBackground() == Color.red);
238+
System.out.println("Tapp2 OK");
239+
}
201240
}
202-
}
203241

204242
public void paint(Graphics g) {
205243
super.paint(g);
@@ -257,39 +295,6 @@ public void paint(Graphics g) {
257295
// g.drawString("SwingJS", 200, 30);
258296
// g.setColor(Color.white);
259297
// g.drawString("SwingJS", 200, 30);
260-
261-
262-
addMouseListener(new MouseListener() {
263-
264-
@Override
265-
public void mouseClicked(MouseEvent e) {
266-
System.out.println(">>>>mouseClicked: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e);
267-
}
268-
269-
@Override
270-
public void mouseEntered(MouseEvent e) {
271-
// TODO Auto-generated method stub
272-
273-
}
274-
275-
@Override
276-
public void mouseExited(MouseEvent e) {
277-
// TODO Auto-generated method stub
278-
279-
}
280-
281-
@Override
282-
public void mousePressed(MouseEvent e) {
283-
System.out.println(">>>>mousePressed: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e);
284-
}
285-
286-
@Override
287-
public void mouseReleased(MouseEvent e) {
288-
System.out.println(">>>>mouseReleased: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e);
289-
}
290-
291-
});
292298

293299
}
294300
}
295-

0 commit comments

Comments
 (0)