Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

import javax.swing.JTextField;

import java.awt.Container;
import java.awt.Component;

public class Main {
    public static String param(String name, Container c) {
        List<JTextField> filter = new ArrayList<JTextField>();
        searchFor(c, JTextField.class, filter, name.replaceAll("\\[", "\\[").replaceAll("\\]", "\\]"));
        return filter.isEmpty() ? null : filter.get(0).getText();
    }

    private static void searchFor(Container c, Class cls, List list, String name) {
        if (!isEmpty(c.getComponents())) {
            for (Component comp : c.getComponents()) {
                if (cls.isInstance(comp)
                        && (name == null ? true : (comp.getName() != null && comp.getName().matches(name)))) {
                    list.add(comp);
                } else if (comp instanceof Container) {
                    searchFor((Container) comp, cls, list, name);
                }
            }
        }
    }

    public static boolean isEmpty(Object o) {
        return o == null || (o instanceof String && o.toString().trim().equals(""));
    }
}