66import javax .swing .JFrame ;
77import javax .swing .JLabel ;
88import javax .swing .JPanel ;
9+ import javax .swing .JProgressBar ;
10+ import javax .swing .JTextArea ;
911import javax .swing .JTextField ;
1012import javax .swing .SwingConstants ;
1113
@@ -16,15 +18,15 @@ public final class Components {
1618
1719 private Components () { }
1820
19- static Value newWindow (Value ... args ) {
21+ static Value newWindow (Value [] args ) {
2022 Arguments .checkOrOr (0 , 1 , args .length );
2123 String title = (args .length == 1 ) ? args [0 ].asString () : "" ;
2224 final JFrame frame = new JFrame (title );
2325 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
2426 return new JFrameValue (frame );
2527 }
2628
27- static Value newPanel (Value ... args ) {
29+ static Value newPanel (Value [] args ) {
2830 Arguments .checkOrOr (0 , 1 , args .length );
2931 final JPanel panel = new JPanel ();
3032 if (args .length == 1 ) {
@@ -33,22 +35,57 @@ static Value newPanel(Value... args) {
3335 return new JPanelValue (panel );
3436 }
3537
36- static Value newButton (Value ... args ) {
38+ static Value newButton (Value [] args ) {
3739 Arguments .checkOrOr (0 , 1 , args .length );
3840 String text = (args .length == 1 ) ? args [0 ].asString () : "" ;
3941 return new JButtonValue (new JButton (text ));
4042 }
4143
42- static Value newLabel (Value ... args ) {
44+ static Value newLabel (Value [] args ) {
4345 Arguments .checkRange (0 , 2 , args .length );
4446 String text = (args .length >= 1 ) ? args [0 ].asString () : "" ;
4547 int align = (args .length == 2 ) ? args [1 ].asInt () : SwingConstants .LEADING ;
4648 return new JLabelValue (new JLabel (text , align ));
4749 }
4850
49- static Value newTextField (Value ... args ) {
50- Arguments .checkOrOr (0 , 1 , args .length );
51- String text = (args .length == 1 ) ? args [0 ].asString () : "" ;
52- return new JTextFieldValue (new JTextField (text ));
51+ static Value newTextField (Value [] args ) {
52+ Arguments .checkRange (0 , 2 , args .length );
53+ String text = "" ;
54+ int cols = 0 ;
55+ switch (args .length ) {
56+ case 1 : {
57+ text = args [0 ].asString ();
58+ } break ;
59+ case 2 : {
60+ text = args [0 ].asString ();
61+ cols = args [1 ].asInt ();
62+ } break ;
63+ }
64+ return new JTextFieldValue (new JTextField (text , cols ));
65+ }
66+
67+ static Value newProgressBar (Value [] args ) {
68+ Arguments .checkRange (0 , 3 , args .length );
69+ boolean isVertical = false ;
70+ int min = 0 ;
71+ int max = 100 ;
72+ switch (args .length ) {
73+ case 1 : {
74+ isVertical = args [0 ].asInt () != 0 ;
75+ } break ;
76+ case 2 : {
77+ min = args [0 ].asInt ();
78+ max = args [1 ].asInt ();
79+ } break ;
80+ case 3 : {
81+ isVertical = args [0 ].asInt () != 0 ;
82+ min = args [1 ].asInt ();
83+ max = args [2 ].asInt ();
84+ } break ;
85+ }
86+ return new JProgressBarValue (new JProgressBar (
87+ isVertical ? SwingConstants .VERTICAL : SwingConstants .HORIZONTAL ,
88+ min , max
89+ ));
5390 }
5491}
0 commit comments