Java tutorial
//package com.java2s; import javax.swing.JComponent; import javax.swing.text.JTextComponent; public class Main { public static Object getValue(JComponent com) { if (com == null) { return null; } Class<?> comType = com.getClass(); Object val = null; if (JTextComponent.class.isAssignableFrom(comType)) { val = ((JTextComponent) com).getText(); } else { throw new RuntimeException("Unsupported getValue component-" + comType); } return val; } }