Java

Swing program to find whether a string is available in Combo Box

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

class JComboBoxDemo extends JFrame
{
 JComboBox jcb;
 JButton jbtn;
 JComboBoxDemo()
 {
  super("Java with Z");
  setSize(500,500);
  setDefaultCloseOperation(2);
  setLocationRelativeTo(null);
  Container c=getContentPane();
  c.setLayout(null);

  Vector v=new Vector();
  v.add("Tom");
  v.add("Alex");
  v.add("Mike");
  v.add("John");

  jcb=new JComboBox(v);
  jcb.setBounds(100,100,200,30);
  c.add(jcb);

  jbtn=new JButton("Find Tom");
  jbtn.setBounds(100,300,100,30);
  jbtn.addActionListener(new ActionListener()
    {
     public void actionPerformed(java.awt.event.ActionEvent ae)
     {
     int size=jcb.getItemCount();
     for (int i=0;i<size ;i++)
     {
      String s=jcb.getItemAt(i).toString();
      if (s.equalsIgnoreCase("tom"))
      {
       JOptionPane.showMessageDialog(null,"Found");
      }
     }

     }
    });
    c.add(jbtn);


 
  setVisible(true);
 }
 public static void main(String args[] )
 {
  JComboBoxDemo app=new JComboBoxDemo();
 }
}

Related Posts

language_img
Java

Overriding

Oct 12, 2013

Table Of Contents

;