Skip to content

Commit da4ad9a

Browse files
hansonrhansonr
authored andcommitted
test files
1 parent 27a78e7 commit da4ad9a

File tree

6 files changed

+576
-241
lines changed

6 files changed

+576
-241
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@
18391839
* @since 1.5
18401840
*/
18411841
@SuppressWarnings({"rawtypes", "unchecked", "unused"})
1842-
public final class Formatter implements Flushable {
1842+
public class Formatter implements Flushable {
18431843
Appendable a;
18441844
private Locale l;
18451845

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

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
import java.awt.event.ActionListener;
1313
import java.awt.event.ItemEvent;
1414
import java.awt.event.ItemListener;
15+
import java.awt.event.KeyEvent;
16+
import java.awt.event.KeyListener;
1517
import java.awt.event.MouseEvent;
1618
import java.awt.event.MouseListener;
1719

1820
import javax.swing.ImageIcon;
1921
import javax.swing.JButton;
2022
import javax.swing.JCheckBox;
2123
import javax.swing.JCheckBoxMenuItem;
24+
import javax.swing.JDesktopPane;
2225
import javax.swing.JFrame;
26+
import javax.swing.JInternalFrame;
2327
import javax.swing.JLabel;
2428
import javax.swing.JMenu;
2529
import javax.swing.JMenuBar;
@@ -48,6 +52,11 @@ public static void main(String[] args) {
4852
private JMenuItem mb5;
4953
private JMenuItem testbtn;
5054

55+
JMenuBar mb = new JMenuBar();
56+
JFrame frame = new JFrame();
57+
58+
JMenu mRight = new JMenu("right");
59+
5160
ActionListener listener = new ActionListener() {
5261

5362
@Override
@@ -61,21 +70,41 @@ public void actionPerformed(ActionEvent e) {
6170
* Put some content in a JFrame and show it
6271
*/
6372
void doTest() {
64-
JFrame main = new JFrame();
65-
main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
73+
74+
// JInternalFrame main = new JInternalFrame();
75+
76+
frame.addKeyListener(new KeyListener() {
77+
78+
@Override
79+
public void keyTyped(KeyEvent e) {
80+
System.out.println(e);
81+
}
82+
83+
@Override
84+
public void keyPressed(KeyEvent e) {
85+
System.out.println(e);
86+
}
87+
88+
@Override
89+
public void keyReleased(KeyEvent e) {
90+
System.out.println(e);
91+
}
92+
93+
});
94+
95+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
6696

6797
JMenu menu = new JMenu("testing");
6898
JMenu menu1 = new JMenu("testing1");
6999
JMenu menu2 = new JMenu("testing2");
70-
71100
menu.setHorizontalAlignment(SwingConstants.RIGHT);
72-
main.setJMenuBar(new JMenuBar());
73-
main.getJMenuBar().add(menu);
74-
main.setContentPane(getVisualPaneContent(menu, menu1, menu2));
75-
main.getJMenuBar().add(menu1);
76-
main.getJMenuBar().add(menu2);
77-
main.pack();
78-
main.setVisible(true);
101+
102+
frame.setJMenuBar(mb);
103+
mb.add(menu);
104+
mb.add(menu1);
105+
mb.add(menu2);
106+
frame.setContentPane(getVisualPaneContent(menu, menu1, menu2));
107+
frame.pack();
79108

80109
JPopupMenu pmenu = new JPopupMenu();
81110
JMenuItem b = new JMenuItem("testing1");
@@ -88,7 +117,7 @@ void doTest() {
88117
b.addActionListener(listener);
89118
pmenu.add(b);
90119

91-
main.addMouseListener(new MouseListener() {
120+
frame.addMouseListener(new MouseListener() {
92121

93122
@Override
94123
public void mouseClicked(MouseEvent e) {
@@ -97,7 +126,7 @@ public void mouseClicked(MouseEvent e) {
97126
int n = pmenu.getComponentCount();
98127
if (n > 1)
99128
pmenu.remove(n - 1);
100-
pmenu.show(main, 100, 100);
129+
pmenu.show(frame, 100, 100);
101130
// TODO Auto-generated method stub
102131

103132
}
@@ -127,6 +156,18 @@ public void mouseExited(MouseEvent e) {
127156
}
128157

129158
});
159+
160+
frame.setVisible(true);
161+
162+
// JDesktopPane d = new JDesktopPane();
163+
// d.setPreferredSize(new Dimension(600,300));
164+
// d.add(main);
165+
// JFrame top = new JFrame();
166+
// top.setContentPane(d);
167+
// top.setBounds(100,100, 600, 600);
168+
// top.pack();
169+
// top.setVisible(true);
170+
130171
}
131172

132173
/**
@@ -148,7 +189,6 @@ Container getVisualPaneContent(JMenu menu, JMenu menu1, JMenu menu2) {
148189
firstColumn.setLayout(new GridLayout(13, 1));
149190
firstColumn.setBorder(new TitledBorder("column 1"));
150191

151-
152192
JLabel l1 = new JLabel(getImage("test2.png"));
153193
l1.setText("trailing right");
154194
l1.setHorizontalTextPosition(SwingConstants.TRAILING);
@@ -301,34 +341,42 @@ public void actionPerformed(ActionEvent e) {
301341
btn.setFont(font);
302342
menu.add(btn);
303343
testbtn = new JMenuItem("testing");
304-
testbtn.setFont(font);
344+
testbtn.setFont(font);
345+
testbtn.addActionListener(new ActionListener() {
346+
347+
@Override
348+
public void actionPerformed(ActionEvent e) {
349+
System.out.println("You pressed button " + ((JMenuItem)e.getSource()).getText());
350+
}
351+
352+
});
305353
menu.add(testbtn);
306354

307-
JMenu m2 = new JMenu("right");
308-
menu.add(m2);
309-
m2.setFont(font);
310-
m2.addMenuListener(this);
311-
m2.add(cb6m);
312-
m2.add(rb1m);
355+
menu.add(mRight);
356+
mRight.setFont(font);
357+
mRight.addMenuListener(this);
358+
mRight.add(cb6m);
359+
mRight.add(rb1m);
313360
btn = new JMenuItem("-");
314361
btn.setFont(font);
315-
m2.add(btn);
316-
m2.add(rb3m);
362+
mRight.add(btn);
363+
mRight.add(rb3m);
317364
btn = new JMenuItem("-");
318365
btn.setFont(font);
319-
m2.add(btn);
320-
m2.add(mb3);
321-
m2.add(mb4);
366+
mRight.add(btn);
367+
mRight.add(mb3);
368+
mRight.add(mb4);
322369

323370
JPanel theTab = new JPanel();
324371

325-
firstColumn.add(new JButton("remove 'testbtn'") {
372+
firstColumn.add(new JButton("<html>remove <i>testbtn</i></html>") {
326373
{
327374
this.addActionListener(new ActionListener() {
328375

329376
@Override
330377
public void actionPerformed(ActionEvent e) {
331378
menu.remove(testbtn);
379+
System.out.println("removing testbtn");
332380
}
333381

334382
});
@@ -340,14 +388,28 @@ public void actionPerformed(ActionEvent e) {
340388

341389
@Override
342390
public void actionPerformed(ActionEvent e) {
343-
testbtn.setText("testbtn");
391+
testbtn.setText("test" + ++ntest);
344392
menu.add(testbtn);
345393

346394
}
347395

348396
});
349397
}
350398
});
399+
firstColumn.add(new JButton("menu bar add 'right'") {
400+
{
401+
this.addActionListener(new ActionListener() {
402+
403+
@Override
404+
public void actionPerformed(ActionEvent e) {
405+
mb.add(mRight);
406+
mb.invalidate();
407+
frame.pack();
408+
}
409+
410+
});
411+
}
412+
});
351413
theTab.setLayout(null);
352414
theTab.setBackground(Color.white);
353415
theTab.add(firstColumn);
@@ -356,6 +418,8 @@ public void actionPerformed(ActionEvent e) {
356418
return panel;
357419
}
358420

421+
int ntest = 0;
422+
359423
private ImageIcon getImage(String name) {
360424
ImageIcon icon = new ImageIcon(getClass().getResource(name));
361425

@@ -367,12 +431,13 @@ private ImageIcon getImage(String name) {
367431
return icon;
368432
}
369433

370-
371434
@Override
372435
public void menuSelected(MenuEvent e) {
373436
System.out.println("menuSelected " + e.getSource().toString());
374437
JMenu menu = (JMenu) e.getSource();
438+
System.out.println("adding mb5");
375439
menu.add(mb5);
440+
System.out.println("mb5 added");
376441
}
377442

378443
@Override

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.BorderLayout;
44
import java.awt.Color;
55
import java.awt.Container;
6+
import java.awt.GridLayout;
67
import java.awt.event.ActionEvent;
78
import java.awt.event.ActionListener;
89
import java.beans.PropertyChangeEvent;
@@ -83,32 +84,45 @@ public void onDialogReturn(int value) {
8384
public void onDialogReturn(Object value) {
8485
if (value instanceof UIResource)
8586
return;
86-
System.out.println("object value is " + value);
87+
status.setText(value.toString());
8788
}
8889

90+
JLabel status;
8991

9092

9193
public Test_Dialog() {
9294
super();
9395
this.setTitle("testing dialogs");
94-
Container contentPane = this.getContentPane();
95-
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
96+
97+
JPanel m = new JPanel(new GridLayout());
98+
status = new JLabel("testing");
99+
m.add(status, null);
100+
add(m,BorderLayout.SOUTH);
101+
102+
103+
JPanel p = new JPanel();
104+
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
105+
add(p, BorderLayout.CENTER);
96106
this.setLocation(300, 300);
97107
JButton b;
98108

109+
99110
b = new JButton("ConfirmDialog");
100111
final JPanel content = new JPanel();
101112
content.setLayout(new BorderLayout());
102113
content.add(new JLabel("this is the option panel"), BorderLayout.CENTER);
103114
b.addActionListener(new ActionListener() {
104115
@Override
105116
public void actionPerformed(ActionEvent e) {
106-
Test_Dialog.this.onDialogReturn(JOptionPane.showConfirmDialog(Test_Dialog.this, "OK"/* content */,
117+
Test_Dialog.this.onDialogReturn(JOptionPane.showConfirmDialog(
118+
Test_Dialog.this,
119+
"The frame is now " + (isResizable() ? "NOT " : "") + "resizable.",
107120
"Testing JOptionPane", JOptionPane.OK_CANCEL_OPTION));
121+
setResizable(!isResizable());
108122
}
109123

110124
});
111-
this.add(b);
125+
p.add(b);
112126

113127
b = new JButton("MessageDialog");
114128
final JPanel message = new JPanel();
@@ -122,7 +136,7 @@ public void actionPerformed(ActionEvent e) {
122136
}
123137

124138
});
125-
this.add(b);
139+
p.add(b);
126140

127141
b = new JButton("InputDialog");
128142
final JPanel input = new JPanel();
@@ -136,7 +150,7 @@ public void actionPerformed(ActionEvent e) {
136150
}
137151

138152
});
139-
this.add(b);
153+
p.add(b);
140154

141155

142156

@@ -150,7 +164,7 @@ public void actionPerformed(ActionEvent e) {
150164
}
151165

152166
});
153-
this.add(b);
167+
p.add(b);
154168

155169
b = new JButton("ColorDialog");
156170
b.addActionListener(new ActionListener() {
@@ -164,9 +178,10 @@ public void actionPerformed(ActionEvent e) {
164178
}
165179

166180
});
167-
this.add(b);
168-
this.pack();
169-
this.setVisible(true);
181+
p.add(b);
182+
183+
pack();
184+
setVisible(true);
170185

171186
}
172187

0 commit comments

Comments
 (0)