MAIL / CATATAN</>↗Mail31 Agt 2007
To enable your application to send email you can use the JavaMail API, and prior to JDK 1.6 you will also need the JavaBeans Activation Framework. The JAF jar file should be included in your application classpath. package org.kodejava.mail; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; publi...
SWING / CATATAN</>↗Swing26 Agt 2007
To right justified a JTextField contents we can call the setHorizontalAlignment(JTextField.RIGHT) method of the JTextField class. package org.kodejava.swing; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; public class TextFieldRightJustify extends JFrame { public TextFieldRightJustify() { initComponents(); } public...
SWING / CATATAN</>↗Swing22 Agt 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 / CATATAN</>↗Core API21 Agt 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 / CATATAN</>↗Core API21 Agt 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 / CATATAN</>↗Swing19 Agt 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...