Breaking News
Home / Java / Java Snippets

Java Snippets

How to show Alert Dialog in Java Swing?

Displaying a simple message box or an alert dialog with an Ok button can be done with just one line of code as show below: A) Without a JFrame JOptionPane.showMessageDialog(null, “Message goes here”); This will display the dialog box in the center of your screen. B) If you have a …

Read More »

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and point version.   public class CheckVersion {   public static void main(String[] args) {     String version = System.getProperty(“java.version”);     char minor = version.charAt(2);     char point = version.charAt(4);     if(minor …

Read More »

How to parse ShoutCast/IceCast Stream Metadata in Java?

Snippet StreamScraper is a java library that can be used to harvest streaming metadata (current song title, genre, current listener count, etc.) from SHOUTcast/IceCast servers. Usage import; import java.util.List; import net.moraleboost.streamscraper.Stream; import net.moraleboost.streamscraper.Scraper; import net.moraleboost.streamscraper.scraper.IceCastScraper;   public class   Harvester{    public static void main(String[] args)throws Exception    { …

Read More »
Advertisment ad adsense adlogger