CORE API / NOTES</>↗Core API12 Sep 2007
package org.kodejava.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class MillisecondsToDate { public static void main(String[] args) { // Create a DateFormatter object for displaying date information. DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); // Get date and time information in milliseconds long now = System.currentTimeMillis(); // Create a calendar object that will convert the date […]
MAIL / NOTES</>↗Mail11 Sep 2007
In this example we create a small program to send email with a file attachment. To send message with attachment we need to create an email with javax.mail.Multipart object which basically will contain the email text message and then add a file to the second block, which both of them is an object of javax.mail.internet.MimeBodyPart. […]
CORE API / NOTES</>↗Core API07 Sep 2007
Instead of using the StringTokenizer class or the String.split() method we can use the java.util.Scanner class to split a string. package org.kodejava.util; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ScannerTokenDemo { public static void main(String[] args) { // This file contains some data as follows: // a, b, c, d // e, f, g, […]
CORE API / NOTES</>↗Core API04 Sep 2007
Here is a compact way to read file line by line using the java.util.Scanner class. package org.kodejava.util; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ScannerReadFile { public static void main(String[] args) { // Create an instance of File for data.txt file. File file = new File("README.md"); try { // Create a new Scanner object […]
MAIL / NOTES</>↗Mail31 Aug 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 / NOTES</>↗Swing26 Aug 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...