0% found this document useful (0 votes)
31 views53 pages

AJP Unit 2 Swing

Swing is a GUI widget toolkit for Java, part of Oracle's Java Foundation Classes, providing a more sophisticated set of components than AWT. It is platform-independent, lightweight, and follows the MVC architecture, allowing for easy customization and management of GUI elements. Key components include JFrame, JApplet, JButton, JTextField, and JCheckBox, each with specific constructors and methods for creating interactive applications.

Uploaded by

patilaayush00069
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views53 pages

AJP Unit 2 Swing

Swing is a GUI widget toolkit for Java, part of Oracle's Java Foundation Classes, providing a more sophisticated set of components than AWT. It is platform-independent, lightweight, and follows the MVC architecture, allowing for easy customization and management of GUI elements. Key components include JFrame, JApplet, JButton, JTextField, and JCheckBox, each with specific constructors and methods for creating interactive applications.

Uploaded by

patilaayush00069
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Unit II

Swing
Marks :10 Marks
Created By: Prof.P.M.Takate
Introduction to Swing
 Swing is a GUI widget toolkit for java.
 It is part of Oracle’s Java Foundation Classes –an API for
providing a Graphical User Interface(GUI) for Java programs.
 Swing was developed to provide more sophisticated set of GUI
components than the earlier Abstract Windowing ToolKit(AWT).
 Swing has more powerful and flexible components than AWT.
 In addition to familiar components such as buttons,checkboxes
and labels.Swing provides several advanced components such
as tabbed panel,scroll panes,trees,tables and so on.
 Swing is an extension to the AWT components which provides
feature of pluggable look and feel for the components.
Fig.AWT and Swing Classes
Swing Features
 1. Platform Independent: It is platform independent, the swing
components that are used to build the program are not platform
specific. It can be used at any platform and anywhere.
 2. Lightweight: Swing components are lightweight which helps in
creating the UI lighter. Swings component allows it to plug into the
operating system user interface framework that includes the
mappings for screens or device and other user interactions like key
press and mouse movements.
 3. Plugging: It has a powerful component that can be extended to
provide the support for the user interface that helps in good look and
feel to the application. Its components are imported through a
package called java. swing.
 4. Manageable: It is easy to manage and configure. Its mechanism
and composition pattern allows changing the settings at run time as
well. The uniform changes can be provided to the user interface
without doing any changes to application code.
 5. MVC: They mainly follows the concept of MVC that is Model
View Controller. With the help of this, we can do the changes
in one component without impacting or touching other
components. It is known as loosely coupled architecture as
well.
 6.Highly Customizable − Swing controls can be customized
in a very easy way as visual appearance is independent of
internal representation.
MVC Architecture

Fig.MVC Architecture
 Model represents component's data.
 View represents visual representation of the
component's data.
 Controller takes the input from the user on the view and
reflects the changes in Component's data.
 Swing component has Model as a separate 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.
Difference between AWT and Swing
No. Java AWT Java Swing
1) AWT components are platform- Java swing components
dependent. are platform-independent.

2) AWT components are heavyweight. Swing components are lightweight.

3) AWT doesn't support pluggable look Swing supports pluggable look


and feel. and feel.

4) AWT provides less components than Swing provides more powerful


Swing. components such as tables,
scrollpanes, tabbedpane etc.

5) AWT doesn't follows MVC(Model View Swing follows MVC.


Controller) where model represents data,
view represents presentation and
controller acts as an interface between
model and view.
Working With Swing

Fig.Swing Application Window


 In Swing the main window, also called top level container is
root of a hierarchy,which contains all the other Swing
components that appear inside the window.
 Every top level container has one intermediate container
called content pane.
 This content pane contains all the visible components in GUI
window.
 Just like AWT application, a Swing application requires top level
container.
 There are three top level containers in Swing :
1.JFrame :Used for application main window.
2.JDialog :Used for secondary pop-up window.
3.JApplet :Used for applet display area inside browser’s window.
Swing Components :JApplet
 JApplet is a class that represents the swing applet.
 It is a subclass of Applet class and must be extended by all the
