REFLECTION / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 […]
SWING / NOTES</>↗Swing04 Nov 2008
To create a JLabel with an image icon we can either pass an ImageIcon as a second parameter to the JLabel constructor or use the JLabel.setIcon() method to set the icon. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.util.Objects; public class JLabelWithIcon extends JFrame { public JLabelWithIcon() throws HeadlessException { initialize(); } private void initialize() […]
SWING / NOTES</>↗Swing30 Oct 2008
package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class JLabelDemo extends JFrame { public JLabelDemo() throws HeadlessException { initialize(); } private void initialize() { setSize(150, 300); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setLayout(new FlowLayout()); // Create some JLabel with Texts and define the horizontal alignment JLabel label1 = new JLabel("Username :", JLabel.RIGHT); JLabel label2 = new JLabel("Password :", JLabel.R...