REGEX / NOTES</>↗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 […]
SWING / NOTES</>↗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 […]
CORE API / NOTES</>↗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...
CORE API / NOTES</>↗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 / NOTES</>↗Core API02 Apr 2013
In the snippet below you’ll learn to open file for reading using Files.newBufferedReader() method in JDK 7. This method returns a java.io.BufferedReader which makes a backward compatibility with the old I/O system in Java. To read a file you’ll need to provide a Path and the Charset to the newBufferedReader() method arguments. package org.kodejava.io; import […]
CORE API / NOTES</>↗Core API02 Apr 2013
To open a file for writing in JDK 7 you can use the Files.newBufferedWriter() method. This method takes three arguments. We need to pass the Path, the Charset and a varargs of OpenOption. For example, in the snippet below we pass the path of our log file, we use the StandardCharsets.UTF_8 charset, and we use […]