actionlisteners for 2 comboboxes
I have to comboboxes name, accountnumbers that have information in them. If I pick a name like msaenz, it will give me the accountnumbers to go with it and I have it do vice versa. however when i pick a name and an account number and if that account number has another person pointed to it, it changes the namefield. its basically like tag. I have this code for the actionlisteneres but do not know really what to do to check on the other. I also have a reset button to set the comboboxes to their original state. i was thinking maybe a counter? I don't know any ideas would be wonderful.. thanks for your help all of you who have seen my numerous posts.......
//first combo box name.. i have a hashmap with the accounts and names that are related to each other that i get from a db....and i call them from the testsql class
if ((event.getActionCommand().equals("no"))){
for (String key:TestSQL.theMap().keySet())
{
check=(String) getNames().getSelectedItem();
if (check.equals(key)){
value = TestSQL.theMap().get( key );
}
}
value.add("");
values=(String[]) value.toArray(new String[value.size()]);
getCuentas2().setModel(new JComboBox(values).getModel());
}
//second class....
if ((event.getActionCommand().equals("yes"))){
for (String key:TestSQL.theMap2().keySet())
{
check=(String) getAccounts().getSelectedItem();
if (check.equals(key)){
entry= TestSQL.theMap().get( key );
}
}
entrys=(String[]) entry.toArray(new String[entry.size()]);
getCuentas2().setModel(new JComboBox(values).getModel());
}
# 7
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.*;
import javax.swing.ComboBoxModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import java.awt.Dimension;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.JRadioButton;
import javax.swing.JTextPane;
import javax.swing.JTextField;
public class Test extends JTabbedPane implements ActionListener {
private static final long serialVersionUID = 1;
/*****Tab2****/
JPanel MainPanel;
JPanel jPanel2;
JTable table;
DefaultTableModel model;
JComboBox TablasBox;
JLabel Tablas;
JPanel extra = null;
JPanel trads = null;
JComboBox traders = null;
JPanel accounts = null;
JComboBox cuentas2 = null;
String []ops={"","=","between", "and", "where","<", ">", "<=", ">=", "in"};
JButton updateQuery;
TestSQL examen;
static Hashtable<String, JCheckBox> checkboxes=new Hashtable<String,JCheckBox>();
private JComboBox jComboBox = null;
private JPanel accnttrd = null;
String check;
String lool;
Set<String> value;
String[] values;
Set <String> answer;
String [] things;
Calendar cal;
Date today;
Date yesterday;
SimpleDateFormat sqlFormat;
String todayString;
String yesterdayString;
public Test() {
super();
setVisible(true);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private Map < String, Set < String > > map = new HashMap < String,
Set < String > > ();
public boolean put(String key, String value) {
Set<String> values = map.get(key);
if (values == null)
map.put(key, values=new HashSet < String > ());
return values.add(value);
}
public String toString() {
return map.toString();
}
public Map < String, Set < String > > theMap(){
Test m = new Test();
m.put("alex", "12345");
m.put("vivian", "12345");
m.put("teacher", "98741");
m.put("harry", "65789");
m.put("steve", "54652");
m.put("teacher", "54652");
return m.map;
}
public Map < String, Set < String > > theMap2(){
Test m = new Test();
m.put("12345", "alex");
m.put("12345", "vivian");
m.put("98741", "teacher");
m.put("65789", "harry");
m.put("54652", "steve");
m.put("54652", "teacher");
m.put("98741","vivian");
return m.map;
}
public void initialize() {
this.setSize(1118, 419);
this.addTab("GUI",null, getMainPanel(), null);
}
String[] nombres={"alex","vivian","teacher","harry"};
String[] accountnum={"12345","98741","65789","54652"};
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
public JPanel getMainPanel() {
if (MainPanel == null) {
FlowLayout flowLayout1 = new FlowLayout();
flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
flowLayout1.setVgap(3);
flowLayout1.setHgap(3);
MainPanel = new JPanel();
MainPanel.setLayout(flowLayout1);
MainPanel.setPreferredSize(new java.awt.Dimension(900,300));
MainPanel.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
MainPanel.setVisible(true);
MainPanel.add(getAccnttrd(), null);
}
return MainPanel;
}
private JPanel getTrads() {
if (trads == null) {
GridLayout gridLayout11 = new GridLayout();
gridLayout11.setRows(8);
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(8);
trads = new JPanel();
trads.setLayout(gridLayout11);
trads.setPreferredSize(new java.awt.Dimension(100,189));
trads.setVisible(true);
trads.add(getTraders(), null);
}
return trads;
}
JComboBox getTraders() {
if (traders == null) {
traders = new JComboBox(nombres);
traders.setEditable(false);
traders.setPreferredSize(new java.awt.Dimension(60,20));
traders.addActionListener(this);
traders.setActionCommand("no");
}
return traders;
}
private JPanel getAccounts() {
if (accounts == null) {
GridLayout gridLayout14 = new GridLayout();
gridLayout14.setRows(8);
accounts = new JPanel();
accounts.setPreferredSize(new java.awt.Dimension(100,189));
accounts.setLayout(gridLayout14);
accounts.add(getCuentas2(), null);
accounts.setVisible(true);
}
return accounts;
}
private JComboBox getCuentas2() {
if (cuentas2 == null) {
cuentas2 = new JComboBox(accountnum);
cuentas2.setPreferredSize(new java.awt.Dimension(60,20));
cuentas2.setEditable(false);
cuentas2.addActionListener(this);
cuentas2.setActionCommand("cuentas2");
}
return cuentas2;
}
/**
* This method initializes accnttrd
*
* @return javax.swing.JPanel
*/
private JPanel getAccnttrd() {
if (accnttrd == null) {
FlowLayout flowLayout = new FlowLayout();
flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
flowLayout.setVgap(2);
flowLayout.setHgap(2);
accnttrd = new JPanel();
accnttrd.setPreferredSize(new java.awt.Dimension(330,190));
accnttrd.setVisible(true);
accnttrd.setLayout(flowLayout);
accnttrd.add(getTrads(), null);
accnttrd.add(getAccounts(), null);
}
return accnttrd;
}
public static String checkCaja()
{
String temp="";
for(String name:checkboxes.keySet()){
//System.out.println(checkboxes.get(name).isSelected()+name);
if (checkboxes.get(name).isSelected()==true)
{
temp=temp+name+",";
}
}
if(temp.length() > 0) {
temp = temp.substring(0, temp.length() - 1);
}
//System.out.print(temp);
return temp;
}
public void actionPerformed(ActionEvent event) {
if ((event.getActionCommand().equals("no"))){
for (String key: theMap().keySet())
{
check=(String) getTraders().getSelectedItem();
if (check.equals(key)){
value = ((Map<String,Set><String>>) theMap()).get( key );
}
}
values=(String[]) value.toArray(new String[value.size()]);
getCuentas2().setModel(new JComboBox(values).getModel());
}
if ((event.getActionCommand().equals("cuentas"))){
for (String key: theMap2().keySet())
{
lool=(String) getCuentas2().getSelectedItem();
if (lool.equals(key)){
answer = ((Map<String,Set><String>>) theMap2()).get( key );
}
}
things=(String[]) value.toArray(new String[value.size()]);
getTraders().setModel(new JComboBox(things).getModel());
}
}
}