Ajp Presentation
Ajp Presentation
Ajp Presentation
College Of Engineering
Subject Teacher :-
Team
prof.S.V.Chitale
Ostwal Isha Lalit
Members :- Puri Sakshi Ramesh
Shinde Suhani Vijay
Gaikwad Snehal Sunil
Components of swing
JButton, JLabel, JTextField, JTextArea, JPasswordField, JCheckBox,
JOptionPane, JRadioButton, JComboBox, Tabbed Panes , JScrollPane,
JMenuBar, JMenu JMenuItem, JTree, JTable, JProgressBar.
JButto
n JButton class is used to create a labeled button that has platform independent
The
implementation. The application result in some action when the button is pushed.
It inherits AbstractButton class.
Constructors:-
JButton() :- It creates a button with no text and icon.
JButton(String s) :- It creates a button with the specified text.
JButton(Icon i) :- It creates a button with the specified icon object.
Methods :
- setText(String s) :- It is used to set specified text on button
void
String getText() :- It is used to return the text of the button.
void setEnabled(boolean b) :- It is used to enable or disable the button.
void setIcon(Icon b) :- It is used to set the specified Icon on the button.
Icon getIcon() :- It is used to get the Icon of the button.
void addActionListener(ActionListener a) :- It is used to add the action listener to this
object.
Java JButton Example :-
import javax.swing.*;
public class ButtonExample1
{
public static void main(String[] args)
{
JFrame f=new JFrame("Button Example");
JButton b=new JButton("Click Here");
b.setBounds(50,100,95,30);
f.add(b);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
JTextField
The object of a JTextField class is a text component that allows
the editing of a single line text. It inherits JTextComponent class.
Constructors :-
JTextField() :- Creates a new TextField
JTextField(String text) :- Creates a new TextField initialized with the specified text.
JTextField(String text, int columns ) :- Creates a new TextField initialized with the
specified text and columns.
JTextField(int columns) :- Creates a new empty TextField with the specified number
of columns.
Methods :-
void addActionListener(ActionListener) :- It is used to add the specified action
listener to
receive action events from this textfield.
Action getAction() It returns the currently set Action for this ActionEvent source,
or null if no Action is set.
Java JTextField Example :-
import javax.swing.*;
class TextFieldExample
{
public static void main(String args[])
{
JFrame f= new JFrame("TextField Example");
JTextField t1,t2;
t1=new JTextField("Welcome to Arrow World.");
t1.setBounds(50,100, 200,30);
t2=new JTextField("Swing Tutorial");
t2.setBounds(50,150, 200,30);
f.add(t1);
f.add(t2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Java JPasswordField
The object of a JPasswordField class is a text component
specialized for password entry. It
allows the editing of a single line of text. It inherits JTextField
class.
Constructors :-
Constructors :-
JScrollPane()
JScrollPane(Component comp)
JScrollPane(int vsb, int hsb) JScrollPane(Component comp, int vsb, int hsb)
HORIZONTAL_SCROLLBAR_ALWAYS
Always provide horizontal scroll bar
HORIZONTAL_SCROLLBAR_AS_NEEDED
Provide horizontal scroll bar, if needed
VERTICAL_SCROLLBAR_ALWAYS
Always provide vertical scroll bar
VERTICAL_SCROLLBAR_AS_NEEDED
Provide vertical scroll bar, if needed
Java JScrollPane Example :-
import javax.swing.*;
import java.awt.*;
public class JScrollPaneDemo
{
public static void main(String[] args)
{
JFrame frame = new JFrame("Scroll
Pane Example");
JPanel jp = new JPanel();
jp.setLayout(new GridLayout(20, 20));
int b = 0;
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 20; j++)
{
jp.add(new JButton("Button " + b));
++b;
}
}
int v =
ScrollPaneConstants.VERTICAL_SCROL
LBAR_AS_NEEDED;
int h =
ScrollPaneConstants.HORIZONTAL_SC
ROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(jp,
v, h);
frame.add(jsp,BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
Java JMenuBar, JMenu and JMenuItem :-
The JMenuBar class is used to display menubar on the window or frame. It may have
several menus.
The object of JMenu class is a pull down menu component which is displayed from
the menubar.
It inherits the JMenuItem class.
The object of JMenuItem class adds a simple labeled menu item.
Constructors :-
JTree() :- Creates a JTree with a sample model.
JTree(Object[] value) :- Creates a JTree with every element of the specified array as
the child of a new root node.
JTree(TreeNode root) :- Creates a JTree with the specified TreeNode as its root,
which displays the root node.
• The DefaultMutableTreeNode class implements the
MutableTreeNode interface.
• It represents a node in a tree. One of its
constructors is shown here:
• DefaultMutableTreeNode(Object obj) :-
vegetables.add(vegetable1);
vegetables.add(vegetable2);
dryFruits.add(dryFruit1);
dryFruits.add(dryFruit2);
JTree tree = new JTree(rootNode);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jf.add(label1);
jf.add(jsp,BorderLayout.CENTER);
jf.setSize(300,200);
jf.setVisible(true);
}
}