Magazine
 
Tips ‘n’ Tricks
 

if (lastIndexOfPeriod >=1 && lastIndexOfSlash >= 0 &&
lastIndexOfSlash < fileAddress.length()
-1 1)
{
FileDownload(fileAddress,fileName,
destinationDir);
}
else
{
System.err.println(“Specify correct path or file name.”);
}}
public static void main(String[] args)
{

// Check whether there are atleast
two arguments.

if(args.length==2)
{
for (int i = 1; i < args.length; i++) {
fileDownload(args[i],args[0]);
}
}
else{System.err.println(“Provide
\”Destination directory path\” and \”file
names\” separated by space.”);
}
}
}

Compile and Run:

In this example, the location for the
directory where file “jsf.htm” is to be
saved is “c:\download”.

C:\JavaJazzup>javac FileDataDownload.java
C:\JavaJazzup>java FileDataDownload
c:\download http://localhost:8080/
tomahawk_tags/pages/jsf.htm

 

Output:



2. Using Swing Timer:
A Swing Timer fires an event after a
specified delay of time. Swing Timer can be used to perform a task once, after a delay and to perform a task repeatedly. For example, determining when to display and hide a tool tip, updating a component that displays the progress. Swing timers are very easy to use. Create actionPerformed() method, which is called when action listener is notified. So write the code for the task to be performed, in actionPerformed() method. When creating timer by instantiating the Timer class, we specify the time in milliseconds which is the time interval of invoking the ctionPerformed() each time. To start the timer, just call its start() method and to stop it doing anything, call stop() method. To understand how the swing timer can be used with the progress bar component showing its status is given below:


SwingTimer.java:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.html.*;
public class SwingTimer{
final static int interval = 1000;
int i;
JLabel label;
JProgressBar pb;
Timer timer;
JButton button;
public SwingTimer() {
JFrame frame = new JFrame(“Swing Timer
Example”);
button = new JButton(“Start”);
button.addActionListener(new
ButtonListener());

Sept 2007 | Java Jazz Up | 66
previous
index
next
 
Pages: 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,   Download PDF