SWING / CATATAN</>↗Swing25 Nov 2008
The example below shows you how we can customize the icon for JButton Swing components. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class JButtonCustomIcon extends JFrame { public JButtonCustomIcon() throws HeadlessException { initialize(); } private void initialize() { setSize(500, 500); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.LEFT)); JButton button = new JButton("Press Me!"); // Below is ho...
SWING / CATATAN</>↗Swing25 Nov 2008
JCheckBox can have a different icon for its states, there are default icon, a selected icon, disabled icon, pressed icon or rollover icon, etc. See the code below and have a try on it. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class JCheckBoxCustomIcon extends JFrame { public JCheckBoxCustomIcon() throws HeadlessException { initialize(); } private void […]
SWING / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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...