Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Government Polytechnic Aurangabad

Department Of Computer Engineering

-With Mr. G.U.Jadhav


Lecturer in Computer Engineering
import javax.swing.*

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Differentiate between AWT and Swing on the given aspect
2. Develop GUI programs using SWING component for the given problem.
3. Use the given types of Button in java based GUI
4. Develop GUI programs using advanced swing components for the given
problem

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Light Weight
2. Rich Controls
3. Highly customizable
4. Pluggable look and
feel
5. ToolTip
6. Platform independent

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Swing API architecture follows loosely based MVC architecture ..
1. Model represents component's data
2. View represents visual representation of the component's data.
3. Controller takes the input from the user on the view and reflects the changes in
Component's data.
4. Swing component has Model as a seperate element, while the View and Controller part
are clubbed in the User Interface elements. Because of which, Swing has a pluggable
look-and-feel architecture.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Mr. Gajanan Jadhav
Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Swing has two types of controls
a. Passive Controls
b. Active Controls
2. We will learns following AWT controls

• JLabel
• JButton
• JCheckbox
• JCheckboxGroup These classes are subclasses of
• JChoice JComponent Class
• JList
• JScrollbar
• JTextField
• JTextArea

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. JLabel()
2. JLabel(Icon image)
3. JLabel(Icon image, int how)
4. JLabel(String text,Icon image, int how)
5. JLabel(String labeltext)
6. JLabel(String str, int how)

Where how is—

JLabel.LEFT
JLabel.RIGHT
JLabel.CENTER

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void setText(String str)

2. String getText( )

3. void setHorizontalAlignment(int how)

4. int getHorizontalAlignment( )

5. Icon getIcon()

6. Void setIcon( Icon i);


Methods

1. Void setText( String s)

2. String getText()

3. void setDisabledIcon(Icon di)

4. void setPressedIcon(Icon pi)

5. void setSelectedIcon(Icon si)

6. void setRolloverIcon(Icon ri)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Push Button
with label
Submit
Constructor

1. JButton (Icon i)

2. JButton (String s)

3. JButton( String s , Icon i)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Checkbox
with label
Constructor c++ , Java
1. JCheckbox(Icon i )

2. Jcheckbox( Icon I, boolean state)

3. JCheckbox(String str)

4. JCheckbox(String str, boolean state)

5. JCheckbox(String str, Icon i)

6. JCheckbox( String str, Icon I, boolean state)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void setSelected(boolean state)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. JRadioButton(Icon i)

2. JRadioButton(Icon i, boolean state)

3. JRadioButton(String s)

4. JRadioButton(String s, boolean state)

5. JRadioButton(String s, Icon i)

6. JRadioButton(String s, Icon i, boolean state)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Adding radio button to ButtonGroup
ButtonGroup b= new ButtonGroup()

Void add( AbstractButton ab)

Ex: b.add( r1);


Constructor
1. JComboBox( )

2. JComboBox(Vector v)

3. JComboBox(Object obj[])

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void addItem(Object obj)

2. public void setEditable(boolean aFlag)

3. public boolean isEditable()

4. public void setMaximumRowCount(int count)

5. public void setSelectedItem(Object anObject)

6. public void insertItemAt(Object anObject, int index)

7. public void removeItem(Object anObject)

8. public void removeItemAt(int anIndex)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
JComponent

Constructor J

1. JTextField( )
J J
2. JTextField(int cols)

3. JTextField(String s, int cols)

4. JTextField(String s))

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor

1. JTextArea()
2. JTextArea(String text)
3. JTextArea(int rows , int cols)
4. JTextArea ( String txt, int rows,int cols)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. JTabbedPane()

1. JTabbedPane( int tabPlacement)

2. JTabbedPane( int tabPlacement, int tabLayoutPolicy)

Where tabplacement: where tablayoutpolicy


1. JTabbedPane.TOP 1. JTabbedPane.WRAP_TAB_LAYOUT
2. JTabbedPane.BOTTOM 2. JTabbedPane.SCROLL_TAB_LAYOUT
3. JTabbedPane.LEFT
4. JTabbedPane.RIGHT

Tabs are defined via the following method:


void addTab(String str, Component comp)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructors
1. JScrollPane()

2. JScrollPane(Component comp)

3. JScrollPane(int vsb, int hsb)

4. JScrollPane(Component comp, int vsb, int hsb)

Where vsb
1. ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
2. ScrollPaneConstants. VERTICAL_SCROLLBAR_AS_NEEDED
Where hsb
1. ScrollPaneConstants. HORIZONTAL_SCROLLBAR_ALWAYS
2. ScrollPaneConstants.
HORIZONTAL_SCROLLBAR_AS_NEEDED

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructors
1. JTable(Object data[ ][ ], Object colHeads[ ])

2. JTable(int numRows, int numColumns)

3. JTable(Vector rowData, Vector columnData)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructors
1. JTree( Hashtable ht)

2. JTree( Object obj[ ])

3. JTree( TreeNode tn)

4. JTree( Vector v)

-A JTree object generates events when a node is expanded or collapsed.

- void addTreeExpansionListener( TreeExpansionListener tel)


- void removeTreeExpansionListener( TreeExpansionListener tel)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
TreePath getPathForLocation(int x, int y)

The return value is a TreePath object that encapsulates information about


the tree node that was selected by the user.

The TreeNode interface declares methods that obtain information about a


tree node. For example, it is possible to obtain a reference to the parent
node or an enumeration of the child nodes. The MutableTreeNode interface
extends TreeNode. It declares methods that can insert and remove child
nodes or change the parent node.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor:

DefaultMutableTreeNode(Object obj)

Method to add Node :

void add(MutableTreeNode child)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor:
1. JPasswordField()

2. JPasswordField( int columns)

3. JPasswordField(String text)

4. JPasswordField(String text, int columns)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
You can create a tool tip for any JComponent with setToolTipText( String
text) method. This method is used to set up a tool tip for the component.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad

You might also like