44import javax .swing .*;
55
66import java .awt .*;
7+ import java .awt .event .ActionEvent ;
8+ import java .awt .event .ActionListener ;
79import java .awt .event .MouseAdapter ;
810import java .awt .event .MouseEvent ;
911import java .awt .image .BufferedImage ;
@@ -93,10 +95,11 @@ public class DlgAddBooks extends JDialog {
9395 this .setLayout (null );
9496 //this.setVisible(true); //remove by Li Huang 2014.8.15 to make it can be shown in Modal way
9597
96- choosePic .addMouseListener (new MouseAdapter () // choose a picture
98+ //choosePic.addMouseListener(new MouseAdapter() // choose a picture
99+ choosePic .addActionListener (new ActionListener () // choose a picture
97100 {
98- public void mouseClicked ( MouseEvent me ) {
99-
101+ @ Override
102+ public void actionPerformed ( ActionEvent e ) {
100103 // System.out.println("fffff"); //test1
101104 FileDialog readFD = new FileDialog (new Frame (),
102105 "Choose a file" , FileDialog .LOAD );
@@ -112,10 +115,11 @@ public void mouseClicked(MouseEvent me) {
112115 }
113116 });
114117
115- add .addMouseListener (new MouseAdapter () // add new book
118+ //add.addMouseListener(new MouseAdapter() // add new book
119+ add .addActionListener (new ActionListener () // add new book
116120 {
117- public void mouseClicked ( MouseEvent me ) {
118-
121+ @ Override
122+ public void actionPerformed ( ActionEvent e ) {
119123 Validator test = new Validator ();
120124
121125 String currentISBN = jtf_isbn .getText ();
@@ -173,7 +177,7 @@ public void mouseClicked(MouseEvent me) {
173177// new reName().rename(picDirectory, picFileName,
174178// currentISBN);
175179 library .copyBookImage (picDirectory , picFileName , currentISBN );
176- } catch (Exception e ) {
180+ } catch (Exception ex ) {
177181 // TODO Auto-generated catch block
178182 System .out .println ("No picture selected." );
179183 } finally {
@@ -184,18 +188,17 @@ public void mouseClicked(MouseEvent me) {
184188 }
185189
186190 }
187-
188191 else {
189192 JOptionPane .showMessageDialog (DlgAddBooks .this ,
190193 "Invaild book information!" , "Error" ,
191194 JOptionPane .ERROR_MESSAGE );
192195 }
193-
194- }// mouse clicked
196+ }
195197 });
196198
197- close .addMouseListener (new MouseAdapter () {
198- public void mouseClicked (MouseEvent me ) {
199+ close .addActionListener ( new ActionListener () {
200+ @ Override
201+ public void actionPerformed (ActionEvent e ) {
199202 //FrmAddBooks.this.setVisible(false); //modify by Li Huang. use dispose() to totally dispose this window
200203 DlgAddBooks .this .dispose ();
201204 }
0 commit comments