12
12
import java .awt .Dimension ;
13
13
import java .awt .event .ActionEvent ;
14
14
import java .awt .event .ActionListener ;
15
+ import java .awt .event .MouseAdapter ;
16
+ import java .awt .event .MouseEvent ;
15
17
import java .util .List ;
16
18
import javax .swing .JButton ;
17
19
import javax .swing .JFrame ;
@@ -30,6 +32,7 @@ public class CourseListWindow extends JPanel {
30
32
private static JFrame frame ;
31
33
private final JList <CourseCard > courses ;
32
34
private PreferencesPanel prefPanel ;
35
+ private final JButton button ;
33
36
34
37
public CourseListWindow (List <Course > courses , PreferencesPanel prefPanel ) {
35
38
this .prefPanel = prefPanel ;
@@ -40,8 +43,8 @@ public CourseListWindow(List<Course> courses, PreferencesPanel prefPanel) {
40
43
this .courses = new JList <>(courseCards );
41
44
this .courses .setSelectionMode (ListSelectionModel .SINGLE_SELECTION );
42
45
setLayout (new BorderLayout ());
43
- JButton button = new JButton ("Select" );
44
- button .addActionListener (new SelectCourseListener (this ));
46
+ this . button = new JButton ("Select" );
47
+ this . button .addActionListener (new SelectCourseListener (this ));
45
48
46
49
this .courses .setCellRenderer (new CourseCellRenderer ());
47
50
this .courses .setVisibleRowCount (4 );
@@ -53,9 +56,16 @@ public CourseListWindow(List<Course> courses, PreferencesPanel prefPanel) {
53
56
this .courses .setBackground (new Color (242 , 241 , 240 ));
54
57
55
58
this .courses .setSelectedIndex (setDefaultSelectedIndex ());
56
-
59
+ this .courses .addMouseListener (new MouseAdapter () {
60
+ @ Override
61
+ public void mouseClicked (MouseEvent event ) {
62
+ if (event .getClickCount () >= 2 ) {
63
+ button .doClick ();
64
+ }
65
+ }
66
+ });
57
67
add (pane , BorderLayout .NORTH );
58
- add (button , BorderLayout .SOUTH );
68
+ add (this . button , BorderLayout .SOUTH );
59
69
}
60
70
61
71
public static void display (PreferencesPanel prefPanel ) throws Exception {
0 commit comments