Thursday, October 16, 2008


Java sort() Method Example

If you want to sort string characters then this example is the best for you. The sort() method sort words in ascending order. Look a simple example of sort() method given below :

import java.util.*;
import java.io.*;
import java.lang.String;

public class sortstr{
public static void main(String args[]){
String str = "Java String Example";
char[] content = str.toCharArray();
java.util.Arrays.sort(content);
String sorted = new String(content);
System.out.println(content);
}
}

Result : EJSaaegilmnprtvx


Friday, September 26, 2008


Show Icon on The Button

With the help of java swing, you can add images, icons in the application to make your GUI application interface more attractive. With the help of this example, you can learn how to add image on the button or other control. This example expain you add image file. The code is given below :

import javax.swing.*;
import java.awt.*;

public class IconButton{
public static void main(String[] args){
JFrame frame = new JFrame("Swing Icon Example");
JButton button = new JButton("My Button");
Icon imgicon = new ImageIcon("smiley_icon.gif");
JPanel panel = new JPanel();
button.setIcon(imgicon);
panel.add(button);
frame.add(panel, BorderLayout.NORTH);
frame.setSize(380, 380);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}