CORE API / CATATAN</>↗Core API17 Des 2009
In this code snippet you will see how to sort the content of an Enumeration object. We start by creating a random numbers and stored it in a Vector. We use these numbers and create a Enumeration object by calling Vector‘s elements() method. We convert it to java.util.List and then sort the content of the […]
SPRING JDBC / CATATAN</>↗Spring JDBC15 Des 2009
The following example show you how to use the Spring’s JdbcTemplate class to insert a record into database. package org.kodejava.spring.jdbc; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.sql.DataSource; import java.sql.Types; import java.util.Date; public class InsertDemo { private static final String INSERT_QUERY = """ INSERT INTO record (title, release_date, artist_id, label_id, created)...
SPRING JDBC / CATATAN</>↗Spring JDBC15 Des 2009
In this example you will learn how to create and configure a DriverManagerDataSource object that will be used by the JdbcTemplate object. There are some information required when creating a DataSource including the JDBC driver class, the JDBC Url of the target database, the username and password for connecting to database server. package org.kodejava.spring.jdbc; import […]
APACHE COMMONS / CATATAN</>↗Apache Commons11 Des 2009
The following example shows you how to read file contents into byte array. We use the IOUtils class of the Apache Commons IO library. package org.kodejava.commons.io; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class FileToByteArray { public static void main(String[] args) { File file = new File("README.md"); try { InputStream is […]
SWING / CATATAN</>↗Swing07 Des 2009
The example below demonstrates you how to create a JTree that have a different icons for each node of the tree. package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellRenderer; import java.awt.*; import java.net.URL; public class JTreeDifferentNodeIcon extends JFrame { public JTreeDifferentNodeIcon() throws HeadlessException { initializeUI(); } public static void main(String[] args) { SwingUtilities.in...
SWING / CATATAN</>↗Swing04 Des 2009
This example demonstrates how to use the expand-all and / or collapse-all features in the java.swing.JTree swing component. package org.kodejava.swing; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import javax.swing.tree.TreeNode; import java.awt.*; import java.util.Enumeration; public class JTreeNodeAutoExpandCollapse extends JFrame { public JTreeNodeAutoExpandCollapse() throws HeadlessException { initializeUI(); } p...