Skip to main content

Posts

Showing posts from April, 2013

Day-to-day Programming 3: Rename Files with numbers - part 2

How to rename bunch of files with numbers (with leading zeros)? I mentioned in my earlier post  Day-today Programming 2     about the simple java program to rename files with numbers.  eg:- 1.MP3 2.MP3 3.MP3  ... As I said there were about 200 MP3s. Mom wanted them to play in the numbered order. But when the DVD player plays them after playing 1.MP3 it didn't play 2.MP3 next. It played 10.MP3 instead. That was because it plays them in ascending order.  When it plays in ascending order, after 1, the next one is 10, and the next one is 100. It plays 2.Mp3 after finishing all the tracks that start from digit 1. So I had to write the DVD again. This time I have to rename them in a different way.  If I rename them with leading zeros, it will play them in the order as numbered. eg:- 001.MP3 002.MP3 ... 010.MP3 ... 100.MP3 In order to do that, I changed my previous renaming program a little bit. This might not be the most efficient way...

Day-to-day Programming 2: Rename Files with numbers

How to rename a bunch of files with numbers? From my earlier post-Day-today  Programming 1  I told you how my mom asked me to write her a DVD. Then as I mentioned earlier, I managed to take a printout of the filenames. Now I have to write them into a DVD. But mom asked me to rename the MP3s with numbers. so that she can find the number of the MP3 printed-out document. So I again wrote a simple java program to rename the files with numbers starting from 1. Here is the small program I wrote. //simple java program to rename files with numbers.  import java.io.File; import java.io.IOException; public class Rename2Numbers { public static void main(String[] args) throws IOException { File folder = new File("C:/My Folder"); int i = 1; for(File f : folder.listFiles()){ f.renameTo(new File("C:/My Folder/"+i+".mp3")); i++; } ...

Day-to-day Programming 1: File names into a text file

How to get the names of the files in a specific directory (folder)  to a text file? Today my mother asked me to write some MP3s into a DVD. There were nearly 200 MP3 files. and she also asked me to number them and make a list of file names to print out. I was like o.O how am I going to do that? type all 200 file names into a document? I felt lazy and thought why can't I write a program that will do it for me !. so I wrote a simple program that gets file names and writes them into a text file, so I can print them out. This is the simple program I wrote. It took less than 2 minutes to write it. and saved a considerable amount of time!  ;) 1: import java.io.BufferedWriter; 2: import java.io.File; 3: import java.io.FileWriter; 4: import java.io.IOException; 5: 6: public class FilenamesToTxt { 7: public static void main(String[] args) throws IOException { 8: File folder = new File("C:/My Folder"); 9: BufferedWriter bf ...

How to set a background image to a jFrame?

in Eclipse in NetBeans IDE If you are using Netbeans IDE or windowbuilder in Eclipse to develop Swing GUIs, you might wanted to set background images to jFrames. The easiest way is putting a jLabel to cover whole jFrame and set an image to it. It might be ok Absolute layout but if you are using  something like SpringLayout this will not work. And also there might be problems with re-sizing the jFrame. Instead of that what we are going to do is put a jPanel to cover up the whole jFrame and set a background image to it. in Eclipse WindowBuilder I have already installed WindowBuilder plugin in my Eclipse and created a java project. And I have created a new jFrame form with WindowBuilder. (If you are not familiar with eclipse and windowbuilder please google it and read first) Here is the code for MyFrame class which is automatically created by windowbuilder 1: package org.jframebg; 2: import java.awt.BorderLayout; 3: import java.awt.EventQ...