Java swing

Java swing

Hi,

I want to copy the file from one directory to another directory,the same time i want to get the particular copying filename will be displayed in the page and progress bar also.

Example,
I have 10 files in the source directory ,i want to copy the first file from source to destination,that time in the panel the progress bar and the first.txt is copying message will be displayed.

Please send the sample code ,its very very urgent.

Thanks,
Valarmathi P
View Answers

October 6, 2010 at 2:57 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.html.*;

public class Copy {
final static int interval = 1000;
int i;
JLabel label;
JProgressBar pb;
Timer timer;
JButton button;

public Copy() {
JFrame frame = new JFrame("Swing Progress Bar");
button = new JButton("Start");
button.addActionListener(new ButtonListener());

pb = new JProgressBar(0, 20);
pb.setValue(0);
pb.setStringPainted(true);

label = new JLabel(" ");
JPanel panel = new JPanel();
panel.add(button);
panel.add(pb);
JPanel panel1 = new JPanel();
panel1.setLayout(new BorderLayout());
panel1.add(panel, BorderLayout.NORTH);
panel1.add(label, BorderLayout.CENTER);
panel1.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
frame.setContentPane(panel1);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

timer = new Timer(interval, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (i == 20) {
Toolkit.getDefaultToolkit().beep();
timer.stop();
button.setEnabled(true);
pb.setValue(0);
String str = "<html>" + "<font color=\"#FF0000\">" + "<b>"
+ "File is copied." + "</b>" + "</font>"
+ "</html>";
label.setText(str);
}
i = i + 5;
pb.setValue(i);
}
});
}

class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
button.setEnabled(false);
i = 0;
String str = "<html>" + "<font color=\"#008000\">" + "<b>"
+ "Copying File......." + "</b>" + "</font>" + "</html>";
label.setText(str);
timer.start();
try {
File f1 = new File("C:/UploadedFiles/file.txt");
File f2 = new File("C:/Hello/file.txt");
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2, true);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();

} catch (Exception e) {
}
}
}

public static void main(String[] args) {
Copy spb = new Copy();
}
}

Thanks









Related Tutorials/Questions & Answers:
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
java swing
java swing  view the book details using swing
Advertisements
Java swing
Java swing  what are the root classes of all classes in swing
Java swing
Java swing  Does Swing contains any heavy weight component
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: http://www.roseindia.net/java/example/java/swing/ Thanks
java swing - Swing AWT
java swing   how i can insert in JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class FormDemo extends JFrame { JButton ADD; JPanel
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy... a proxy or how to make my java web browser to listen to proxy setting??? please help
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java
java swing
java swing  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Grid view in java swing Thanks
java swing
java swing  add two integer variables and display the sum of them using java swing
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
java swing.
java swing.  Hi How SetBounds is used in java programs.The values in the setBounds refer to what? ie for example setBounds(30,30,30,30) and in that the four 30's refer to what
JAVA SWING
JAVA SWING  Hi.... Iam doing project in java...and my front end in swing ..our project is like billing software... then what are the topics i want cover? then how to design? pls help me
java swing - Swing AWT
java swing  how to save data in sql 2005 while insert in textfield  Hi Friend, Try the following code: import java.sql.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import
Java swing
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
Java swing
to the database using java swing...Java swing  I create one table. That table contains task ID and Task Name. When I click the task ID one more table will be open and that table
java - Swing AWT
What is Java Swing AWT  What is Java Swing AWT
swing - Java Beginners
Swing application testing  What are the conventions for testing a Java swing application
Java swing
Java swing  how to create simple addition program using java swing?   import java.awt.*; import javax.swing.*; import java.awt.event.*; class SumOfNumbers extends JFrame { SumOfNumbers(){ JLabel lab1=new
Java swing
Java swing  when i enter the time into the textbox and activities into the textarea the datas saved into the database.the java swing code for the above item   import java.sql.*; import java.awt.*; import javax.swing.
java swing
java swing  what is code for diplay on java swing internal frame form MYSQL DB pls send   Here is a code of creating form on jinternalframe and connect to mysql. import java.io.*; import java.sql.*; import java.awt.
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
Java swing in NetBeans - Swing AWT
Java swing in NetBeans   thanks a lot sir for everything you answered for my last questions now sir i just have another 3 questions that is Q 1. i will specify a swing code for JTable using NETBEANS so would you tell me
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
java swing and CSS
java swing and CSS  can css be used in java swing desktop application in different forms for better styles?plzz help
Java swing
Java swing  How to combine two java files
java swing
java swing  meaning of out.flush
Java swing
Java swing  What method is used to specify a container's layout
Java swing
Java swing  What methods are used to get and set the text label displayed by a Button object
Java Swing
Java Swing  I want scroll bar in a frame is it possible? if it is possible means i want coding for that please send me a reply
java swing
java swing  iam using my project text box, label , combobox and that the same time i want menubar and popmenu. plz give me code for this. i want immediately plz send me that code
java swing
java swing  iam using my project text box, label , combobox and that the same time i want menubar and popmenu. plz give me code for this. i want immediately plz send me that code
Java Swing
Java Swing  i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the coding sir/madam
Java Swing
Java Swing   i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the answer sir/madam
Java Swing
Java Swing  i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the coding sir/madam
Java Swing
Java Swing  i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the coding sir/madam
Java swing
Java swing  Design an appliaction for with details such as name,age,DOB,address,qualification and finaly when we click the view details button all types details should be displayed in another View in TextView's..I need the sample
Java swing
Java swing  I create 2 text field f1,f2 and 2 button b1,b2.If i enter some text in the text field and click the button b1 the text field f1 text will be shown in the Message dialog box and if i click the button b2 the text field
Java Swing
Java Swing  Write an applet program to transfer the content of the text field into the listbox component on clicking a button code project  ...++"); model.addElement("Java"); model.addElement("Perl"); model.addElement
java swing
java swing  what is code for dislay image on java swinginternalframe form MYSQL DB pls send   Here is a code that displays an image on internal frame. import java.awt.*; import java.io.*; import javax.imageio.
Java swing
Java swing  how to create the login form?   1)LoginDemo.java: import javax.swing.*; import java.sql.*; import java.awt.*; import java.awt.event.*; class LoginDemo extends JFrame { JButton SUBMIT; JLabel
Graph in JAVA SWING
Graph in JAVA SWING  Hi, How to draw a simple GRAPH in JAVA SWING ?  ..., Please visit the following link: Bar Graph in Java Swing Thanks
swing question - Java Beginners
swing question  how i can create login form in java with password entering i can to next page only if password is correct i want to use java swing feature
Java - Swing AWT
Java    Hi friend,read for more information,http://www.roseindia.net/java/example/java/swing
intranet in java swing
intranet in java swing  i want source code of intranet establishment in java swing

Ads