java高手们:
请帮帮忙! 问题描述:我用java实现的一个学生管理系统!是3个下拉框,通过年级找相应的系,再通过系找相应的班。出现的问题是,我想实现这样的功能:我选择年级的时候,自动将相应的系显示出来。我从数据库取相应系的方法完全正确,就是事件监听写的不对。不知道哪错了!高手帮帮忙改改!关键的代码如下:
/**
* This method initializes jComboBoxGrade
*
* @return javax.swing.JComboBox
*/
//得到年级
private JComboBox getJComboBoxGrade()
{
if (jComboBoxGrade == null)
{
jComboBoxGrade = new JComboBox();
jComboBoxGrade.setBounds(new Rectangle(230, 277, 123, 27));
GetInterface getInterface = new GetInterface();
try
{
Sign mySign = getInterface.getMySign();
ArrayList gradeNameArrayList=mySign.queryGradeName();
for(int i=0;i<gradeNameArrayList.size();i++)
{
jComboBoxGrade.addItem(gradeNameArrayList.get(i));
}
jComboBoxGrade.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent e)
{
selectedGrade = getJComboBoxGrade().getSelectedItem().toString();
getJComboBoxDep();
jComboBoxDep.setVisible( true );
}
});
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
return jComboBoxGrade;
}
//得到相应系
private JComboBox getJComboBoxDep()
{
if (jComboBoxDep == null)
{
jComboBoxDep = new JComboBox();
jComboBoxDep.setBounds(new Rectangle(226, 316, 122, 27));
GetInterface getInterface = new GetInterface();
try
{
System.out.println("bbbbbb" + selectedGrade );
Sign mySign = getInterface.getMySign();
ArrayList depNameArrayList=mySign.queryDepName( selectedGrade );
for(int i=0;i<depNameArrayList.size();i++)
{
jComboBoxDep.addItem(depNameArrayList.get(i));
}
jComboBoxDep.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent e)
{
jComboBoxStuClass.setVisible( true );
}
});
}
catch(Exception e2)
{
e2.printStackTrace();
}
}
return jComboBoxDep;
}
//得到相应班
private JComboBox getJComboBoxStuClass()
{
if (jComboBoxStuClass == null)
{
jComboBoxStuClass = new JComboBox();
jComboBoxStuClass.setSize(new Dimension(130, 25));
jComboBoxStuClass.setLocation(new Point(222, 357));
GetInterface getInterface = new GetInterface();
try
{
Sign mySign = getInterface.getMySign();
ArrayList classNameArrayList=mySign.queryAllClassName( getJComboBoxDep().getSelectedItem().toString());
for(int i=0;i<classNameArrayList.size();i++)
{
jComboBoxStuClass.addItem(classNameArrayList.get(i));
}
}
catch (Exception e3)
{
// TODO 自动生成 catch 块
e3.printStackTrace();
}
}
return jComboBoxStuClass;
}
请帮帮忙! 问题描述:我用java实现的一个学生管理系统!是3个下拉框,通过年级找相应的系,再通过系找相应的班。出现的问题是,我想实现这样的功能:我选择年级的时候,自动将相应的系显示出来。我从数据库取相应系的方法完全正确,就是事件监听写的不对。不知道哪错了!高手帮帮忙改改!关键的代码如下:
/**
* This method initializes jComboBoxGrade
*
* @return javax.swing.JComboBox
*/
//得到年级
private JComboBox getJComboBoxGrade()
{
if (jComboBoxGrade == null)
{
jComboBoxGrade = new JComboBox();
jComboBoxGrade.setBounds(new Rectangle(230, 277, 123, 27));
GetInterface getInterface = new GetInterface();
try
{
Sign mySign = getInterface.getMySign();
ArrayList gradeNameArrayList=mySign.queryGradeName();
for(int i=0;i<gradeNameArrayList.size();i++)
{
jComboBoxGrade.addItem(gradeNameArrayList.get(i));
}
jComboBoxGrade.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent e)
{
selectedGrade = getJComboBoxGrade().getSelectedItem().toString();
getJComboBoxDep();
jComboBoxDep.setVisible( true );
}
});
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
return jComboBoxGrade;
}
//得到相应系
private JComboBox getJComboBoxDep()
{
if (jComboBoxDep == null)
{
jComboBoxDep = new JComboBox();
jComboBoxDep.setBounds(new Rectangle(226, 316, 122, 27));
GetInterface getInterface = new GetInterface();
try
{
System.out.println("bbbbbb" + selectedGrade );
Sign mySign = getInterface.getMySign();
ArrayList depNameArrayList=mySign.queryDepName( selectedGrade );
for(int i=0;i<depNameArrayList.size();i++)
{
jComboBoxDep.addItem(depNameArrayList.get(i));
}
jComboBoxDep.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent e)
{
jComboBoxStuClass.setVisible( true );
}
});
}
catch(Exception e2)
{
e2.printStackTrace();
}
}
return jComboBoxDep;
}
//得到相应班
private JComboBox getJComboBoxStuClass()
{
if (jComboBoxStuClass == null)
{
jComboBoxStuClass = new JComboBox();
jComboBoxStuClass.setSize(new Dimension(130, 25));
jComboBoxStuClass.setLocation(new Point(222, 357));
GetInterface getInterface = new GetInterface();
try
{
Sign mySign = getInterface.getMySign();
ArrayList classNameArrayList=mySign.queryAllClassName( getJComboBoxDep().getSelectedItem().toString());
for(int i=0;i<classNameArrayList.size();i++)
{
jComboBoxStuClass.addItem(classNameArrayList.get(i));
}
}
catch (Exception e3)
{
// TODO 自动生成 catch 块
e3.printStackTrace();
}
}
return jComboBoxStuClass;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货