-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowLayoutRonald.java
More file actions
275 lines (267 loc) · 9.37 KB
/
Copy pathFlowLayoutRonald.java
File metadata and controls
275 lines (267 loc) · 9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/* The "FlowLayoutRonald" class provides an example of the FlowLayout layout manager; it demonstrates
* the various fields and methods featured in this layout. FlowLayout organizes components in a flowing manner; it orients
* components on a line and wraps around once no more components fit.
*
* @author Ronald Perlas
* @author Jeffry Lien
* @version 1.0 February 21 2014
*/
public class FlowLayoutRonald extends JPanel
{
/*
* returnField Reference References the JTextField class and creates a new text field which is
* used to output data from get() methods to the user.
*/
JTextField returnField = new JTextField (50);
/*
* f Reference References the FlowLayout class and makes its methods and features accessible.
*/
FlowLayout f;
/*
* This constructor is responsible for executing the flowFunction() method and outputting
* all the relevant buttons and layouts on the JPanel.
*/
public FlowLayoutRonald ()
{
flowFunction();
}
/*
* This method contains the commands to create every component that appears on the JPanel as
* well as integrates the methods of the FlowLayout class.
*
* @param centerButton Reference References the "Center" JButton.
* @param leftButton Reference References the "Left" JButton.
* @param rightButton Reference References the "Right" JButton.
* @param leadButton Reference References the "Leading" JButton.
* @param trailButton Reference References the "Trailing" JButton.
* @param getAlignButton Reference References the "getAlignment()" JButton.
* @param getHgapButton Reference References the "getHgap()" JButton.
* @param incHgapButton Reference References the "setHgap()+" JButton.
* @param decHgapButton Reference References the "setHgap()-" JButton.
* @param getVgapButton Reference References the "getVgap()" JButton.
* @param incVgapButton Reference References the "setVgap()+" JButton.
* @param decVgapButton Reference References the "setVgap()-" JButton.
* @param setBaseAlign Reference References the "setAlignOnBaseline()" JButton.
* @param getBaseAlign Reference References the "getAlignOnBaseline()" JButton.
* @param preferredButton Reference References the "preferredLayoutSize()" JButton.
* @param minimumButton Reference References the "minimumLayoutSize()" JButton.
* @param layoutButton Reference References the "layoutContainer()+" JButton.
* @param stringButton Reference References the "toString()-" JButton.
* @param ae ActionEvent Stores the action command.
*/
public void flowFunction ()
{
// Button creation and initialization.
JButton centerButton = new JButton ("Center");
JButton leftButton = new JButton ("Left");
JButton rightButton = new JButton ("Right");
JButton leadButton = new JButton ("Leading");
JButton trailButton = new JButton ("Trailing");
JButton getAlignButton = new JButton ("getAlignment()");
JButton getHgapButton = new JButton ("getHgap()");
JButton incHgapButton = new JButton ("setHgap()+");
JButton decHgapButton = new JButton ("setHgap()-");
JButton getVgapButton = new JButton ("getVgap()");
JButton incVgapButton = new JButton ("setVgap()+");
JButton decVgapButton = new JButton ("setVgap()-");
JButton setBaseAlign = new JButton ("setAlignmentOnBaseline() Toggle");
JButton getBaseAlign = new JButton ("getAlignmentOnBaseline()");
JButton preferredButton = new JButton ("preferredLayoutSize()");
JButton minimumButton = new JButton ("minimumLayoutSize()");
JButton layoutButton = new JButton ("layoutContainer()");
JButton stringButton = new JButton ("toString()");
// Sets layout.
f = new FlowLayout ();
setLayout (f);
// Adding to JPanel.
add (returnField);
add (leadButton);
add (leftButton);
add (centerButton);
add (rightButton);
add (trailButton);
add (getAlignButton);
add (getHgapButton);
add (incHgapButton);
add (decHgapButton);
add (getVgapButton);
add (incVgapButton);
add (decVgapButton);
add (setBaseAlign);
add (getBaseAlign);
add (preferredButton);
add (minimumButton);
add (layoutButton);
add (stringButton);
// CENTER Field
centerButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
f.setAlignment (FlowLayout.CENTER);
revalidate();
}
});
// LEFT Field
leftButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
f.setAlignment (FlowLayout.LEFT);
revalidate();
}
});
// LEADING Field
leadButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
f.setAlignment (FlowLayout.LEADING);
revalidate();
}
});
// RIGHT Field
rightButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
f.setAlignment (FlowLayout.RIGHT);
revalidate();
}
});
// TRAILING Field
trailButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
f.setAlignment (FlowLayout.TRAILING);
revalidate();
}
});
// getAlignment() Method
getAlignButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
returnField.setText ("Alignment: " + f.getAlignment ());
}
});
// getHgap() Method
getHgapButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
returnField.setText ("Horizontal Gap: " + f.getHgap ());
}
});
// setHgap() Method
incHgapButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
setVisible (false);
f.setHgap (f.getHgap() + 1);
setVisible (true);
}
});
// setHgap() Method
decHgapButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
setVisible (false);
f.setHgap (f.getHgap() - 1);
setVisible (true);
}
});
// getVgap() Method
getVgapButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
returnField.setText ("Vertical Gap: " + f.getVgap());
}
});
// setVgap() Method
incVgapButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
setVisible (false);
f.setVgap (f.getVgap() + 1);
setVisible (true);
}
});
// setVgap() Method
decVgapButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
setVisible (false);
f.setVgap (f.getVgap() - 1);
setVisible (true);
}
});
// getBaseAlignment() Method
getBaseAlign.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
returnField.setText ("Base Alignment: " + f.getAlignOnBaseline ());
}
});
// setBaseAlignment() Method
setBaseAlign.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
setVisible (false);
if (f.getAlignOnBaseline() == false)
f.setAlignOnBaseline (true);
else
f.setAlignOnBaseline (false);
setVisible (true);
}
});
// preferredLayoutSize() Method
preferredButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
Dimension d = f.preferredLayoutSize(FlowLayoutRonald.this);
returnField.setText ("Preferred Layout Size: " + d.getWidth() + "x" + d.getHeight());
}
});
// minimumLayoutSize() Method
minimumButton.addActionListener(new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
Dimension d = f.minimumLayoutSize (FlowLayoutRonald.this);
returnField.setText ("Minimum Layout Size: " + d.getWidth() + " x " + d.getHeight ());
}
});
// layoutContainer() Method
layoutButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
Container c = new Container ();
f.layoutContainer (c);
}
});
// toString() Method
stringButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
returnField.setText ("String Rep: " + f.toString());
}
});
returnField.setText ("Requested Data: ");
setVisible (true);
}
}