REFLECTION / NOTES</>↗Reflection11 Dec 2010
Java reflection also dealing with inheritance concepts. You can get the direct interfaces and direct super class of a class by using method getInterfaces() and getSuperclass() of java.lang.Class object. getInterfaces() will returns an array of Class objects that represent the direct super interfaces of the target Class object. getSuperclass() will returns the Class object representing […]
REFLECTION / NOTES</>↗Reflection11 Dec 2010
You can use the isInterface() method call of the java.lang.Class to identify if a class objects represent an interface type. package org.kodejava.lang.reflect; import java.io.Serializable; public class IsInterfaceDemo { public static void main(String[] args) { IsInterfaceDemo.get(Serializable.class); IsInterfaceDemo.get(Long.class); } private static void get(Class<?> clazz) { if (clazz.isInterface()) { System.out.println(clazz.getName() + " is an interface type."); } else […]
REFLECTION / NOTES</>↗Reflection11 Dec 2010
Java uses class objects to represent all eight primitive types. A class object that represents a primitive type can be identified using the isPrimitive() method call. void is not a type in Java, but the isPrimitive() method returns true for void.class. package org.kodejava.lang.reflect; public class IsPrimitiveDemo { public static void main(String[] args) { IsPrimitiveDemo.get(int.class); IsPrimitiveDemo.get(String.class); […]
REFLECTION / NOTES</>↗Reflection11 Dec 2010
package org.kodejava.lang.reflect; import java.util.Date; public class ClassNameDemo { public static void main(String[] args) { Date date = new Date(); // Gets the Class of the date instance. Class<?> clazz = date.getClass(); // Gets the name of the class. String name = clazz.getName(); System.out.println("Class name : " + name); // Gets the canonical name of the […]
SWING / NOTES</>↗Swing12 Nov 2010
Selecting all text in the JTextArea component can be done by using the selectAll() method. In the example below we use a button action to do the selection. After select the text we transfer focus back to the JTextArea so that the highlighted text is shown. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class TextAreaSelectAll […]
SWING / NOTES</>↗Swing12 Nov 2010
To append text to the end of the JTextArea document we can use the append(String str) method. This method does nothing if the document is null or the string is null or empty. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class TextAreaAppendText extends JPanel { public TextAreaAppendText() { initializeUI(); } public static void showFrame() { […]