Tuesday, 9 May 2017

Creating Progress Bar Using JProgressBar

Creating Progress Bar Using JProgressBar:

In this tutorial you will learning how to create Progressbar using JProgressBar for java application that is basically swings application.

A progress bar is basically a widget(an application, or a component of an interface, that enables a user to perform a function or can help to access a service) that displays progress of a lengthy task, usually used for downloading a or transfer some files. For creating a progress bar in swings you have to use the JProgressBar class. With the help of JProgressBar, you can easily create vertical or horizontal progress bar according to your need. In addition to the JProgressBar class,it allows you to create another kind of progress bar which is known as indeterminate progress bar. The indeterminate progress bar is used to display progress with unknown progress or the progress cannot express by the percentage.Basically it does not explain about how the progress is remain in terms of percentage.

There are some constructors used to create ProgressBar. These are:

1. public JProgressBar()- It creates a Horizontal progress bar.
2. public JProgressBar(int orientation)- It helps in creating horizontal as well as vertical progress bar. You can also create progress bar in any orientation.
3. public JProgressBar(int minimum,int maximum)- It help in creating progress bar which is having minimum values and maximum values.

4. public JProgressBar(int orientation,int minimum,int maximum)- It helps in creating progress bar in any orientation with defined minimum and maximum values.


Syntax for creating for progress bar is:
JProgressBar p=new JProgressBar();


Advantages of ProgressBar:-

1.The progress bar serves a dual purpose when you want to keep your respondents engaged with your survey.You want your respondents must stick to your survey.Suppose when a user searches for a particular result, sometimes it displays some survey to fill after that your request will be processed.Sometimes it shows that the survey is almost 90% completed,and you are almost there to complete the survey and near to your search result.Then the user will be willing to complete the survey.
2.The progress bar helps to display the work completion of your project. It tells us that how much your project remain to finish. How much efforts are remaining to complete the project.

Disadvantages of ProgressBar:-

1.Survey Unbalanced questions: The progress bar is effective only when it is accurate and balanced.The progress bar leads to ineffective during survey when there is unbalanced question in each page.Suppose there is 4 questions in one page and there is 7 questions in next page.The progress bar acts according to the questions including per page.So that leads to loosing interest of respondents during survey.
2.Improper Logic: There must be proper logic behind each page.Suppose the respondents do not want to answer a particular question during survey. If he skips it, suppose the progress bar moves from 30% to 92%, that does not lead to sense.

Example of working of ProgressBar:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
public class prog extends JFrame
{
int i;
JLabel l1=new JLabel();
JProgressBar p=new JProgressBar();

public prog()
{
this.setLayout(null);
this.setSize(1000,1000);
this.setVisible(true);
l1.setBounds(100,400,100,60);
add(l1);
p.setBounds(100,100,300,40);
add(p);
for(i=0;i<=100;i++)
{
p.setValue(i);
l1.setText("LOADING"+i+"%");
if(i>99)
{
JOptionPane.showMessageDialog(null,"PROGRESS DONE");
}
try
{
Thread.sleep(20);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"go away");
}
}
}
public static void main(String[] args)
{
new prog();
}
}

Oracle / PLSQL: FOR LOOP

set serveroutput on; declare a1 varchar2(100); begin select count(*) into a1 from employees; for i in 1..a1 loop dbms_output.put_line...