<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FReflection%2FJavaBean</id>
		<title>Java/Reflection/JavaBean - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FReflection%2FJavaBean"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Reflection/JavaBean&amp;action=history"/>
		<updated>2026-04-23T13:35:55Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Reflection/JavaBean&amp;diff=6057&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Reflection/JavaBean&amp;diff=6057&amp;oldid=prev"/>
				<updated>2010-06-01T06:01:21Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:01, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Reflection/JavaBean&amp;diff=6056&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Reflection/JavaBean&amp;diff=6056&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Get Color ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
Java Reflection in Action&lt;br /&gt;
Ira R. Forman and Nate Forman&lt;br /&gt;
ISBN 1932394184&lt;br /&gt;
Publisher: Manning Publications Co.&lt;br /&gt;
*/&lt;br /&gt;
import java.awt.Color;&lt;br /&gt;
import java.lang.reflect.InvocationTargetException;&lt;br /&gt;
import java.lang.reflect.Method;&lt;br /&gt;
public class GetColor {&lt;br /&gt;
  static public void main(String[] args) {&lt;br /&gt;
    Rabbit rabbit = new Rabbit();&lt;br /&gt;
    //start extract snippet3&lt;br /&gt;
    setObjectColor(rabbit, Color.WHITE);&lt;br /&gt;
    //stop extract snippet3&lt;br /&gt;
    if (!rabbit.setColorCalled)&lt;br /&gt;
      throw new RuntimeException();&lt;br /&gt;
  }&lt;br /&gt;
  //start extract setObjectColor&lt;br /&gt;
  public static void setObjectColor(Object obj, Color color) {&lt;br /&gt;
    Class cls = obj.getClass(); //#1&lt;br /&gt;
    try {&lt;br /&gt;
      Method method = cls.getMethod(&amp;quot;setColor&amp;quot;, //#2&lt;br /&gt;
          new Class[] { Color.class });&lt;br /&gt;
      method.invoke(obj, new Object[] { color }); //#3&lt;br /&gt;
    } catch (NoSuchMethodException ex) { //#4&lt;br /&gt;
      throw new IllegalArgumentException(cls.getName()&lt;br /&gt;
          + &amp;quot; does not support&amp;quot; + &amp;quot;method setColor(:Color)&amp;quot;);&lt;br /&gt;
    } catch (IllegalAccessException ex) { //#5&lt;br /&gt;
      throw new IllegalArgumentException(&lt;br /&gt;
          &amp;quot;Insufficient access permissions to call&amp;quot;&lt;br /&gt;
              + &amp;quot;setColor(:Color) in class &amp;quot; + cls.getName());&lt;br /&gt;
    } catch (InvocationTargetException ex) { //#6&lt;br /&gt;
      throw new RuntimeException(ex);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  //stop extract setObjectColor&lt;br /&gt;
  static public class Rabbit {&lt;br /&gt;
    public boolean setColorCalled = false;&lt;br /&gt;
    public void setColor(Color c) {&lt;br /&gt;
      setColorCalled = true;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Returns attribute&amp;quot;s getter method. If the method not found then NoSuchMethodException will be thrown. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.lang.reflect.Method;&lt;br /&gt;
import java.util.HashSet;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Set;&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source&lt;br /&gt;
 * Copyright 2005, JBoss Inc., and individual contributors as indicated&lt;br /&gt;
 * by the @authors tag. See the copyright.txt in the distribution for a&lt;br /&gt;
 * full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns attribute&amp;quot;s getter method. If the method not found then&lt;br /&gt;
   * NoSuchMethodException will be thrown.&lt;br /&gt;
   * &lt;br /&gt;
   * @param cls&lt;br /&gt;
   *          the class the attribute belongs too&lt;br /&gt;
   * @param attr&lt;br /&gt;
   *          the attribute&amp;quot;s name&lt;br /&gt;
   * @return attribute&amp;quot;s getter method&lt;br /&gt;
   * @throws NoSuchMethodException&lt;br /&gt;
   *           if the getter was not found&lt;br /&gt;
   */&lt;br /&gt;
  public final static Method getAttributeGetter(Class cls, String attr)&lt;br /&gt;
      throws NoSuchMethodException {&lt;br /&gt;
    StringBuffer buf = new StringBuffer(attr.length() + 3);&lt;br /&gt;
    buf.append(&amp;quot;get&amp;quot;);&lt;br /&gt;
    if (Character.isLowerCase(attr.charAt(0))) {&lt;br /&gt;
      buf.append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1));&lt;br /&gt;
    } else {&lt;br /&gt;
      buf.append(attr);&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      return cls.getMethod(buf.toString(), (Class[]) null);&lt;br /&gt;
    } catch (NoSuchMethodException e) {&lt;br /&gt;
      buf.replace(0, 3, &amp;quot;is&amp;quot;);&lt;br /&gt;
      return cls.getMethod(buf.toString(), (Class[]) null);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Returns attribute&amp;quot;s setter method. If the method not found then NoSuchMethodException will be thrown. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.lang.reflect.Method;&lt;br /&gt;
import java.util.HashSet;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Set;&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source&lt;br /&gt;
 * Copyright 2005, JBoss Inc., and individual contributors as indicated&lt;br /&gt;
 * by the @authors tag. See the copyright.txt in the distribution for a&lt;br /&gt;
 * full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns attribute&amp;quot;s setter method. If the method not found then&lt;br /&gt;
   * NoSuchMethodException will be thrown.&lt;br /&gt;
   * &lt;br /&gt;
   * @param cls&lt;br /&gt;
   *          the class the attribute belongs to&lt;br /&gt;
   * @param attr&lt;br /&gt;
   *          the attribute&amp;quot;s name&lt;br /&gt;
   * @param type&lt;br /&gt;
   *          the attribute&amp;quot;s type&lt;br /&gt;
   * @return attribute&amp;quot;s setter method&lt;br /&gt;
   * @throws NoSuchMethodException&lt;br /&gt;
   *           if the setter was not found&lt;br /&gt;
   */&lt;br /&gt;
  public final static Method getAttributeSetter(Class cls, String attr, Class type)&lt;br /&gt;
      throws NoSuchMethodException {&lt;br /&gt;
    StringBuffer buf = new StringBuffer(attr.length() + 3);&lt;br /&gt;
    buf.append(&amp;quot;set&amp;quot;);&lt;br /&gt;
    if (Character.isLowerCase(attr.charAt(0))) {&lt;br /&gt;
      buf.append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1));&lt;br /&gt;
    } else {&lt;br /&gt;
      buf.append(attr);&lt;br /&gt;
    }&lt;br /&gt;
    return cls.getMethod(buf.toString(), new Class[] { type });&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses reflection and JavaBeans introspection to ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2000 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book (recommended),&lt;br /&gt;
 * visit http://www.davidflanagan.ru/javaexamples2.&lt;br /&gt;
 */&lt;br /&gt;
import java.awt.Color;&lt;br /&gt;
import java.awt.ruponent;&lt;br /&gt;
import java.awt.Font;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.awt.event.WindowAdapter;&lt;br /&gt;
import java.awt.event.WindowEvent;&lt;br /&gt;
import java.beans.BeanInfo;&lt;br /&gt;
import java.beans.Introspector;&lt;br /&gt;
import java.beans.PropertyDescriptor;&lt;br /&gt;
import java.lang.reflect.Method;&lt;br /&gt;
import java.util.Vector;&lt;br /&gt;
import javax.swing.ButtonGroup;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JMenu;&lt;br /&gt;
import javax.swing.JMenuBar;&lt;br /&gt;
import javax.swing.JMenuItem;&lt;br /&gt;
import javax.swing.JRadioButtonMenuItem;&lt;br /&gt;
import javax.swing.JTabbedPane;&lt;br /&gt;
import javax.swing.SwingUtilities;&lt;br /&gt;
import javax.swing.UIManager;&lt;br /&gt;
/**&lt;br /&gt;
 * This class is a program that uses reflection and JavaBeans introspection to&lt;br /&gt;
 * create a set of named components, set named properties on those components,&lt;br /&gt;
 * and display them. It allows the user to view the components using any&lt;br /&gt;
 * installed look-and-feel. It is intended as a simple way to experiment with&lt;br /&gt;
 * AWT and Swing components, and to view a number of the other examples&lt;br /&gt;
 * developed in this chapter. It also demonstrates frames, menus, and the&lt;br /&gt;
 * JTabbedPane component.&lt;br /&gt;
 */&lt;br /&gt;
public class ShowComponent {&lt;br /&gt;
  // The main program&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    // Process the command line to get the components to display&lt;br /&gt;
    Vector components = getComponentsFromArgs(args);&lt;br /&gt;
    // Create a frame (a window) to display them in&lt;br /&gt;
    JFrame frame = new JFrame(&amp;quot;ShowComponent&amp;quot;);&lt;br /&gt;
    // Handle window close requests by exiting the VM&lt;br /&gt;
    frame.addWindowListener(new WindowAdapter() { // Anonymous inner class&lt;br /&gt;
          public void windowClosing(WindowEvent e) {&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
          }&lt;br /&gt;
        });&lt;br /&gt;
    // Set up a menu system that allows the user to select the&lt;br /&gt;
    // look-and-feel of the component from a list of installed PLAFs&lt;br /&gt;
    JMenuBar menubar = new JMenuBar(); // Create a menubar&lt;br /&gt;
    frame.setJMenuBar(menubar); // Tell the frame to display it&lt;br /&gt;
    JMenu plafmenu = createPlafMenu(frame); // Create a menu&lt;br /&gt;
    menubar.add(plafmenu); // Add the menu to the menubar&lt;br /&gt;
    // Create a JTabbedPane to display each of the components&lt;br /&gt;
    JTabbedPane pane = new JTabbedPane();&lt;br /&gt;
    // Now add each component as a tab of the tabbed pane&lt;br /&gt;
    // Use the unqualified component classname as the tab text&lt;br /&gt;
    for (int i = 0; i &amp;lt; components.size(); i++) {&lt;br /&gt;
      Component c = (Component) components.elementAt(i);&lt;br /&gt;
      String classname = c.getClass().getName();&lt;br /&gt;
      String tabname = classname&lt;br /&gt;
          .substring(classname.lastIndexOf(&amp;quot;.&amp;quot;) + 1);&lt;br /&gt;
      pane.addTab(tabname, c);&lt;br /&gt;
    }&lt;br /&gt;
    // Add the tabbed pane to the frame. Note the call to getContentPane()&lt;br /&gt;
    // This is required for JFrame, but not for most Swing components&lt;br /&gt;
    frame.getContentPane().add(pane);&lt;br /&gt;
    // Set the frame size and pop it up&lt;br /&gt;
    frame.pack(); // Make frame as big as its kids need&lt;br /&gt;
    frame.setVisible(true); // Make the frame visible on the screen&lt;br /&gt;
    // The main() method exits now but the Java VM keeps running because&lt;br /&gt;
    // all AWT programs automatically start an event-handling thread.&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * This static method queries the system to find out what Pluggable&lt;br /&gt;
   * Look-and-Feel (PLAF) implementations are available. Then it creates a&lt;br /&gt;
   * JMenu component that lists each of the implementations by name and allows&lt;br /&gt;
   * the user to select one of them using JRadioButtonMenuItem components.&lt;br /&gt;
   * When the user selects one, the selected menu item traverses the component&lt;br /&gt;
   * hierarchy and tells all components to use the new PLAF.&lt;br /&gt;
   */&lt;br /&gt;
  public static JMenu createPlafMenu(final JFrame frame) {&lt;br /&gt;
    // Create the menu&lt;br /&gt;
    JMenu plafmenu = new JMenu(&amp;quot;Look and Feel&amp;quot;);&lt;br /&gt;
    // Create an object used for radio button mutual exclusion&lt;br /&gt;
    ButtonGroup radiogroup = new ButtonGroup();&lt;br /&gt;
    // Look up the available look and feels&lt;br /&gt;
    UIManager.LookAndFeelInfo[] plafs = UIManager&lt;br /&gt;
        .getInstalledLookAndFeels();&lt;br /&gt;
    // Loop through the plafs, and add a menu item for each one&lt;br /&gt;
    for (int i = 0; i &amp;lt; plafs.length; i++) {&lt;br /&gt;
      String plafName = plafs[i].getName();&lt;br /&gt;
      final String plafClassName = plafs[i].getClassName();&lt;br /&gt;
      // Create the menu item&lt;br /&gt;
      JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName));&lt;br /&gt;
      // Tell the menu item what to do when it is selected&lt;br /&gt;
      item.addActionListener(new ActionListener() {&lt;br /&gt;
        public void actionPerformed(ActionEvent e) {&lt;br /&gt;
          try {&lt;br /&gt;
            // Set the new look and feel&lt;br /&gt;
            UIManager.setLookAndFeel(plafClassName);&lt;br /&gt;
            // Tell each component to change its look-and-feel&lt;br /&gt;
            SwingUtilities.updateComponentTreeUI(frame);&lt;br /&gt;
            // Tell the frame to resize itself to the its&lt;br /&gt;
            // children&amp;quot;s new desired sizes&lt;br /&gt;
            frame.pack();&lt;br /&gt;
          } catch (Exception ex) {&lt;br /&gt;
            System.err.println(ex);&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      });&lt;br /&gt;
      // Only allow one menu item to be selected at once&lt;br /&gt;
      radiogroup.add(item);&lt;br /&gt;
    }&lt;br /&gt;
    return plafmenu;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * This method loops through the command line arguments looking for class&lt;br /&gt;
   * names of components to create and property settings for those components&lt;br /&gt;
   * in the form name=value. This method demonstrates reflection and JavaBeans&lt;br /&gt;
   * introspection as they can be applied to dynamically created GUIs&lt;br /&gt;
   */&lt;br /&gt;
  public static Vector getComponentsFromArgs(String[] args) {&lt;br /&gt;
    Vector components = new Vector(); // List of components to return&lt;br /&gt;
    Component component = null; // The current component&lt;br /&gt;
    PropertyDescriptor[] properties = null; // Properties of the component&lt;br /&gt;
    Object[] methodArgs = new Object[1]; // We&amp;quot;ll use this below&lt;br /&gt;
    nextarg: // This is a labeled loop&lt;br /&gt;
    for (int i = 0; i &amp;lt; args.length; i++) { // Loop through all arguments&lt;br /&gt;
      // If the argument does not contain an equal sign, then it is&lt;br /&gt;
      // a component class name. Otherwise it is a property setting&lt;br /&gt;
      int equalsPos = args[i].indexOf(&amp;quot;=&amp;quot;);&lt;br /&gt;
      if (equalsPos == -1) { // Its the name of a component&lt;br /&gt;
        try {&lt;br /&gt;
          // Load the named component class&lt;br /&gt;
          Class componentClass = Class.forName(args[i]);&lt;br /&gt;
          // Instantiate it to create the component instance&lt;br /&gt;
          component = (Component) componentClass.newInstance();&lt;br /&gt;
          // Use JavaBeans to introspect the component&lt;br /&gt;
          // And get the list of properties it supports&lt;br /&gt;
          BeanInfo componentBeanInfo = Introspector&lt;br /&gt;
              .getBeanInfo(componentClass);&lt;br /&gt;
          properties = componentBeanInfo.getPropertyDescriptors();&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
          // If any step failed, print an error and exit&lt;br /&gt;
          System.out.println(&amp;quot;Can&amp;quot;t load, instantiate, &amp;quot;&lt;br /&gt;
              + &amp;quot;or introspect: &amp;quot; + args[i]);&lt;br /&gt;
          System.exit(1);&lt;br /&gt;
        }&lt;br /&gt;
        // If we succeeded, store the component in the vector&lt;br /&gt;
        components.addElement(component);&lt;br /&gt;
      } else { // The arg is a name=value property specification&lt;br /&gt;
        String name = args[i].substring(0, equalsPos); // property name&lt;br /&gt;
        String value = args[i].substring(equalsPos + 1); // property&lt;br /&gt;
                                 // value&lt;br /&gt;
        // If we don&amp;quot;t have a component to set this property on, skip!&lt;br /&gt;
        if (component == null)&lt;br /&gt;
          continue nextarg;&lt;br /&gt;
        // Now look through the properties descriptors for this&lt;br /&gt;
        // component to find one with the same name.&lt;br /&gt;
        for (int p = 0; p &amp;lt; properties.length; p++) {&lt;br /&gt;
          if (properties[p].getName().equals(name)) {&lt;br /&gt;
            // Okay, we found a property of the right name.&lt;br /&gt;
            // Now get its type, and the setter method&lt;br /&gt;
            Class type = properties[p].getPropertyType();&lt;br /&gt;
            Method setter = properties[p].getWriteMethod();&lt;br /&gt;
            // Check if property is read-only!&lt;br /&gt;
            if (setter == null) {&lt;br /&gt;
              System.err.println(&amp;quot;Property &amp;quot; + name&lt;br /&gt;
                  + &amp;quot; is read-only&amp;quot;);&lt;br /&gt;
              continue nextarg; // continue with next argument&lt;br /&gt;
            }&lt;br /&gt;
            // Try to convert the property value to the right type&lt;br /&gt;
            // We support a small set of common property types here&lt;br /&gt;
            // Store the converted value in an Object[] so it can&lt;br /&gt;
            // be easily passed when we invoke the property setter&lt;br /&gt;
            try {&lt;br /&gt;
              if (type == String.class) { // no conversion needed&lt;br /&gt;
                methodArgs[0] = value;&lt;br /&gt;
              } else if (type == int.class) { // String to int&lt;br /&gt;
                methodArgs[0] = Integer.valueOf(value);&lt;br /&gt;
              } else if (type == boolean.class) { // to boolean&lt;br /&gt;
                methodArgs[0] = Boolean.valueOf(value);&lt;br /&gt;
              } else if (type == Color.class) { // to Color&lt;br /&gt;
                methodArgs[0] = Color.decode(value);&lt;br /&gt;
              } else if (type == Font.class) { // String to Font&lt;br /&gt;
                methodArgs[0] = Font.decode(value);&lt;br /&gt;
              } else {&lt;br /&gt;
                // If we can&amp;quot;t convert, ignore the property&lt;br /&gt;
                System.err.println(&amp;quot;Property &amp;quot; + name&lt;br /&gt;
                    + &amp;quot; is of unsupported type &amp;quot;&lt;br /&gt;
                    + type.getName());&lt;br /&gt;
                continue nextarg;&lt;br /&gt;
              }&lt;br /&gt;
            } catch (Exception e) {&lt;br /&gt;
              // If conversion failed, continue with the next arg&lt;br /&gt;
              System.err.println(&amp;quot;Can&amp;quot;t convert  &amp;quot;&amp;quot; + value&lt;br /&gt;
                  + &amp;quot;&amp;quot; to type &amp;quot; + type.getName()&lt;br /&gt;
                  + &amp;quot; for property &amp;quot; + name);&lt;br /&gt;
              continue nextarg;&lt;br /&gt;
            }&lt;br /&gt;
            // Finally, use reflection to invoke the property&lt;br /&gt;
            // setter method of the component we created, and pass&lt;br /&gt;
            // in the converted property value.&lt;br /&gt;
            try {&lt;br /&gt;
              setter.invoke(component, methodArgs);&lt;br /&gt;
            } catch (Exception e) {&lt;br /&gt;
              System.err.println(&amp;quot;Can&amp;quot;t set property: &amp;quot; + name);&lt;br /&gt;
            }&lt;br /&gt;
            // Now go on to next command-line arg&lt;br /&gt;
            continue nextarg;&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        // If we get here, we didn&amp;quot;t find the named property&lt;br /&gt;
        System.err.println(&amp;quot;Warning: No such property: &amp;quot; + name);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return components;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>