Example usage for java.util Enumeration nextElement

List of usage examples for java.util Enumeration nextElement

Introduction

In this page you can find the example usage for java.util Enumeration nextElement.

Prototype

E nextElement();

Source Link

Document

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTree tree = new JTree();
    Enumeration en = ((DefaultMutableTreeNode) tree.getModel().getRoot()).preorderEnumeration();
    while (en.hasMoreElements()) {
        TreePath path = new TreePath(((DefaultMutableTreeNode) en.nextElement()).getPath());
        String text = path.toString();
        System.out.println(text);
    }//from ww w.  j  a  va 2s .  co m
}

From source file:FindingAButtonGroup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Group");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Examples");
    panel.setBorder(border);/*from w w  w . ja va2s .c o  m*/
    ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JToggleButton("Toggle Button");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Radio Button");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JCheckBox("Check Box");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item");
    panel.add(abstract5);
    group.add(abstract5);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
    group.setSelected(abstract1.getModel(), true);
    Enumeration elements = group.getElements();
    while (elements.hasMoreElements()) {
        AbstractButton button = (AbstractButton) elements.nextElement();
        if (button.isSelected()) {
            System.out.println("The winner is: " + button.getText());
        }
    }
}

From source file:Main.java

public static void main(String args[]) {
    // create hash table 
    Hashtable<Integer, String> htable1 = new Hashtable<Integer, String>();

    // put values in table
    htable1.put(1, "A");
    htable1.put(2, "B");
    htable1.put(3, "C");
    htable1.put(4, "from java2s.com");

    // create enumeration for keys
    Enumeration en = htable1.keys();

    System.out.println("Display result:");

    // display search result
    while (en.hasMoreElements()) {
        System.out.println(en.nextElement());
    }/* w  ww  .  j a  v  a 2s  .  c o  m*/
}

From source file:Main.java

public static void main(String args[]) {
    Hashtable<Integer, String> htable = new Hashtable<Integer, String>();

    // put values into the table
    htable.put(1, "A");
    htable.put(2, "B");
    htable.put(3, "C");
    htable.put(4, "from java2s.com");

    // create enumeration
    Enumeration<String> e = htable.elements();

    System.out.println("Display result:");

    // display search result
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }/*from  www .  j  a  v  a 2 s  .  c o  m*/
}

From source file:SettingSelectedAButtonGroup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Group");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Examples");
    panel.setBorder(border);/*from  ww w. j a v  a2 s.co  m*/
    ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JToggleButton("Toggle Button");
    panel.add(abstract1);
    group.add(abstract1);

    AbstractButton abstract2 = new JRadioButton("Radio Button");
    panel.add(abstract2);
    group.add(abstract2);

    AbstractButton abstract3 = new JCheckBox("Check Box");
    panel.add(abstract3);
    group.add(abstract3);

    AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item");
    panel.add(abstract4);
    group.add(abstract4);

    AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item");
    panel.add(abstract5);
    group.add(abstract5);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
    group.setSelected(abstract1.getModel(), true);

    Enumeration elements = group.getElements();
    while (elements.hasMoreElements()) {
        AbstractButton button = (AbstractButton) elements.nextElement();
        if (button.isSelected()) {
            System.out.println("The winner is: " + button.getText());
        }
    }
}

From source file:Utilities.java

