Image

Programs - J2EE - Swing

Program:


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

/**
*
* @author Ashish
*/

public class ComboModel implements ComboBoxModel{

ArrayList cityList;
Object item;
int index;

  public ComboModel(ArrayList cityList) {
    this.cityList=cityList;
    cityList.set(index, item);
    
    //item="Select City";
  /*try {
       Class.forName("com.mysql.jdbc.Driver");
       System.out.println("Connected");
       Connection connection = DriverManager.getConnection("jdbc:mySQL://localhost:3306/person", "root", "tiger");
      item=cityList.get(index);
      
      String q1="insert into mycity values ('"+item+"')";
      Statement createStatement = connection.createStatement();
      createStatement.execute(q1);      
      System.out.println("Success");
    } catch (Exception ex) {
      System.out.println(ex);
    }    */

    
    
  }

  @Override
  public void setSelectedItem(Object o) {
    item=o;
// list.set(item);
    //list.add(item);
    //cityList.set(index, item);
  }

  @Override
  public Object getSelectedItem() {
    return item;
    
    //return null;
  }

  @Override
  public int getSize() {
    return cityList.size();
  }

  @Override
  public Object getElementAt(int index) {
  
    return item=cityList.get(index);
  }

  @Override
  public void addListDataListener(ListDataListener l) {
    
  }

  @Override
  public void removeListDataListener(ListDataListener l) {
    
  }



}