简体   繁体   English

选择一个JList项,该项将向JTextField显示信息

[英]Select a JList item which will display info to JTextField

I have two classes. 我有两节课。 A Book class which contains the title, author, and isbn. 一个Book类,其中包含标题,作者和isbn。 The second class is the driver class called Library. 第二类是称为库的驱动程序类。

The GUI contains a jlist and 3 text fields. GUI包含一个jlist和3个文本字段。 The jlist is an arraylist of items from the Book class (title, author, isbn). jlist是Book类(标题,作者,isbn)中各项的数组列表。 When one item is selected from the jlist the text fields show the: title, author, and isbn of the item. 从jlist中选择一个项目时,文本字段将显示该项目的标题,作者和isbn。

My problem is how do I have the selected jlist item display the info in the textfields? 我的问题是如何让选定的jlist项目在文本字段中显示信息? I just need someone to point me into the right direction, I'm trying to understand this logically and then implement it into code. 我只需要有人指出我正确的方向,我试图从逻辑上理解这一点,然后将其实现为代码。

*The Jlist items contain: Book 1, Book 2, Book 3 so if I select Book 1 it will display Harry Potter and the Goblet of Fire, JK Rowling, 24325543. * Jlist项目包括:Book 1,Book 2,Book 3,因此,如果我选择Book 1,它将显示Harry Potter and the Goblet of Fire,JK Rowling,24325543。

如果使用的是JList,则可以使用getSelectedIndex()获取所选项目的索引,或者使用getSelectedValue()获取对象的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM