JListSample.java
JListPanel.java
JListDo.java
Because this problem set contains ideas you are likely not familiar with, we do not assume that the readers have prior knowledge of these topics. Indeed, the purpose of the question set is to ask the readers to read completely new programs and suggest some ways to approach them. (Note that this by no means implies that a reader's approach is incorrect, or that the suggested approach is better.) Please do not read the source code until being instructed by the questions. Also, do not worry if you do not fully understand a question or a solution.
As mentioned before, this question set involves many advanced topics. A detailed discussion of these topics are beyond the scope of this exercise. Interested readers are encouraged to consult the Java online documentation.
The Java API provides classes for creating graphical user interfaces, graphics, and images.
In this problem set, we will refer to these classes as GUI classes
for simplicity. Also item and row are used
interchangeably here to refer to options in a list.
Download files: JListSample.java, JListPanel.java, JListDo.java
Areas: Applet
|
|
JListSample.java |
|
View full source |
|
|
JListPanel.java |
|
View full source |
|
|
JListDo.java |
|
View full source |
| Question 1 |
| Please read JListSample.java.
What methods from the JList class are used in JListSample.java? How can you tell that they are from JList? |
| Question 2 |
| Can you guess the functionality of
the method below?
setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| Question 3 |
| Can you guess the functionality of setVisibleRowCount(2)? |
| Question 4 |
| In the init() method, we have the statement
this.getContentPane().add(this.getList());
Is the this in this.getContentPane() used the same way as
the this in this.getList()? |
| Question 5 |
| Are all the packages in the import list necessary? |
| Question 6 |
| Does your prior knowledge in programming help you to understand JListSample? Which kind of programming knowledge is it? Writing GUI code using Java? Writing GUI code using another language? Programming in general? Which parts of JListSample do you find particularly hard to comprehend? |
| Question 7 |
| Please read JListPanel.java.
Can you guess what JListPanel does? How much can you conclude after reading the program only ONCE? |
| Question 8 |
| Does your understanding of JListSample help? |
| Question 9 |
| What is GridLayout? Can you tell its nature (a class, a method, etc.) by reading the code? |
| Question 10 |
| Run JListSample and JListPanel. Compare the lists in them. The lists in JListPanel have scroll bars. Which part of the code in JListPanel.java causes this difference? |
| Question 11 |
| Do JListSample and JListPanel respond to user input? |
| Question 12 |
| Please read JListDo.java.
Unlike the first two programs, JListDo is interactive, that is it responds to user input. Can you guess which part of the code provides this functionality? |
| Question 13 |
| Can you guess which GUI component takes the user input? |
| Question 14 |
| What does addButton() do? Is the button actually added to the applet? |
| Question 15 |
| How many times is the method addButton() called? What does it accomplish each time? Is it necessary to call it in init()? |
| Question 16 |
| Assume you were a programmer that was assigned the task of debugging an online shopping cart program implemented in Java. All of JListSample, JListPanel, and JListDo were part of the online program. If the three programs appeared to be unrelated to the errors in the main program, what level of understanding would you aim at? If the three programs appeared to cause the malfunction of the main program, what level of understanding would you aim at? |
