JDBC / CATATAN</>↗JDBC11 Jun 2013
In the following code snippet, you will see how to pass some connection arguments when connecting to a database. To do this, we can use the java.util.Properties class. We can put some key value pairs as a connection arguments to the Properties object before we pass this information into the DriverManager class. Let’s see the […]
CORE API / CATATAN</>↗Core API10 Apr 2013
package org.kodejava.example.util; import java.util.Hashtable; import java.util.Random; public class HashtableGetRandom { public static void main(String[] args) { // Create a hashtable and put some key-value pair. Hashtable<String, String> colors = new Hashtable<>(); colors.put("black", "#000"); colors.put("red", "#f00"); colors.put("green", "#0f0"); colors.put("blue", "#00f"); colors.put("white", "#fff"); // Get a random entry from the hashtable. String[] keys = colors.keySe...
SWING / CATATAN</>↗Swing10 Apr 2013
In this code snippet you’ll see how to define JRadioButton label position. By default, the label will be displayed on the right side of the button. In the code below you will see some examples for placing the label on the left side, at the top and the bottom of the JRadioButton. To define the […]
REGEX / CATATAN</>↗Regex10 Apr 2013
package org.kodejava.regex; public class GetNumberOfWordsFromString { public static void main(String[] args) { String text = "The quick brown fox jumps over the lazy dog."; String one = truncateAfterWords(1, text); System.out.println("1 = " + one); String two = truncateAfterWords(2, text); System.out.println("2 = " + two); String four = truncateAfterWords(4, text); System.out.println("4 = " + four); String […]
CORE API / CATATAN</>↗Core API03 Apr 2013
package org.kodejava.io; import java.io.IOException; import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; public class WatchServiceGetFilename { public static void main(String[] args) { try { // Create a WatchService and register the logDir path with the // WatchService for ENTRY_CREATE. WatchService watcher = FileSystems.getDefault().newWatchService(); Path logDir = Paths.get("F:/Temp"); logDir.register(watcher, ENTRY_CREATE); while (true) { WatchKe...
CORE API / CATATAN</>↗Core API03 Apr 2013
package org.kodejava.io; import java.io.IOException; import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; public class FileWatchDemo { public static void main(String[] args) { try { // Creates a instance of WatchService. WatchService watcher = FileSystems.getDefault().newWatchService(); // Registers the logDir below with a watch service. Path logDir = Paths.get("F:/Temp/"); logDir.register(watcher, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); // Monito...