java更新list_java JList的更新

这篇博客讨论了在Java Swing应用中遇到的问题:当点击查询按钮并选择一个选项后,再点击登记按钮,两个相关JDialog同时弹出。作者详细描述了事件监听器的代码,并寻求解决方案,尝试初始化JList的索引但未成功。问题集中在如何避免多个对话框的误触发。
摘要由CSDN通过智能技术生成

————————————-这是查询按钮的————————————btn_xs_cx.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){Strings[]={"以学号为...

————————————-这是查询按钮的————————————

btn_xs_cx.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String s[]={"以学号为关键字查询某学生基本信息","以学号为关键字查询某学生卫生成绩"};

list.setListData(s);

list.addListSelectionListener(

new ListSelectionListener() {

public void valueChanged( ListSelectionEvent event )

{ if(list.getValueIsAdjusting() )

{stop:

switch(list.getSelectedIndex()){

case 0 : {JDialog xs_cxxsjbxx =new xs_cxxsjbxx();

xs_cxxsjbxx.setVisible(true);

break stop;}

case 1 : {JDialog xs_cxxswscj =new xs_cxxswscj();

xs_cxxswscj.setVisible(true);

break stop;}

————————————这是登记按钮的————————————

btn_xs_dj.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String s[]={"对新生进本信息进行登记"};

list.setListData(s);

list.addListSelectionListener(

new ListSelectionListener() {

public void valueChanged( ListSelectionEvent event )

{

if(list.getValueIsAdjusting() )

{stop1:

switch(list.getSelectedIndex()){

case 0 : {JDialog xs_xsdj =new xs_xsdj();

xs_xsdj.setVisible(true);

break stop1;}

——————————————

问题是,如果我点完查询按钮,然后在JList中选“以学号为关键字查询某学生基本信息”,没问题

然后我再点新生登记按钮,然后在JList中选“对新生进本信息进行登记”,不仅混弹出JDialog xs_xsdj,还会弹出JDialog xs_cxxsjbxx。怎么解决呢?

有没有什么办法能初始化JList的索引的还是有其他的办法?

按照你说的,改的switch

代码在这里。结果还是一样啊- -。。

switch(s[list.getSelectedIndex()]){

case "以学号为关键字查询某学生基本信息":

JDialog xs_cxxsjbxx =new xs_cxxsjbxx();

xs_cxxsjbxx.setVisible(true);

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值