public static void main(String[] args) {
    List list = Arrays.asList("one Two three Four five six one".split(" "));
    System.out.println(list);/*from   w w  w.  j a v  a  2 s  . co  m*/
    System.out.println("max: " + Collections.max(list));
    System.out.println("min: " + Collections.min(list));
    AlphabeticComparator comp = new AlphabeticComparator();
    System.out.println("max w/ comparator: " + Collections.max(list, comp));
    System.out.println("min w/ comparator: " + Collections.min(list, comp));
    List sublist = Arrays.asList("Four five six".split(" "));
    System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
    System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
    Collections.replaceAll(list, "one", "Yo");
    System.out.println("replaceAll: " + list);
    Collections.reverse(list);
    System.out.println("reverse: " + list);
    Collections.rotate(list, 3);
    System.out.println("rotate: " + list);
    List source = Arrays.asList("in the matrix".split(" "));
    Collections.copy(list, source);
    System.out.println("copy: " + list);
    Collections.swap(list, 0, list.size() - 1);
    System.out.println("swap: " + list);
    Collections.fill(list, "pop");
    System.out.println("fill: " + list);
    List dups = Collections.nCopies(3, "snap");
    System.out.println("dups: " + dups);
    // Getting an old-style Enumeration:
    Enumeration e = Collections.enumeration(dups);
    Vector v = new Vector();
    while (e.hasMoreElements())
        v.addElement(e.nextElement());
    // Converting an old-style Vector
    // to a List via an Enumeration:
    ArrayList arrayList = Collections.list(v.elements());
    System.out.println("arrayList: " + arrayList);

}

From source file:ASelectedButton.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Radio Buttons");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Options");
    panel.setBorder(border);//  w w w. j  ava2  s .  c  o  m
    final ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JRadioButton("One");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Two");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JRadioButton("Three");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButton("Four");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JRadioButton("Five");
    panel.add(abstract5);
    group.add(abstract5);
    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Enumeration elements = group.getElements();
            while (elements.hasMoreElements()) {
                AbstractButton button = (AbstractButton) elements.nextElement();
                if (button.isSelected()) {
                    System.out.println("The winner is: " + button.getText());
                    break;
                }
            }
            group.setSelected(null, true);
        }
    };
    JToggleButton button = new JToggleButton("Show Selected");
    button.addActionListener(aListener);
    Container container = frame.getContentPane();
    container.add(panel, BorderLayout.CENTER);
    container.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Options");
    panel.setBorder(border);//from w ww.j av  a2  s  . co m
    final ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JRadioButton("One");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Two");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JRadioButton("Three");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButton("Four");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JRadioButton("Five");
    panel.add(abstract5);
    group.add(abstract5);
    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Enumeration elements = group.getElements();
            while (elements.hasMoreElements()) {
                AbstractButton button = (AbstractButton) elements.nextElement();
                if (button.isSelected()) {
                    System.out.println("The winner is: " + button.getText());
                    break;
                }
            }
            group.setSelected(null, true);
        }
    };
    JButton button = new JButton("Show Selected");
    button.addActionListener(aListener);
    Container container = frame.getContentPane();
    container.add(panel, BorderLayout.CENTER);
    container.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:example.browser.Browser.java

public static void main(String[] args) {
    String url = BROKER_URL;
    if (args.length > 0) {
        url = args[0].trim();//from ww w . j ava2  s  .  co  m
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url);
    Connection connection = null;

    try {

        connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        Queue destination = session.createQueue("test-queue");
        QueueBrowser browser = session.createBrowser(destination);
        Enumeration enumeration = browser.getEnumeration();

        while (enumeration.hasMoreElements()) {
            TextMessage message = (TextMessage) enumeration.nextElement();
            System.out.println("Browsing: " + message);
            TimeUnit.MILLISECONDS.sleep(DELAY);
        }

        session.close();

    } catch (Exception e) {
        System.out.println("Caught exception!");
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                System.out.println("Could not close an open connection...");
            }
        }
    }
}

From source file:ReadZip.java

public static void main(String args[]) {
    try {//  www. j  ava  2 s  .com
        ZipFile zf = new ZipFile("ReadZip.zip");
        Enumeration entries = zf.entries();

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        while (entries.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) entries.nextElement();
            System.out.println("Read " + ze.getName() + "?");
            String inputLine = input.readLine();
            if (inputLine.equalsIgnoreCase("yes")) {
                long size = ze.getSize();
                if (size > 0) {
                    System.out.println("Length is " + size);
                    BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
                    String line;
                    while ((line = br.readLine()) != null) {
                        System.out.println(line);
                    }
                    br.close();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}