SWING / NOTES</>↗Swing22 Aug 2007
JLabel text can be formatted using an HTML standard tags. The example below shows you how we can use and HTML font tag to change the font size, color and style of JLabel text. package org.kodejava.swing; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; import java.awt.Container; import java.awt.FlowLayout; public class JLabelHTMLStyle extends JFrame { public […]
CORE API / NOTES</>↗Core API21 Aug 2007
In this example we use the java.io.StringWriter and java.io.PrintWriter class to convert stack trace exception message to a string. package org.kodejava.io; import java.io.StringWriter; import java.io.PrintWriter; public class StackTraceToString { public static void main(String[] args) { try { int result = 10 / 0; } catch (Exception e) { // Create a StringWriter and a PrintWriter […]
CORE API / NOTES</>↗Core API21 Aug 2007
The java.util.prefs package provides a way for applications to store and retrieve user and system preferences and data configuration. These preference data will be stored persistently in an implementation-dependent backing stored. For example in Windows operating system in will stored in Windows registry. To write and read these data we use the java.util.prefs.Preferences class. The […]
SWING / NOTES</>↗Swing19 Aug 2007
package org.kodejava.swing; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; import java.awt.FlowLayout; public class ButtonImageExample extends JFrame { public ButtonImageExample() { initComponents(); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new ButtonImageExample().setVisible(true)); } private void initComponents() { setTitle("My Butt...
SWING / NOTES</>↗Swing18 Aug 2007
The JFormattedTextField allows us to create a text field that can accept a formatted input. In this code snippet we create two formatted text fields that accept a valid phone number and a date. package org.kodejava.swing; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; import javax.swing.text.DateFormatter; import javax.swing.text.MaskFormatter; import java.awt.Dimension; import java.awt...
JDBC / NOTES</>↗JDBC14 Aug 2007
Using an updatable result set enables our program to update record in the database from the ResultSet object. The operation on the ResultSet object can be updated, inserted or deleted. With this mechanism, we can update a database without executing a query. In the example below we have a product table with the id, code, […]