• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

点击jList中的某一项,却不能显示出该项对应的详细信息(JTextArea)的疑问

public abstract class Mainform extends JFrame{ protected JPanel pnlContent = null; protected JPanel pnlInformation = null; protected JPanel pnlButton = null; protected JPanel pnlTime = null;  protected JList jList = null; protected DefaultListModel model = null; protected ProductController productController = null;  protected Cart cart = null; protected JButton btnAdd = null;  protected JTextArea txtInform = null; protected JScrollPane scrollpnl = null;  public Mainform(){    this.setSize(new Dimension(800,600));  this.setBackground(Color.LIGHT_GRAY);  this.setLocationRelativeTo(null);  this.setTitle("Gourmet Coffee System");  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);    pnlContent = new JPanel();   pnlTime = new TimePanel();   pnlInformation = new JPanel();  pnlInformation.setBackground(Color.GRAY);   pnlButton = new JPanel();  pnlButton.setBackground(Color.white);   txtInform = new JTextArea(500,600);      setList();  this.add(pnlTime, BorderLayout.NORTH);  this.add(pnlContent,BorderLayout.WEST);  this.add(pnlButton,BorderLayout.SOUTH);    addButton(pnlButton);      showFrame(); }  private void showFrame() {  this.setVisible(true); }  public void setList(){    model = new DefaultListModel();  productController = new ProductController("information","Product.txt");  for(Product product: productController.readObject("information", "Product.txt")){   model.addElement(product.getCode());  }  jList = new JList(model);  jList.setPreferredSize(new Dimension(200,600));  pnlContent.add(jList);  setText(); }   public void setText(){  txtInform.setLineWrap(true);  txtInform.setEditable(false);  txtInform.setBackground(Color.blue);  jList.addListSelectionListener(new ListSelectionListener(){   @Override   public void valueChanged(ListSelectionEvent e) {    if(!jList.getValueIsAdjusting()){    /*     *监听过程中如果匹配,增加text内容      */    String code = jList.getSelectedValue();    ProductController productcontroller = new ProductController("information", "Product.txt");    ArrayList products =       productcontroller.readObject("information", "Product.txt");     for(Product product:products){      if(code == product.getCode()){       txtInform.setText(product.toString());         }     }    }   }  });  pnlInformation.add(txtInform);  this.add(pnlInformation,BorderLayout.CENTER); }    abstract void addButton(JPanel pnlButton);参数:
jList列出目录
jTextArea
我希望JList在鼠标点击的时候能显示商品的详细信息,详细信息用JTextArea等表示。为此设置了一个事件ListSelectionListener在内部类里面读取商品文件的信息(读取文件的函数返回ArrayList)查看是否有匹配(通过比较商品的属性---Code是否一致的方式)
我认为我的逻辑上应该是没有问题的。在  txtInform.setText(product.toString());这句设了断点以后似乎发现有线程的冲突,还有空指针异常……?菜鸟一个,不懂怎么解决此类问题…跪求大佬帮忙。


这是设了断点以后发现的问题:




刚刚step into 一步以后就显示了这个…





感谢!!!!

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!