REFLECTION / CATATAN</>↗Reflection14 Nov 2008
Below is an example that showing you how to get constructors of a class object. In the code below we get the constructors by calling the Class.getDeclaredConstructors() or the Class.getConstructor(Class[]) method. package org.kodejava.lang.reflect; import java.lang.reflect.Constructor; public class GetConstructors { public static void main(String[] args) { Class<String> clazz = String.class; // Get all declared constructors and […]
REFLECTION / CATATAN</>↗Reflection13 Nov 2008
A refection demo to get fields of a class’s object and set or get their values. package org.kodejava.lang.reflect; import java.util.Date; import java.lang.reflect.Field; public class GetSetFieldDemo { public static Date now; public Long id; public String name; public static void main(String[] args) { GetSetFieldDemo demo = new GetSetFieldDemo(); Class<? extends GetSetFieldDemo> clazz = demo.getClass(); try { […]
REFLECTION / CATATAN</>↗Reflection13 Nov 2008
The example below using reflection to obtain the fields of a class object. We’ll get the field names and their corresponding type. There are three ways shown below which can be used to get an object fields: Class.getDeclaredFields() Class.getFields() Class.getField(String) package org.kodejava.lang.reflect; import java.util.Date; import java.lang.reflect.Field; public class GetFields { public Long id; protected String […]
REFLECTION / CATATAN</>↗Reflection12 Nov 2008
This example demonstrate using reflection to invoke methods of a class object. Using reflection we can call method of an object using the given string name of the method. When using this method we need to catch for the NoSuchMethodException, IllegalAccessException and InvocationTargetException. package org.kodejava.lang.reflect; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; public class InvokingMethod { public static […]
REFLECTION / CATATAN</>↗Reflection07 Nov 2008
In this example we show you how to get the methods available in a class object. We show three ways to get the methods, they are: Class.getDeclaredMethods() Class.getMethods() Class.getMethod(String, Class<?>…) package org.kodejava.lang.reflect; import java.lang.reflect.Method; public class GetMethods { public static void main(String[] args) { GetMethods object = new GetMethods(); Class<? extends GetMethods> clazz = object.getClass(); […]
SWING / CATATAN</>↗Swing05 Nov 2008
In this example we associate a JLabel component with JTextField and JPasswordField using the setLabelFor(). A mnemonic need to be set for the JLabel component and when we press the defined key (ALT + U or ALT + P) a text field will be gained focus. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; public […]