-
Notifications
You must be signed in to change notification settings - Fork 0
/
Documentation
563 lines (518 loc) · 25.8 KB
/
Documentation
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
Lecture 1: JFrame
Lecture 2: JLabel
Lecture 3: JTextField
Lecture 4: JPasswordField
Lecture 5: JButton
Lecture 6_1: JButton Event
Lecture 6_2: JButton Event
Lecture 6_3: Event Handling Using anonymous inner class
Lecture 6_4: Event handling using other Class
Lecture 7: JTextArea
Lecture 8: JRadioButton
Lecture 9: JCheckBox
Lecture 10: JComboBox
Lecture 11: JAR Files
Lecture 12: JMenuBar
Lecture 13: Event Listeners
Lecture 14: Listeners
Lecture 15: ItemListener: ItemListener is a Listener that listens ItemEvent.
Lecture 16: keyListener
Lecture 17: MouseListener
Lecture 18: MouseMotionListener
Lecture 19: FocusListener
Lecture 20: CaretListener
Lecture 21: WindowListener
Lecture 22 : Layout Managers
Lecture 23 : Practice of NullLayout
Lecture 24 : Practice of BorderLayout
Lecture 25 : Practice of FlowLayout
Lecture 26 : Practice of gridlayout
Lecture 27 : Practice for Gridbaglayout
Lecture 28 : JPanel
Lecture 29 : Card layout
Lecture 30 : Box Layout:
Lecture 31 : Advance Components
Lecture 32 : JOptionPane
Lecture 33 : JScrollPane
Lecture 34 : JTabbedPane
Lecture 35 : JTable: is used to display the data into tabular form (rows and columns)
Lecture 36 : JProgressBar: is used to display the progress of some specified task.
Lecture 37 : JPopupMenu
Lecture 38 : JCheckBoxMenuItem
Lecture 39 : JSeparator
Lecture 40 : JSplitPane
Lecture 41 : JSpinner
Lecture 42 : JToolTip
Lecture 43 : JSlider
Lecture 44 : JInternalFrame
Lecture 45 : JDesktopPane
Lecture 46 : JEditorPane
Lecture 47 : JToggleButton
Lecture 48 : JDialog
Lecture 48++ : Calling other frame from one
Lecture 49 : JWindow
Lecture 50 : JToolBar
Lecture 51 : JList
Lecture 52 : JTextPane
Lecture 53 : JRootPane
Lecture 54 : JLayeredPane
Lecture 55 : GlassPane
Lecture 56 : JColorChooser
Lecture 57 : JComponent
Lecture 58 : JTree
Lecture 59 : JViewPoint
Lecture 60 : JApplet
Lecture 61 : JFileChooser
Lecture 62 : Look and feel
Lecture 63 : Graphics Animation 1
Lecture 64 : Graphics Animation 2
Lecture 65 : Graphics Animation 3
Lecture 66 : Graphics Animation 4
Practice 1 : Login Form
Practice 2 : Simple Calculator
Practice 3 : Registration Form
Practice 4 : How to create NotePad Application
Practice 5 : Brick Breaker
Practice 6 : Complete Snake Game
Practice 7 : Chat Application
Lecture 1: JFrame
setVisible()
setDefaultCloseOperation()
setSize()
setLocation()
setBounds()
setIconImage()
setTitle()
setBackground()
setResizable()
Lecture 2: JLabel
setText()
setFont()
How to use Image in JLabel
Hot to use both Image and Text in JLabel
Lecture 3: JtextField
setText()
setFont()
setBackground()
setForeground()
setEditable()
Lecture 4: JPasswordField
setEchoChar()
How to hide/show Password
Lecture 5: JButton
How to create
setFont()
setText()
setForeground()
setBackground()
setCursor()
setEnabled()
setVisible()
How to use Image in Button
Lecture 6_1: JButton Event
ActionListener
void actionPerformed()
ddActionListener()
Lecture 6_2: JButton Event
Multiple Buttons Event
handling
getSource()
Lecture 6_3: Event Handling Using anonymous inner class
Lecture 6_4: Event handling using other Class
Steps to follow WhileEvent handling:
step1: implement ActionListener interface
class Myframe implements ActionListener{
public void actionPerformed(ActionEvent e){}
}
class Main{
psvm(String {} args){
Myframe f = new Myframe();
}
}
Step2: override method public void actonPerformed(ActionEvent e){}
class Main{
psmv(String [] args){
button.addActionListener(new Red()){
}
}
static class Red implements ActionListener{
public void actionPerformed(ActionEvent e){}
}
}
Step3: bind the ActionListener to component by using addActionListener() method
class Main{
psvm(String [] args){
button.addActionListener(new ActionListener()){
public void actionPerformedActionEvent e){
}
}
}
}
Lecture 7: JTextArea
how to create JTextArea
setText(String)
setFont(Font)
setEditable(boolean)
setLineWrap(boolean)
Lecture 8: JRadioButton
setFont()
setEnabled()
ButtonGroup()
how to create already selected radio button
setSelected(boolean)
Lecture 9: JCheckBox
setFont()
setEnabled()
setSelected()
Lecture 10: JComboBox
setEditable()
setSelectedIndex(index)
setSelectedItem(String)
setFont()
getSelectedIndex()
getSelectedItem()
addItem()
Lecture 11: JAR Files
Why jar files?
How to create jar files?
1. Jar files are the executable files that can be run by double clicking on it.
2. A developer should not provide source code to its client/other so when he create a software
he profile an executable file to its client so that they can run it easily.
Lecture 12: JMenuBar
parts of a menubar
1.MenuBar
2.menus
3.menuItems
How to create a menubar in JFrame
Lecture 13: Event Listeners
>Listeners : Anything that listens something is called a Listener.
>Events: An Event is the Change in the state of a component.
>Event Listeners: An Event Listener is a Listener that listens an Event.
>Event Handling: To handle the events is called Handling. To handle an event we need an Event Listener
and Handling those events is called Event.
Different types of Event Listeners:
ActionListener (ActionEvent)
ItemListener (ItemEvent)
KeyListener (KeyEvent)
MouseListener (MouseEvent)
MouseMotionListener (MouseMotionEvent)
WindowListener (WindowEvent)
FocusListener (FocusEvent)
CaretListener (CaretEvent)
Lecture 14: Listeners
A Listener is an interface in Java, that listens some event generated by component.
ActionEvent fires on
When user
>click on a button
>press Enter in a TextField
>choose a menuItem.
How to write an ActionListener
>ActionListener interface
>void actionPerformed()
>addActonListener()
class Example implements ActionListener{
public Example(){ component.addActionListener(this);}
public void actionPerformed(ActionEvent e){}
}
Lecture 15: ItemListener: ItemListener is a Listener that listens ItemEvent.
ItemEvent fires on:
>Any item is selected in a combobox
> checkbox is clicked
> radiobutton is clicked
> choose a JCheckBoxMenuItem
ItemListener
How to write Item Listener
>ItemListener
>void itemStateChanged()
>addItemListener()
Lecture 16: keyListener
How to write KeyListener
>KeyListener
>void keyPressed()
>void keyTyped()
>void keyReleased()
>void keyListener()
Lecture 17: MouseListener
how to write MouseListener
>MouseListener
>void mouseClicked(MouseEvent e)
>void mousePressed(MouseEvent e)
>mouseReleased(MouseEvent e)
>void mouseEntered(MouseEvent e)
>void mouseExited(MouseEvent e)
>addMouseListener()
Lecture 18: MouseMotionListener
How to write MouseMotionListener
>MouseMotionListener
>void mouseMoved()
>void mouseDragged()
>addMouseMotionListener()
Lecture 19: FocusListener
How to write FocusListener
>FocusListener
>void focusGained()
>void focusLost()
>addFocusListener()
Lecture 20: CaretListener
>caretListener
>void caretUpdated()
>addCaretListener()
Lecture 21: WindowListener
How to write WindowListener
>public void windowOpened(WindowEvent e)
>public void windowClosing(WindowEvent e)
>public void windowClosed(WindowEvent e)
>public void windowIconified(WindowEvent e)
>public void windowDeiconified(WindowEvent e)
>public void windowActivated(WindowEvent e)
>public void windowDeactivated(WindowEvent e)
>addWindowListener()
Lecture 22 : Layout Managers
Layout: the arrangement of the components inside a container is called Layout.
>NullLayout
>BorderLayout
>FlowLayout
>GridLayout
>GridBagLayout
>CardLayout
>GroupLayout
>BoxLayout
Lecture 23 : Practice of NullLayout
Lecture 24 : Practice of BorderLayout
Lecture 25 : Practice of FlowLayout
How to use FlowLayout
>Set alignment in flowLayout
>setVgap() and setHgap()
>indexing in FlowLayout
Properties:
1.Flow Layout is the default Layout for JPanel
2.Its sets the components its preferred size in java.
3.It also sets the width of the component acc. to its content
4.If width of Jframe is less than it shifts the extra components to the next row.
5.If width of JFrame is more than it aligns the components to the center.
Lecture 26 : Practice of gridlayout
properties:
>Just like Flow Layout, Grid Layout also sets the components left to right in a flow
>In grid Layout all the available space is consumed by the components.
>Grid Layout can be divided into the form of rows and columns.
> in grid layout the all components have the same size.
Lecture 27 : Practice for Gridbaglayout
Lecture 28 : JPanel
Components:
1.Light weight components
>that can be added to some other components,
eg: JButton and JRadioButton etc
2.Heavy weight components
>that cannot be added to any other component.
eg: JDialog and JFrame...
Lecture 29 : Card layout
>A CardLayout object is a layout manager for a container.
>It treats each component in the container as a card.
>Only one card is visible at a time,and the container acts as a stack of cards.
>the first component added to a CardLayout object is the visible component
when the container is first displayed.
>cardLayout has some useful methods to flip the cards.
important methods:
>first()
>last()
>next()
>previous()
>show()
Lecture 30 : Box Layout:
>A BoxLayout arranges the components in a single row or a single column.
>Only one constructor is used by BoxLayout:
BoxLayout(Container target , int axis)
>Four different axes could be chosen:
-Y_AXIS
-X_AXIS
-LINE_AXIS
-PAGE_AXIS
>BoxLayout is same as FlowLayout but with more features
Lecture 31 : Advance Components
>JProgressBar
>JSpinner
>JCheckBoxMenuItem
>JOptionPane
>JScrollPane
>JTabbedPane
>JTable
>JFileChooser
>JColorChooser
Lecture 32 : JOptionPane
>Show an Input
Str = JOpyionPane.showInputDialog("Enter your name")
>Show a Message Dialog
JOptionPane.showMessageDialog( parent,message,title,messageType );
types of Messages:
JOptionPane.PLAIN_MESSAGE
JOptionPane.INFORMATION_MESSAGE
JOptionPane.QUESTION_MESSAGE
JOptionPane.ERROR_MESSAGE
JOptionPane.WARNING_MESSAGE
>Show a Confirm Dialog
JOptionPane.showConfirmDialog( Parent, message, title, optionType, messageType );
Lecture 33 : JScrollPane
Lecture 34 : JTabbedPane
Lecture 35 : JTable: is used to display the data into tabular form (rows and columns)
JTable table =new JTable(data,columnName);
>There are many ways to create a table in Java(i.e. Constructor)
>two popular ways to create a table are:
1. JTable(data , columnNames);
2. JTable(tableModel);
Steps:
rowData[][] = {{a1,a2},{b1,b2},...,{n1,n2}};
columnNames[] = {col_q.col_2,...,col_n};
DefaultTableMode tableMode = new DefaultTableModel(rowData , columnNames );
JTable table = new JTable(tableModel);
Lecture 36 : JProgressBar: is used to display the progress of some specified task.
: show the percentage of completion of specified task.
>the progress bar fills up as the task reaches its completion.
>In addition to show the percentage of completion of task, it can also display some text.
-JProgressBar(): creates an progress bar with no text on it
-JProgressBar(int orientation): creates an progress bar with a specified orientation.
>SwingConstants.VERTICAL
>SwingConstants.HORIZONTAL
-JProgressBar(int min , int max): creates an progress bar with specified minimum and maximum value
-JProgressBar(int orientation , int min , int max)
Commonly used methods of JProgressBar are:
>void setMaximum(int n): set the progress bar's maximum value to the value n.
>void setMinimum(int n): set the progress bar's minimum value to the value n.
>void setValue(int n): set progress bar's current value to the value n.
>void setString(String s): set the value of progress String to the String s.
>void setStringPainted(boolean b): decides whether string should be displayed or not in progressbar
Lecture 37 : JPopupMenu
Lecture 38 : JCheckBoxMenuItem
Lecture 39 : JSeparator
is a component that is used to implement divider lines.
it is used to draw a line to separate widgets in a Layout .
it can be horizontal or vertical.
Lecture 40 : JSplitPane
1. JSplitPane is a component that is used to divide a container into two parts.
2. There is a divider line b/w both the parts that can be moved to resize the parts.
3. Both the parts now works as a separate container.
4. JSplitPane can be of two types, vertical and horizontal.
Lecture 41 : JSpinner
1.JSpinner is a single line input field that allows the user to select a number or an object value from an
ordered sequence.
2.the user can manually typr in a legal data into the text field of the spinner.
3.The spinner is something preferred because they don't need a drop down list.
4.Spinner contains a upward and a downward arrow to show the previous and the next element when it is pressed.
Constructors of JSpinner are:
> JSpinner(): creates an empty spinner with initial value set to zero and no constraints.
> JSpinner(SpinnerModel model):
creates a spinner with a specified spinner model passed as argument.
Commonly used methods are:
>SpinnerListModel(List l)
>SpinnerNumberModel(int value, int max, int min, int step)
>setValue(Object o)
>getValue()
>getPreviousValue()
>getNextValue()
Lecture 42 : JToolTip
is a message that appears when a cursor is positioned over an icon, image, hyperlink or other element in a GUI.
Lecture 43 : JSlider
is a implementation of slider that allows the user to select a value by sliding the knob within the bounded value.
Parts of Slider:
>Track
>Knob
>Major Ticks
>Minor Ticks
>Labels
Important Methods are:
>setMinimum(int n)
>setMaximum(int n)
>setOrientation(o)
>setValue(int n)
>setPaintTicks(boolean b)
>setPaintTrack(boolean b)
>setPaintLabels(boolean b)
>setMajorTickSpacing(int n)
>setMinorTickSpacing(int n)
>addChangeListener( ChangeListener l)
Lecture 44 : JInternalFrame
is a light weight component that has all the features of a JFrame.
Lecture 45 : JDesktopPane
> can be used to create "multi-document" application.
>JDesktopPane is a component by which you can add multiple small windows instances to the main window.
Lecture 46 : JEditorPane
is used to create a simple text editor window. It has to methods
>setContentType()
>setText()
Lecture 47 : JToggleButton
Lecture 48 : JDialog
is a used to create dialog boxes in Java.
>it is a heavy component like JFrame, so it can't be added to any container.
>like JFrame, JDialog also contains the border layout as the default layout manager.
>It is like JFrame but the main difference is that It is always used as a child Window.
>JDialog doesn't contain maximize and minimize buttons like JFrame.
>JDialog usually are created with JOptionPane static methods.
Lecture 49 : JWindow
> is also a Top Level Container like JFrame but the major difference is that JWindow does not have the titleBar and
window management buttons like maximize button, minimize button and close button.
> it can be displayed anywhere on user's desktop.
Lecture 50 : JToolBar
is a group of commonly used components such as buttons with icons or dropdown menus.
Lecture 51 : JList
is a component that display a set of Objects and allows the user to select one or more items.
> JList is an easy way to display an array of Vectors
> Constructor for JList are:
JList(): creates an empty blank list
JList(Object[] items): creates an new list with the elements of array.
JList(Vector v): creates an new list with the elements of vector.
JList(ListModel m): creates an new list with the specified List Model.
Lecture 52 : JTextPane
Lecture 53 : JRootPane
is a light weight container used behind the scenes by JFrame, JDialog, JWindow, JApplet and JInternalFrame
parts of Root Pane:
>Content Pane
>Optional menubar
>Layered Pane
>Glass Pane
Lecture 54 : JLayeredPane
is used to add depth to swing container.
> it is used to provide a third dimension for positioning the component.
> it allow components to overlap each other when needed.
> An integer object specify each component's depth in the container.
> The Higher numbered component display "on top" of other components.
>JLayeredPane divides the depth range into several different layers.
1. FRAME_CONTENT_LAYER(-30000)
2. DEFAULT_LAYER(0)
3. PALETTE_LAYER(100)
4. MODEL_LAYER(200)
5. POPUP_LAYER(300)
6. DRAG_LAYER(400)
> How to sdd components
LayeredPane.add(component, LayeredPane.DEFAULT_LAYER);
OR
LayeredPane.add(component, new Integer(10));
Lecture 55 : GlassPane
is a container that seems like a glass showing at the top of content pane.
>it is transparent and hidden by default.
>the glass pane is useful when you want to be able to catch events or paint over an area that already contains one or more
components
>For example, you can deactivate mouse events for a multi component region by having the glass pane intercept the events.
or you can display an image over multiple components using the glass pane.
Lecture 56 : JColorChooser
Lecture 57 : JComponent
Lecture 58 : JTree
is a swing component that is used to display a hierarchical data into a tree form.
> A tree is made of nodes.
> The node from which tree starts is called root node.
> The node having sub-nodes is called parent.
> The node having its parent is called child node.
> The node having no child is called leaf-node.
> The node at the same hierarchical level and having same parent is called siblings.
Lecture 59 : JViewPoint
lecture 60 : JApplet
Lecture 61 : JFileChooser
is a very component that id used t show a system dialog to the user so that user can choose a file or a directory.
Lecture 62 : Look and feel
"lOOK" refers to the appearance of GUI widgets and "FEEL" refers to the way the widget behave
try{
UIManager.setLookAndFeel(String lookAndFeelClassName);
}catch (Exception e){}
Different types of Themes of Java
1. MetalLookAndFeel-- "javax.swing.plaf.metal.MetalLookAndFeel"
2. NimbusLookAndFeel-- "javax.swing.plaf.nimbus.NimbusLookAndFeel"
3. MotifLookAndFeel-- "javax.swing.plaf.motif.MotifLookAndFeel"
4. WindowsClassicLookAndFeel-- "javax.swing.plaf.windows.WindowsClassicLookAndFeel""