The most effective bookmarking tool ,rather a service (not exactly a service though).
check out http://www.furl.net
Archive for January, 2005
Bookmark the pages
Posted by Prabhu Beeman on January 31, 2005
Posted in agile | 1 Comment »
AutoScrolling of JList
Posted by Prabhu Beeman on January 24, 2005
Scrolling the List box (JList) automatically so as to view the last item added
This was the necessity for one of the applications i developed.
I was scratching my head for almost half a day and finally got a solution.
Get the JScrollBar object of the ScrollPane that is being used by the JList
//e.g:
JScrollBar verticalBar = jListScrollPane.getVerticalScrollBar();
// jListScrollPane is the ScrollPane to which the JList is added
//Now set the verticalBar’s value to it’s maximum value which is the bottom most part
//it could achieve
//e.g:
verticalBar.setValue(verticalBar.getMaximum());
//This has to be done whenever the model related to the list is updated
Posted in agile | Leave a Comment »
The MVC Pattern
Posted by Prabhu Beeman on January 20, 2005
My understanding of the MVC pattern thru a small example
Arithmetic.java
//This is the model (ie the logic)
import java.util.*;
public class Arithmetic extends Observable {
private int additionValue;
public Arithmetic() {
}
public void addInt(int number1,int number2) {
additionValue = number1 + number2; //Add two numbers
setChanged(); //Just to say something has happened
notifyObservers(); //Notify all the observers
}
public int getInt() {
return additionValue;
}
}
—————————
ArithmeticView.java
//This is the View
import java.util.*;
public class ArithmeticView implements Observer {
public void update(Observable obs,Object obj) {
System.out.println(“From ArithmeticView…..”);
Arithmetic arith = (Arithmetic)obs;
System.out.println(“Addition value = ” + arith.getInt());
}
}
——————————-
ArithmeticMain.java
//This is the controller that creates the model and attaches the view
public class ArithmeticMain {
public static void main(String arg[]){
//Create a model
Arithmetic arith = new Arithmetic(); //Create an object (Business logic)
arith.addInt(10,20); //Perform the necessary operation
//Create a view
ArithmeticView aView = new ArithmeticView();//Create a view to display the result from Arithmetic
//Attach the view to the model
arith.addObserver(aView); //Add the view to the logic (which notifies the view when gets changed)
aView.update(arith,null); //Update the view
}
}
Now run the ArithmeticMain (Controller) to view the output
Posted in agile | Leave a Comment »
An SQL Query
Posted by Prabhu Beeman on January 13, 2005
I got a mail from one of my friends with the following body.
————————————————————-
Dear Friends,
Pls. run this in oracle.
SELECT TRANSLATE(‘#1;.)89(.)1#9@1,81*.)89*-$11@.2*9$7.81^^9$5((.^5135.851@)8._51@)8.1$4.^*%(^5*9);.)%.5=5*;.%$5.%6.-(.}}}._9(89$7.-.1@@.1.=5*;.81^^;.^%$71@.}}}’,'1234567890!@#$%^&*()-=_+;,.}’,'ABCDEFGHIJKLMNOPQRSTUVWXYZ !,’) as Greetings from dual
————————————————————-
But i didn’t have oracle though i came to know about the TRANSLATE function this way
The translate function replaces a sequence of characters in a string with another set of characters. However, it replaces a single character at a time. For example, it will replace the 1st character in the string_to_replace with the 1st character in the replacement_string. Then it will replace the 2nd character in the string_to_replace with the 2nd character in the replacement_string, and so on.
The syntax for the translate function is:
translate (string1, string_to_replace, replacement_string )
string1 is the string to replace a sequence of characters with another set of characters.
string_to_replace is the string that will be searched for in string1.
replacement_string – All characters in the string_to_replace will be replaced with the corresponding character in the replacement_string.
For example:
translate (‘1tech23′, ‘123′, ‘456); would return ‘4tech56′
translate (‘222tech, ‘2ec’, ‘3it’); would return ‘333tith’
———————————————–
Here is a java simulation of the above functionality
class Translate {
private static String translate(String srcString,String strToReplace,String replacementString) {
String newString = “”;
for(int i = 0; i < srcString.length();i++) {
if((strToReplace.indexOf(srcString.charAt(i))) !=-1){
int index = strToReplace.indexOf(srcString.charAt(i));
newString += new Character(replacementString.charAt(index)).toString();
}
else {
newString += new Character(srcString.charAt(i)).toString();
}
}
return newString;
}
}
The output was the PONGAL Wishes.
Posted in agile | Leave a Comment »
Retrieving the webpage through a simple java program
Posted by Prabhu Beeman on January 13, 2005
I was thinking of writing an RSS reader on my own in my favourite language (JAVA). The simple logic was to write an XML parser/reader to read the xml file and then grab the webpage using the link available in the XML file. So here is the code that does that. This program has some limitations though,
1- can get only http pages and not https
2- Cannot get redirected pages (requires a slight modification)
Now here is the code
import java.net.*;
import java.net.MalformedURLException;
import java.net.URLConnection;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class WebPageReader {
private static URLConnection connection;
private static void connect( String urlString ) {
//Omit the following 3 lines if you are not behind the proxy
System.setProperty(“http.proxyHost”,”your_proxy_name”);
System.setProperty(“http.proxyPort”,”port_number”);
Authenticator.setDefault(new ProxyAuthenticator(“proxyUsername”,”proxyPassword”));
try {
URL url = new URL(urlString);
connection = url.openConnection();
} catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void readContents() {
System.out.println(“Reading contents…”);
BufferedReader in = null;
try {
in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while (
(inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
if (args.length != 1) {
System.err.println(“usage: java WebPageReader “
+ “”);
System.exit(0);
}
connect(args[0]);
System.out.println(“Connected…”);
readContents();
}
}
// My own Proxy authenticator
class ProxyAuthenticator extends Authenticator {
private String username;
private String password;
public ProxyAuthenticator(String username,String password) {
this.username = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password.toCharArray());
}
}
Posted in agile | 2 Comments »