applets that use Swing.
 Whenever we require to add a component to it.The component is
added to the content pane.
 JApplet supports various panes such as root pane,glass pane and
content pane.
Example
import javax.swing.JApplet;
Output:
import java.awt.*;
/*<applet code=“JAppletDemo.class” width=250 height=250>
</applet> */
public class JAppletDemo extends JApplet
{
public void paint ( Graphics g )
{
g.drawString(“Welcome”,100,100);
}
}
JFrame
 The frame is a top level container or window,on which other swing
components are placed.
 Contructors :

SR Constructor Description
No
1 JFrame() It constructs a new frame that is initially
invisible.

2 JFrame(String title) It creates a new, initially invisible Frame


with the specified title.
Program
import javax.swing.*; SE);
Import java.awt.*; f.setVisible(true);
public class JFrameExample { }
public static void main(String args[]) { }
JFrame f = new JFrame("JFrame Example"); Output :

f.setLayout(new FlowLayout());

JLabel label = new JLabel("JFrame By Example");


JButton button = new JButton(“Button”);
f.add(label);
f.add(button);
f.setSize(200, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLO
ImageIcon
 Icons are encapsulated by the ImageIcon class in swing.
 It paints an icon from an image.
 Constructors :

SR.NO Constructor Description

1 ImageIcon(String Creates an ImageIcon from the specified


filename) file.

2 ImageIcon(URL Creates an ImageIcon from the specified


location) URL.
Program
import java.awt.*; Output:
import javax.swing.*;
public class ImageIconDemo extends JApplet
{
public void init()
{
ImageIcon i= new ImageIcon("j1.png");
JButton B1= new JButton( “Butterfly",i);
add(B1);
}
}
/*
<applet code=“ImageIconDemo" width=150 height=150>
</applet>
*/
JLabel
 A JLabel object is a component for placing text in a container.
 This class used to create single read only text which describes the
other component.
 Labels can display text as well as Images
 Constructors :

SR.NO Constructor Description

1 JLabel() Creates a JLabel instance with no image and


with an empty string for the title.

2 JLabel(String s) Creates a JLabel instance with the specified


text.
3 JLabel(Icon i) Creates a JLabel instance with the specified
image.
 Methods :

SR. Methods Description


No

1 String getText() It returns the text string that a label


displays.
2 void setText(String text) It defines the single line of text this
component will display.
3 void setHorizontalAlignment(int It sets the alignment of the label's
alignment) contents along the X axis.
4 Icon getIcon() It returns the graphic image that the
label displays.
5 void setIcon(Icon i) It sets the image to Label.

6 int getHorizontalAlignment() It returns the alignment of the label's


contents along the X axis.
Program
import javax.swing.*; Output:
class LabelExample
{
public static void main(String args[])
{
JFrame f= new JFrame("Label Example");
JLabel l1,l2;
l1=new JLabel("First Label.");
l1.setBounds(50,50, 100,30);
l2=new JLabel("Second Label.");
l2.setBounds(50,100, 100,30);
f.add(l1); f.add(l2);
f.setSize(300,300);
f.setVisible(true);
}
}
JButton
 The JButton class is used to create a labeled button that has platform
independent implementation. The application result in some action
when the button is pushed. It inherits AbstractButton class.
 Constructors :

Sr.No. Constructor & Description

JButton()
1
Creates a button with no set text or icon.
JButton(Icon icon)
2
Creates a button with an icon.
JButton(String text)
3
Creates a button with the text.
JButton(String text, Icon icon)
4
Creates a button with an initial text and an icon.
 Methods :

SR.NO Methods Description

1 void setText(String s) It is used to set specified text on button

2 String getText() It is used to return the text of the button.

3 void setEnabled(boolean b) It is used to enable or disable the button.

4 void setIcon(Icon i) It is used to set the specified Icon on the


button.

5 Icon getIcon() It is used to get the Icon of the button.


Program
import javax.swing.*; Output :
public class ButtonExample {
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 :

SR. Constructor Description


No
1 JTextField() Creates a new TextField
2 JTextField(String text) Creates a new TextField initialized with
the specified text.
3 JTextField(String text, int Creates a new TextField initialized with
columns) the specified text and columns.
4 JTextField(int columns) Creates a new empty TextField with the
specified number of columns.
Program
import javax.swing.*; Output :
class TextFieldExample
{
public static void main(String args[])
{
JFrame f= new JFrame("TextField Example");
JTextField t1,t2;
t1=new JTextField("Welcome to Javatpoint.");
t1.setBounds(50,100, 200,30);
t2=new JTextField(“AWT Tutorial");
t2.setBounds(50,150, 200,30);
f.add(t1); f.add(t2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
JTextArea
 The object of a JTextArea class is a multi line region that displays text.
It allows the editing of multiple line text. It inherits JTextComponent
class.
 Constructors :
SR. Constructor Description
NO
1 JTextArea() Creates a text area that displays no
text initially.
2 JTextArea(String s) Creates a text area that displays
specified text initially.
3 JTextArea(int row, int column) Creates a text area with the
specified number of rows and
columns that displays no text
initially.
4 JTextArea(String s, int row, int Creates a text area with the
column) specified number of rows and
columns that displays specified text.
Program
import javax.swing.*; Output:
public class TextAreaExample
{
TextAreaExample(){
JFrame f= new JFrame();
JTextArea area=new JTextArea("Welcome to javatpoint");
area.setBounds(10,30, 200,200);
f.add(area);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new TextAreaExample();
}}
JComboBox
 The class JComboBox is a component which combines a button or
editable field and a drop-down list.
 Constructors :

SR.NO Constructor Description


1 JComboBox() Creates a JComboBox with a
default data model.
2 JComboBox(Object[] items) Creates a JComboBox that
contains the elements in the
specified array.
 Methods :
Program
import javax.swing.*; Output :
public class ComboBoxExample {
JFrame f;
ComboBoxExample(){
f=new JFrame("ComboBox Example");
String country[]={"India","Aus","U.S.A","England","Newzealand"};
JComboBox cb=new JComboBox(country);
cb.setBounds(50, 50,90,20);
f.add(cb);
f.setLayout(null);
f.setSize(400,500);
f.setVisible(true);
}
public static void main(String[] args) {
new ComboBoxExample();
}
}
JCheckbox
 The JCheckBox class is used to create a checkbox. It is used to turn an
option on (true) or off (false). Clicking on a CheckBox changes its
state from "on" to "off" or from "off" to "on ".It inherits JToggleButton
class.
 Constructors :
SR.NO Constructor Description

1 JCheckBox() Creates an initially unselected check box button


with no text, no icon.
2 JChechBox(String s) Creates an initially unselected check box with text.

3 JCheckBox(String text, Creates a check box with text and specifies


boolean selected) whether or not it is initially selected.

4 JCheckBox(Icon icon) Creates an initially unselected checkbox with an


icon.
5 JCheckBox(Icon icon, boolean Creates a checkbox with an icon and specifies
selected) whether or not it is initially selected.

6 JCheckBox(String text, Icon Creates an initially unselected checkbox with the


icon) specified text and icon.

7 JCheckBox(String text, Icon Creates a checkbox with text and icon, and
 Program : Output:
import javax.swing.*;
public class CheckBoxExample
{
CheckBoxExample(){
JFrame f= new JFrame("CheckBox Example");
JCheckBox checkBox1 = new JCheckBox("C++");
checkBox1.setBounds(100,100, 50,50);
JCheckBox checkBox2 = new JCheckBox("Java", true);
checkBox2.setBounds(100,150, 50,50);
f.add(checkBox1);
f.add(checkBox2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new CheckBoxExample();
JRadioButton
 The JRadioButton class is used to create a radio button. It is used to
choose one option from multiple options. It is widely used in exam
systems or quiz.
 Constructors :
SR.NO Constructor Description

1 JRadioButton() Creates an unselected radio button with no text.


2 JRadioButton(String s) Creates an unselected radio button with specified
text.
3 JRadioButton(String s, Creates a radio button with the specified text and
boolean selected) selected status.
4 JRadioButton(Icon icon) Creates an initially unselected radio button with
the specified image but no text
5 JRadioButton(Icon icon, Creates a radio button with the specified image
boolean selected) and selection state, but no text
6 JRadioButton(String text, Creates a radio button that has the specified text
Icon icon) and image, and which is initially unselected.
7 JRadioButton(String text, Creates a radio button that has the specified
Icon icon, boolean text, image, and selection state.
selected)
 Methods :

SR.NO Methods Description

1 void setText(String s) It is used to set specified text on


button.
2 String getText() It is used to return the text of
the button.
3 void setEnabled(boolean b) It is used to enable or disable
the button.
4 void setIcon(Icon b) It is used to set the specified
Icon on the button.
5 Icon getIcon() It is used to get the Icon of the
button.
 Program : Output:
import javax.swing.*;
public class RadioButtonExample {
JFrame f;
RadioButtonExample(){
f=new JFrame();
JRadioButton r1=new JRadioButton("A) Male");
JRadioButton r2=new JRadioButton("B) Female");
r1.setBounds(75,50,100,30);
r2.setBounds(75,100,100,30);
ButtonGroup bg=new ButtonGroup();
bg.add(r1);bg.add(r2);
f.add(r1);f.add(r2);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new RadioButtonExample();
}
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 :

SR.No Constructor Description

1 JPasswordField() Constructs a new JPasswordField, with a default


document, null starting text string, and 0 column
width.

2 JPasswordField(int columns) Constructs a new empty JPasswordField with the


specified number of columns.

3 JPasswordField(String text) Constructs a new JPasswordField initialized with the


specified text.
4 JPasswordField(String text, int Construct a new JPasswordField initialized with the
columns) specified text and columns.
 Program :
Output :
import javax.swing.*;
public class PasswordFieldExample {
public static void main(String[] args) {
JFrame f=new JFrame("Password Field Example");
JPasswordField value = new JPasswordField();
JLabel l1=new JLabel("Password:");
l1.setBounds(20,100, 80,30);
value.setBounds(100,100,100,30);
f.add(value); f.add(l1);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
}
Advanced Swing Components: JTabbedPane
 The JTabbedPane class is used to switch between a group of
components by clicking on a tab with a given title or icon. It inherits
JComponent class.
SR. Constructor Description
No
1 JTabbedPane() Creates an empty TabbedPane with a
default tab placement of JTabbedPane.Top.
2 JTabbedPane(int tabPlacement) Creates an empty TabbedPane with a
specified tab placement i,e
JTabbedPane.TOP, JTabbedPane.BOTTOM,
JTabbedPane.LEFT
JTabbedPane.RIGHT
3 JTabbedPane(int tabPlacement, int Creates an empty TabbedPane with a
tabLayoutPolicy) specified tab placement and tab layout
policy i,e JTabbedPane.WRAP_TAB_LAYOUT,
JTabbedPAne.SCROLL_TAB_LAYOUT
 Tabs are added via the following method :
void addTab(String str,Component comp)
Here,str is the title for the tab, and comp is the component that
should be added to the tab.Typically, a JPanel or subclass of it is added.
 The general procedure to use a tabbed pane in an applet as follows :
Step1 : Create a JTabbedPane object.
Step 2: Call addTab() to add a tab to the pane.
Step 3:Repeat step2 for each tab.
Step 4 : Add the tabbed pane to applet/frame.
import javax.swing.*; public SY()
public class JTabbedPaneDemo extends JApplet {
{ JButton b1=new JButton("Abhijeet");
public void init() add(b1);
{ JButton b2=new JButton("Rohit");
JTabbedPane jtp= new JTabbedPane(); add(b2);
jtp.addTab("First Year",new FY()); JButton b3=new JButton("Omkar");
jtp.addTab("Second Year", new SY()); add(b3); } }
jtp.addTab("Third Year", new TY()); class TY extends JPanel
add(jtp); }} {
class FY extends JPanel public TY()
{ {
public FY() JComboBox j1=new JComboBox();
{ j1.addItem("Abhijeet");
JLabel l1=new JLabel("Abhijeet"); j1.addItem("Rohit");
add(l1); j1.addItem("Omkar");
JLabel l2=new JLabel("Rohit"); add(j1); } }
add(l2);
JLabel l3=new JLabel("Omkar"); /*<applet code="JTabbedPaneDemo.class"
add(l3); }} width=400 height=400>
class SY extends JPanel </applet>
{ */
JScrollPane
 A JScrollPane is used to make scrollable view of a component. When
screen size is limited, we use a scroll pane to display a large
component or a component whose size can change dynamically.
 Constructors :

SR.NO Constructor Purpose

1 JScrollPane() It creates a scroll pane.


The Component
2 JScrollPane(Component comp) parameter, when
present, sets the scroll
pane's client. The two int
3 JScrollPane(int v, int h) parameters, when
present, set the vertical
4 JScrollPane(Component comp, int v, int and horizontal scroll bar
h) policies (respectively).
 Constants of JScrollPane Class :
1. HORIZONTAL_SCROLLBAR_ALWAYS
2. HORIZONTAL_SCROLLBAR_AS_NEEDED
3. VERTICAL_SCROLLBAR_ALWAYS
4. VERICAL_SCROLLBAR_AS_NEEDED
 Steps to use scrollpane in an applet :
Step 1:Create a JComponent Object.
Step 2:Create JScrollPane Object
Step 3 :Add the scrollpane to the applet.
 Program : }
import javax.swing.*; int v =
import java.awt.*; ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_
NEEDED ;
public class JScrollPane2 extends JApplet
int h =
{
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_A
public void init() S_NEEDED ;
{ JScrollPane jsp = new JScrollPane( jp, v, h ) ;
JPanel jp = new JPanel( ) ; add(jsp) ;
jp.setLayout( new GridLayout( 5,5) ) ; }
char b='A'; }
for(int i=0; i<5; i++) /*
{ <applet code=JScrollPane2.class height=400
for( int j=0; j<5; j++) width=400>
{ </applet>
jp.add(new JButton("Button " + b)); */
++b; Output :
}
JTree
 The JTree class is used to display the tree structured data or
hierarchical data.
 JTree is a complex component.
 It has a 'root node' at the top most which is a parent for all nodes in
the tree. It inherits JComponent class.
 Constructors :

SR. Constructor Description


NO
1 JTree() Creates a JTree with a sample model.
2 JTree(Object[] value) Creates a JTree with every element of the
specified array as the child of a new root
node.
3 JTree(TreeNode root) Creates a JTree with the specified TreeNode
as its root, which displays the root node.
 Methods :
SR.NO Methods Description

1 TreePath getPathForLocation(int x,int y) It is used to translate a mouse click


on a point of tree or tree path.Where
x and y are coordinates of mouse
click.
 DefaultMutableTreeNode Class :
It is used to represent a node in a tree. Using
DefaultMutableTreeNode,you can create nodes for the root and for all of
the data you want to represent in the tree.
 Constructors :
SR. Constructor Description
NO
1 DefaultMutableTreeNode() Creates anode with no associated user
object.
2 DefaultMutableTreeNode Creates a node which you can attach
(Object ob) children.
3 DefaultMutableTreeNode To specify that child nodes cannot be
(Object ob,boolean attached by supplying the third argument
allowschildren) as false.
 Methods :

SR.NO Methods Description

1 void add(MutableTreeNode child) It is used to create tree node


hierarchy.

 Steps to create JTree :


 Step 1 :Create a JTree object.
 Step 2 :Create JScrollPane Object
 Step 3 :Add tree to scroll pane.
 Step 4 :Add scroll pane to frame or applet.
import java.awt.*; DefaultMutableTreeNode("TextArea");
import javax.swing.*; a.add(a4);
import javax.swing.tree.DefaultMutableTreeNode; DefaultMutableTreeNode b=new
public class JTreeDemo1 extends JApplet DefaultMutableTreeNode ("Swing");

{ root.add(b);

public void start() JTree tree=new JTree(root);

{ int
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_
DefaultMutableTreeNode root=new NEEDED;
DefaultMutableTreeNode("Java");
int
DefaultMutableTreeNode a=new h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_A
DefaultMutableTreeNode ("AWT"); S_NEEDED;
root.add(a); JScrollPane jsp=new JScrollPane(tree,v,h);
DefaultMutableTreeNode a1=new add(jsp);
DefaultMutableTreeNode("Label");
}
a.add(a1);
}
DefaultMutableTreeNode a2=new
DefaultMutableTreeNode("Button"); /*

a.add(a2); <applet code=JTreeDemo1.class height=300


width=300>
DefaultMutableTreeNode a3=new
DefaultMutableTreeNode("TextField"); </applet>

a.add(a3); */
JTable
 The JTable class is used to display data in tabular form. It is composed
of rows and columns.
 Constructors :

Sr.No Constructor Description


1 JTable() Creates a table with
empty cells.
2 JTable(Object[][] rows, Object[] Creates a table with
columns) the specified data.

 Steps to Create JTable in applet


Step1 :Create JTable object.
Step 2:Create JScrollPane object.
Step 3:Add the table to the scroll pane.
Step 4 :Add the scroll pane to the applet/frame.
Program : Output :
import javax.swing.*;
public class TableExample {
JFrame f;
TableExample(){
f=new JFrame();
String data[][]={ {"101","Amit","670000"},
{"102","Jai","780000"},
{"101","Sachin","700000"}};
String column[]={"ID","NAME","SALARY"};
JTable jt=new JTable(data,column);
jt.setBounds(30,40,200,300);
JScrollPane sp=new JScrollPane(jt);
f.add(sp);
f.setSize(300,400);
f.setVisible(true);
}
public static void main(String[] args) {
new TableExample();
}
JTooltip
 We can create a tool tip for any JComponent with setToolTipText() method.
 This method is used to set up a tool tip for the component.
 Program: Output :
import javax.swing.*;
public class ToolTipExample {
public static void main(String[] args) {
JFrame f=new JFrame("Password Field Example");
//Creating PasswordField and label
JPasswordField value = new JPasswordField();
value.setBounds(100,100,100,30);
value.setToolTipText("Enter your Password");
JLabel l1=new JLabel("Password:");
l1.setBounds(20,100, 80,30);
//Adding components to frame
f.add(value); f.add(l1);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
JProgressBar
 The JProgressBar class is used to display the progress of the task. It
inherits JComponent class.
 Constructors :

SR. Constructor Description


No

1 JProgressBar() It is used to create a horizontal


progress bar but no string text.
2 JProgressBar(int min, int max) It is used to create a horizontal
progress bar with the specified
minimum and maximum value.
3 JProgressBar(int orient) It is used to create a progress bar with
the specified orientation, it can be
either Vertical or Horizontal by using
SwingConstants.VERTICAL and
SwingConstants.HORIZONTAL
constants.
4 JProgressBar(int orient, int min, int It is used to create a progress bar with
max) the specified orientation, minimum and
maximum value.
 Methods :

SR.No Method Description

1 void setStringPainted(boolean b) It is used to determine whether string


should be displayed.
2 void setString(String s) It is used to set value to the progress
string.
3 void setOrientation(int It is used to set the orientation, it
orientation) may be either vertical or horizontal
by using SwingConstants.VERTICAL
and SwingConstants.HORIZONTAL
constants.
4 void setValue(int value) It is used to set the current value on
the progress bar.
 Program : i=i+20;
import javax.swing.*; try
import java.awt.*; {
public class MyProgress extends JFrame Thread.sleep(50);
{ }
JProgressBar jb,; catch(Exception e){ }
int i=0,num=0; }
public MyProgress() }
{ public static void main(String args[])
jb=new JProgressBar(0,2000); {
jb.setBounds(40,40,200,30); MyProgress m=new MyProgress();
jb.setValue(0); m.setTitle("Progress Bar");
jb.setStringPainted(true); m.setVisible(true);
add(jb); m.iterate();
setSize(400,400); }
} }
public void iterate() /*<applet code="MyProgress.class" height=500
width=500>
{
</applet>
while(i<=2000)
*/
{
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy