SWING / NOTES</>↗Swing21 Nov 2008
This simple example shows you how to get or set the state of a JCheckBox. The method to set the state is JCheckBox.setSelected(boolean) and the method for getting the state is JCheckBox.isSelected() which return a boolean value. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class CheckBoxState extends JFrame { public CheckBoxState() throws HeadlessException { initialize(); […]
SWING / NOTES</>↗Swing19 Nov 2008
This example demonstrate a various way to create JCheckBox component. Here you can also see how the handle an event when the checkbox is clicked by user. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.util.Objects; public class CheckBoxDemoCreate extends JFrame { public CheckBoxDemoCreate() throws HeadlessException { initialize(); } private void initialize() { setSize(500, 500); setTitle("JCheckBox […]
REFLECTION / NOTES</>↗Reflection19 Nov 2008
package org.kodejava.lang.reflect; import java.lang.reflect.Modifier; public class ClassModifier { public static void main(String[] args) { getClassModifier(String.class); getClassModifier(TestA.class); getClassModifier(TestB.class); } private static void getClassModifier(Class<?> clazz) { int modifier = clazz.getModifiers(); // Return true if the integer argument includes the public modifier, // false otherwise. if (Modifier.isPublic(modifier)) { System.out.println(clazz.get...
REFLECTION / NOTES</>↗Reflection15 Nov 2008
The example below using a constructor reflection to create a string object by calling String(String) and String(StringBuilder) constructors. package org.kodejava.lang.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class CreateObjectDemo { public static void main(String[] args) { Class<String> clazz = String.class; try { Constructor<String> constructor = clazz.getConstructor(String.class); String object = constructor.n...
REFLECTION / NOTES</>↗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 / NOTES</>↗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 { […]