@@ -72,6 +72,13 @@ public class SearchBook extends JFrame {
7272 JCheckBox [] jcb = new JCheckBox [10 ];
7373 private final ButtonGroup buttonGroup_1 = new ButtonGroup ();
7474 private final ButtonGroup buttonGroup_2 = new ButtonGroup ();
75+ JRadioButton headerRadioButton ;
76+ JRadioButton recentRadioButton ;
77+ JRadioButton gradeRadioButton ;
78+ JRadioButton popularityRadioButton ;
79+ JRadioButton canborrowRadioButton ;
80+ JRadioButton borrowingNewRadioButton ;
81+ List <RowSorter .SortKey > sortKeys ;
7582 private int t = 0 ;
7683 private Main mainFrame ;
7784 private UserInfo userInfoFrame ;
@@ -278,6 +285,7 @@ public void windowClosing(WindowEvent e) {
278285 "SELECT BOOK_TITLE, BOOK_AUTHOR, BOOK_PUB, BOOK_CATEGORY, BOOK_ISBN, BOOK_GRADE, BOOK_RENT_COUNT, BOOK_APPEND_DATE FROM BOOK WHERE BOOK_PRE = TRUE;" );
279286 set_table (rs );
280287 setTrs ();
288+ setFilter ();
281289 } catch (SQLException e1 ) {
282290 e1 .printStackTrace ();
283291 System .out .println ("도서 검색창 테이블 구성중 SQL 실행 에러" );
@@ -300,6 +308,7 @@ public void windowClosing(WindowEvent e) {
300308 "SELECT BOOK_TITLE, BOOK_AUTHOR, BOOK_PUB, BOOK_CATEGORY, BOOK_ISBN, BOOK_GRADE, BOOK_RENT_COUNT, BOOK_APPEND_DATE FROM BOOK WHERE BOOK_PRE = TRUE;" );
301309 set_table (rs );
302310 setTrs ();
311+ setFilter ();
303312 } catch (SQLException e1 ) {
304313 e1 .printStackTrace ();
305314 System .out .println ("도서 검색창 테이블 구성중 SQL 실행 에러" );
@@ -420,6 +429,8 @@ public void windowClosing(WindowEvent e) {
420429 jcb [7 ].setFont (new Font ("한컴산뜻돋움" , Font .PLAIN , 12 ));
421430 jcb [7 ].setBounds (8 , 204 , 107 , 23 );
422431 panel_2 .add (jcb [7 ]);
432+
433+
423434
424435
425436
@@ -458,10 +469,10 @@ public void windowClosing(WindowEvent e) {
458469
459470
460471
461- List < RowSorter . SortKey > sortKeys = new ArrayList <>();
472+ sortKeys = new ArrayList <>();
462473
463474 //제목순 라디오버튼
464- JRadioButton headerRadioButton = new JRadioButton ("\uC81C \uBAA9 \uC21C " );
475+ headerRadioButton = new JRadioButton ("\uC81C \uBAA9 \uC21C " );
465476
466477 buttonGroup_1 .add (headerRadioButton );
467478 headerRadioButton .addItemListener (new ItemListener () {
@@ -484,7 +495,7 @@ public void itemStateChanged(ItemEvent e) {
484495 panel_2 .add (headerRadioButton );
485496
486497 // 최신순 라디오버튼
487- JRadioButton recentRadioButton = new JRadioButton ("\uCD5C \uC2E0 \uC21C " );
498+ recentRadioButton = new JRadioButton ("\uCD5C \uC2E0 \uC21C " );
488499 recentRadioButton .addItemListener (new ItemListener () {
489500 public void itemStateChanged (ItemEvent e ) {
490501 if (e .getStateChange () == ItemEvent .SELECTED ) {
@@ -504,7 +515,7 @@ public void itemStateChanged(ItemEvent e) {
504515 panel_2 .add (recentRadioButton );
505516
506517 // 인기순 라디오버튼
507- JRadioButton popularityRadioButton = new JRadioButton ("\uC778 \uAE30 \uC21C " );
518+ popularityRadioButton = new JRadioButton ("\uC778 \uAE30 \uC21C " );
508519 popularityRadioButton .addItemListener (new ItemListener () {
509520 public void itemStateChanged (ItemEvent e ) {
510521 if (e .getStateChange () == ItemEvent .SELECTED ) {
@@ -521,9 +532,11 @@ public void itemStateChanged(ItemEvent e) {
521532 popularityRadioButton .setFont (new Font ("한컴산뜻돋움" , Font .PLAIN , 12 ));
522533 popularityRadioButton .setBounds (12 , 316 , 113 , 23 );
523534 panel_2 .add (popularityRadioButton );
535+
536+
524537
525538 // 평점순 라디오 버튼
526- JRadioButton gradeRadioButton = new JRadioButton ("\uD3C9 \uC810 \uC21C " );
539+ gradeRadioButton = new JRadioButton ("\uD3C9 \uC810 \uC21C " );
527540 gradeRadioButton .addItemListener (new ItemListener () {
528541 public void itemStateChanged (ItemEvent e ) {
529542 if (e .getStateChange () == ItemEvent .SELECTED ) {
@@ -548,7 +561,7 @@ public void itemStateChanged(ItemEvent e) {
548561 panel_2 .add (canBorrowLabel );
549562
550563 // 대출가능 라디오버튼
551- JRadioButton canborrowRadioButton = new JRadioButton ("\uB300 \uCD9C \uAC00 \uB2A5 " );
564+ canborrowRadioButton = new JRadioButton ("\uB300 \uCD9C \uAC00 \uB2A5 " );
552565
553566 //대출 가능 필터링 이벤트
554567 canborrowRadioButton .addItemListener (new ItemListener () {
@@ -564,14 +577,18 @@ public void itemStateChanged(ItemEvent e) {
564577 combineOrAndFilters ();
565578 }
566579 });
580+
581+
582+
583+
567584 canborrowRadioButton .setBackground (Color .WHITE );
568585 buttonGroup_2 .add (canborrowRadioButton );
569586 canborrowRadioButton .setFont (new Font ("한컴산뜻돋움" , Font .PLAIN , 12 ));
570587 canborrowRadioButton .setBounds (12 , 428 , 113 , 23 );
571588 panel_2 .add (canborrowRadioButton );
572589
573590 // 대출중 라디오버튼
574- JRadioButton borrowingNewRadioButton = new JRadioButton ("\uB300 \uCD9C \uC911 " );
591+ borrowingNewRadioButton = new JRadioButton ("\uB300 \uCD9C \uC911 " );
575592 borrowingNewRadioButton .addItemListener (new ItemListener () {
576593 public void itemStateChanged (ItemEvent e ) {
577594 if (e .getStateChange () == ItemEvent .SELECTED ) {
@@ -686,6 +703,39 @@ public void search_event() {
686703 System .out .println ("SQL 실행 에러" );
687704 }
688705 }
706+
707+
708+ public void setFilter () {
709+ if (canborrowRadioButton .isSelected ()) {
710+ borrowFilter .put (canborrowRadioButton .getText (), RowFilter .regexFilter (canborrowRadioButton .getText (), 4 )); //테이블 5행에 있는 대출여부명을 필터항목에 추가시켜 해시맵에 삽입
711+ }else if (borrowingNewRadioButton .isSelected ()) {
712+ borrowFilter .put (borrowingNewRadioButton .getText (), RowFilter .regexFilter (borrowingNewRadioButton .getText (), 4 )); //테이블 5행에 있는 대출여부명을 필터항목에 추가시켜 해시맵에 삽입
713+ }
714+
715+ for (int i = 0 ; i < 8 ; i ++) {
716+ if (jcb [i ].isSelected ()) {
717+ categoryFilter .put (jcb [i ].getText (), RowFilter .regexFilter (jcb [i ].getText (), 3 )); //테이블 3행에 있는 카테고리명을 필터항목에 추가시켜 해시맵에 삽입
718+ checkNum ++;
719+ }
720+ combineOrAndFilters ();
721+
722+ if (headerRadioButton .isSelected ()) {
723+ sortKeys .add (new RowSorter .SortKey (0 , SortOrder .ASCENDING ));
724+ }
725+ else if (recentRadioButton .isSelected ()) {
726+ sortKeys .add (new RowSorter .SortKey (7 , SortOrder .DESCENDING ));
727+ }else if (popularityRadioButton .isSelected ()) {
728+ sortKeys .add (new RowSorter .SortKey (6 , SortOrder .DESCENDING ));
729+ }else if (gradeRadioButton .isSelected ()) {
730+ sortKeys .add (new RowSorter .SortKey (5 , SortOrder .DESCENDING ));
731+ }
732+
733+ trs .setSortKeys (sortKeys );
734+
735+
736+
737+ }
738+ }
689739
690740 // ResultSet을 받아 테이블 재구성하는 함수
691741 public void set_table (ResultSet rs ) throws SQLException {
0 commit comments