Your SlideShare is downloading. ×
-923925-923925<br />WARNINGBUKU INI HANYA UNTUK PEMBACA YANG TELAH MENGENAL STANDAR PEMBUATAN APLIKASI MENGGUNAKAN SWING. ...
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Java Swing Make Over
Upcoming SlideShare
Loading in...5
×

Java Swing Make Over

2,353

Published on

Belajar Java Swing Make Over

Published in: Technology, Business
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,353
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Transcript of "Java Swing Make Over"

  1. 1. -923925-923925<br />WARNINGBUKU INI HANYA UNTUK PEMBACA YANG TELAH MENGENAL STANDAR PEMBUATAN APLIKASI MENGGUNAKAN SWING. <br />Daftar Isi<br /> TOC o "1-3" h z u Daftar Isi PAGEREF _Toc304103413 h 3Daftar Gambar PAGEREF _Toc304103414 h 7Persiapan PAGEREF _Toc304103415 h 13Swing dan AWT PAGEREF _Toc304103416 h 13Project SwingMakeOver PAGEREF _Toc304103417 h 13Project SwingMakeOver dan NetBeans PAGEREF _Toc304103418 h 13Project SwingMakeOver dan Eclipse PAGEREF _Toc304103419 h 15JPanel PAGEREF _Toc304103420 h 19Pemanasan PAGEREF _Toc304103421 h 19Memanipulasi paintComponent() PAGEREF _Toc304103422 h 19Menggambar Bentuk PAGEREF _Toc304103423 h 19Mewarnai Bentuk dengan Solid Color PAGEREF _Toc304103424 h 29Mewarnai Bentuk dengan Gradient Color PAGEREF _Toc304103425 h 37Antialiasing PAGEREF _Toc304103426 h 44Alpha PAGEREF _Toc304103427 h 48Color PAGEREF _Toc304103428 h 48Composite PAGEREF _Toc304103429 h 50Image PAGEREF _Toc304103430 h 51Efek Kaca PAGEREF _Toc304103431 h 54Kesimpulan PAGEREF _Toc304103432 h 58JButton PAGEREF _Toc304103433 h 63Glass PAGEREF _Toc304103434 h 63Tombol Kotak Lancip PAGEREF _Toc304103435 h 63Tombol Kotak Luncul PAGEREF _Toc304103436 h 66Image PAGEREF _Toc304103437 h 69Mouse PAGEREF _Toc304103438 h 72Over PAGEREF _Toc304103439 h 72Press PAGEREF _Toc304103440 h 75Kesimpulan PAGEREF _Toc304103441 h 80JLabel PAGEREF _Toc304103442 h 81Drop Shadow Text PAGEREF _Toc304103443 h 81Clip Text PAGEREF _Toc304103444 h 83Gradient Text PAGEREF _Toc304103445 h 84JTextField PAGEREF _Toc304103446 h 86Shadow Text PAGEREF _Toc304103447 h 86Auto Complete Text PAGEREF _Toc304103448 h 89Manipulasi Background PAGEREF _Toc304103449 h 92Gradients PAGEREF _Toc304103450 h 92Image PAGEREF _Toc304103451 h 94Validasi Input PAGEREF _Toc304103452 h 96Kesimpulan PAGEREF _Toc304103453 h 98Pelajaran 7 JComboBox PAGEREF _Toc304103454 h 103Render PAGEREF _Toc304103455 h 103Background PAGEREF _Toc304103456 h 103Image PAGEREF _Toc304103457 h 106Kesimpulan PAGEREF _Toc304103458 h 109Pelajaran 8 JList PAGEREF _Toc304103459 h 115Render PAGEREF _Toc304103460 h 115Background PAGEREF _Toc304103461 h 115Image PAGEREF _Toc304103462 h 117Boolean PAGEREF _Toc304103463 h 118Number PAGEREF _Toc304103464 h 120Font PAGEREF _Toc304103465 h 122Model PAGEREF _Toc304103466 h 124Sorting PAGEREF _Toc304103467 h 124Filter PAGEREF _Toc304103468 h 128Kesimpulan PAGEREF _Toc304103469 h 131Pelajaran 9 JViewPort PAGEREF _Toc304103470 h 133JTextArea PAGEREF _Toc304103471 h 135Background Image PAGEREF _Toc304103472 h 135Glass PAGEREF _Toc304103473 h 139Pelajaran 10 JWindow PAGEREF _Toc304103474 h 142About Screen PAGEREF _Toc304103475 h 142Splash Screen PAGEREF _Toc304103476 h 144Kesimpulan PAGEREF _Toc304103477 h 147Pelajaran 11 JTree PAGEREF _Toc304103478 h 149Render PAGEREF _Toc304103479 h 149File and Folder PAGEREF _Toc304103480 h 149About Icon PAGEREF _Toc304103481 h 151Leaf Icon PAGEREF _Toc304103482 h 151Color PAGEREF _Toc304103483 h 153Background PAGEREF _Toc304103484 h 155Glass PAGEREF _Toc304103485 h 159Editor PAGEREF _Toc304103486 h 162JComboBox PAGEREF _Toc304103487 h 163JChekBox PAGEREF _Toc304103488 h 164Color PAGEREF _Toc304103489 h 166File PAGEREF _Toc304103490 h 169Yes No Editor PAGEREF _Toc304103491 h 172Kesimpulan PAGEREF _Toc304103492 h 178Pelajaran 12 JTable PAGEREF _Toc304103493 h 179Render PAGEREF _Toc304103494 h 179Color PAGEREF _Toc304103495 h 179Gradient PAGEREF _Toc304103496 h 181NetBeans PAGEREF _Toc304103497 h 183Editor PAGEREF _Toc304103498 h 200JComboBox PAGEREF _Toc304103499 h 200JChekBox PAGEREF _Toc304103500 h 202Color PAGEREF _Toc304103501 h 210Spinner PAGEREF _Toc304103502 h 213Custom Editor PAGEREF _Toc304103503 h 216Other PAGEREF _Toc304103504 h 220Sorter PAGEREF _Toc304103505 h 220Filter PAGEREF _Toc304103506 h 224Microsoft Excel dan OpenOffice Calc PAGEREF _Toc304103507 h 227HTML PAGEREF _Toc304103508 h 241Kesimpulan PAGEREF _Toc304103509 h 245Pelajaran 13 JTextPane PAGEREF _Toc304103510 h 246Highlight PAGEREF _Toc304103511 h 246Pelajaran 14 GlassPane PAGEREF _Toc304103512 h 249Gradient Glass PAGEREF _Toc304103513 h 249Block Event PAGEREF _Toc304103514 h 251Warning GlassPane PAGEREF _Toc304103515 h 255GlassPane Transition 1 PAGEREF _Toc304103516 h 257GlassPane Transition 2 PAGEREF _Toc304103517 h 260GlassPane dan JTable PAGEREF _Toc304103518 h 263Dragging PAGEREF _Toc304103519 h 265File PAGEREF _Toc304103520 h 266Image PAGEREF _Toc304103521 h 270Container PAGEREF _Toc304103522 h 275Show Message PAGEREF _Toc304103523 h 275GlassDialog PAGEREF _Toc304103524 h 279ProgressBar PAGEREF _Toc304103525 h 282ProgressBar2 PAGEREF _Toc304103526 h 285Kesimpulan PAGEREF _Toc304103527 h 287Pelajaran 15 JLayeredPane PAGEREF _Toc304103528 h 288GlassPane PAGEREF _Toc304103529 h 293Kesimpulan PAGEREF _Toc304103530 h 296Sample Swing Make Over PAGEREF _Toc304103531 h 297Lampiran PAGEREF _Toc304103532 h 301Instalasi PAGEREF _Toc304103533 h 3017-Zip PAGEREF _Toc304103534 h 301JDK 1.6 PAGEREF _Toc304103535 h 303Java Doc PAGEREF _Toc304103536 h 307NetBeans 6.0 PAGEREF _Toc304103537 h 308Eclipse 3.3 PAGEREF _Toc304103538 h 312Tentang Penulis PAGEREF _Toc304103539 h 315<br />Daftar Gambar<br /> TOC h z c "Gambar " Gambar 1 Menu Libraries PAGEREF _Toc302718467 h 15<br />Gambar 2 Library Manager PAGEREF _Toc302718468 h 15<br />Gambar 3 New Library PAGEREF _Toc302718469 h 16<br />Gambar 4 Add Jar / Folder PAGEREF _Toc302718470 h 16<br />Gambar 5 Browse Jar / Folder PAGEREF _Toc302718471 h 16<br />Gambar 6 Library Manager PAGEREF _Toc302718472 h 17<br />Gambar 7 Project Properties PAGEREF _Toc302718473 h 17<br />Gambar 8 Project Properties PAGEREF _Toc302718474 h 18<br />Gambar 9 Add Library PAGEREF _Toc302718475 h 18<br />Gambar 10 Project Properties PAGEREF _Toc302718476 h 19<br />Gambar 11 Project Explorer PAGEREF _Toc302718477 h 19<br />Gambar 12 Menu Preferences PAGEREF _Toc302718478 h 20<br />Gambar 13 Preferences PAGEREF _Toc302718479 h 21<br />Gambar 14 New User Library PAGEREF _Toc302718480 h 21<br />Gambar 15 Preferences PAGEREF _Toc302718481 h 22<br />Gambar 16 Jar Selection PAGEREF _Toc302718482 h 23<br />Gambar 17 Menu Add Libraries PAGEREF _Toc302718483 h 23<br />Gambar 18 Add Library PAGEREF _Toc302718484 h 24<br />Gambar 19 Add Library PAGEREF _Toc302718485 h 24<br />Gambar 20 Package Explorer PAGEREF _Toc302718486 h 25<br />Gambar 21 Menu Open Project PAGEREF _Toc302718487 h 25<br />Gambar 22 Open Project PAGEREF _Toc302718488 h 26<br />Gambar 23 Project Explorer PAGEREF _Toc302718489 h 26<br />Gambar 24 Menu Import PAGEREF _Toc302718490 h 27<br />Gambar 25 Import PAGEREF _Toc302718491 h 27<br />Gambar 26 Import PAGEREF _Toc302718492 h 28<br />Gambar 27 Browse For Folder PAGEREF _Toc302718493 h 28<br />Gambar 28 Import PAGEREF _Toc302718494 h 29<br />Gambar 29 Package Explorer PAGEREF _Toc302718495 h 29<br />Gambar 30 PanelKotak.java PAGEREF _Toc302718496 h 52<br />Gambar 31 PanelKotak2.java PAGEREF _Toc302718497 h 53<br />Gambar 32 PanelRound.java PAGEREF _Toc302718498 h 54<br />Gambar 33 PanelRound2.java PAGEREF _Toc302718499 h 55<br />Gambar 34 PanelLingkaran .java PAGEREF _Toc302718500 h 57<br />Gambar 35 PanelLingkaran2.java PAGEREF _Toc302718501 h 58<br />Gambar 36 PanelBentukLain.java PAGEREF _Toc302718502 h 59<br />Gambar 37 PanelKotak.java PAGEREF _Toc302718503 h 61<br />Gambar 38 PanelKotak2.java PAGEREF _Toc302718504 h 62<br />Gambar 39 PanelRound.java PAGEREF _Toc302718505 h 63<br />Gambar 40 PanelRound2.java PAGEREF _Toc302718506 h 64<br />Gambar 41 PanelLingkaran.java PAGEREF _Toc302718507 h 66<br />Gambar 42 PanelLingkaran2.java PAGEREF _Toc302718508 h 67<br />Gambar 43 PanelBentukLain.java PAGEREF _Toc302718509 h 68<br />Gambar 44 PanelLinear.java PAGEREF _Toc302718510 h 70<br />Gambar 45 PanelRadial.java PAGEREF _Toc302718511 h 72<br />Gambar 46 PanelLinearMultiple.java PAGEREF _Toc302718512 h 73<br />Gambar 47 PanelRadialMultiple.java PAGEREF _Toc302718513 h 75<br />Gambar 48 PanelLingkaran sebelum antialiasing PAGEREF _Toc302718514 h 75<br />Gambar 49 PanelLingkaranAntialiashing.java PAGEREF _Toc302718515 h 77<br />Gambar 50 PanelLinear sebelum antialiasing PAGEREF _Toc302718516 h 77<br />Gambar 51 PanelLinearMultipleAntialiashing.java PAGEREF _Toc302718517 h 79<br />Gambar 52 PanelAlpha.java PAGEREF _Toc302718518 h 80<br />Gambar 53 PanelComposite.java PAGEREF _Toc302718519 h 82<br />Gambar 54 PanelImage.java PAGEREF _Toc302718520 h 83<br />Gambar 55 PanelImage2.java PAGEREF _Toc302718521 h 85<br />Gambar 56 PanelImageKaca.java PAGEREF _Toc302718522 h 87<br />Gambar 57 PanelImageKaca2.java PAGEREF _Toc302718523 h 89<br />Gambar 58 MyOpenOffice Login PAGEREF _Toc302718524 h 90<br />Gambar 59 MyOpenOffice Menu PAGEREF _Toc302718525 h 90<br />Gambar 60 MyOpenOffice Contact PAGEREF _Toc302718526 h 91<br />Gambar 61 PanelEfect.java PAGEREF _Toc302718527 h 93<br />Gambar 62 ButtonGlass.java PAGEREF _Toc302718528 h 95<br />Gambar 63 ButtonGlass2.java PAGEREF _Toc302718529 h 97<br />Gambar 64 ButtonGlassRound.java PAGEREF _Toc302718530 h 98<br />Gambar 65 ButtonGlassRound2.java PAGEREF _Toc302718531 h 100<br />Gambar 66 ButtonImage.java PAGEREF _Toc302718532 h 102<br />Gambar 67 ButtonImage menggunakan glass diatas PAGEREF _Toc302718533 h 103<br />Gambar 68 ButtonOver.java saat mouse exit PAGEREF _Toc302718534 h 106<br />Gambar 69 ButtonOver.java saat mouse over PAGEREF _Toc302718535 h 106<br />Gambar 70 ButtonOverPress.java saat mouse exit PAGEREF _Toc302718536 h 110<br />Gambar 71 ButtonOverPress.java saat mouse over PAGEREF _Toc302718537 h 110<br />Gambar 72 ButtonOverPress.java saat mouse press PAGEREF _Toc302718538 h 110<br />Gambar 73 LabelDropShadow.java PAGEREF _Toc302718539 h 113<br />Gambar 74 LabelClip.java PAGEREF _Toc302718540 h 115<br />Gambar 75 LabelGradient.java PAGEREF _Toc302718541 h 116<br />Gambar 76 Contoh Shadow Text PAGEREF _Toc302718542 h 118<br />Gambar 77 TextFieldShadowText.java saat shadow text terlihat PAGEREF _Toc302718543 h 121<br />Gambar 78 TextFieldShadowText.java saat user menginputkan teks PAGEREF _Toc302718544 h 121<br />Gambar 79 TextFieldAutoComplete.java PAGEREF _Toc302718545 h 123<br />Gambar 80 TextFieldAutoComplete.java saat user menginputkan teks PAGEREF _Toc302718546 h 124<br />Gambar 81 TextFieldAutoComplete untuk website PAGEREF _Toc302718547 h 124<br />Gambar 82 TextFieldBackground PAGEREF _Toc302718548 h 126<br />Gambar 83 TextFieldImage.java PAGEREF _Toc302718549 h 128<br />Gambar 84 TextFieldImage.java saat user menginputkan teks PAGEREF _Toc302718550 h 128<br />Gambar 85 DocumentFormatedApp.java PAGEREF _Toc302718551 h 130<br />Gambar 86 TextFieldStyle.java PAGEREF _Toc302718552 h 132<br />Gambar 87 TextFieldStyle2.java PAGEREF _Toc302718553 h 134<br />Gambar 88 ComboColor.java PAGEREF _Toc302718554 h 137<br />Gambar 89 ComboColor2.java PAGEREF _Toc302718555 h 138<br />Gambar 90 ComboImage.java PAGEREF _Toc302718556 h 141<br />Gambar 91 ComboGradient.java PAGEREF _Toc302718557 h 144<br />Gambar 92 ComboGradient2.java PAGEREF _Toc302718558 h 146<br />Gambar 93 ListColor.java PAGEREF _Toc302718559 h 148<br />Gambar 94 ListColor2.java PAGEREF _Toc302718560 h 149<br />Gambar 95 ListBackground.java PAGEREF _Toc302718561 h 150<br />Gambar 96 ListBoolean.java PAGEREF _Toc302718562 h 152<br />Gambar 97 ListNumber.java PAGEREF _Toc302718563 h 154<br />Gambar 98 ListFont.java PAGEREF _Toc302718564 h 156<br />Gambar 99 List menggunakan ListModelUsu saat keadaan No SORT PAGEREF _Toc302718565 h 159<br />Gambar 100 List menggunakan ListModelUsu saat keadaan ASCENDING PAGEREF _Toc302718566 h 159<br />Gambar 101 List menggunakan ListModelUsu saat keadaan DESCENDING PAGEREF _Toc302718567 h 160<br />Gambar 102 List menggunakan ListModelUsuFilter saat tidak di filter PAGEREF _Toc302718568 h 162<br />Gambar 103 List menggunakan ListModelUsuFilter saat difilter PAGEREF _Toc302718569 h 163<br />Gambar 104 Font Browser PAGEREF _Toc302718570 h 164<br />Gambar 105 JViewPort dalam JScrollPane PAGEREF _Toc302718571 h 165<br />Gambar 106 ViewPortTranparan.java PAGEREF _Toc302718572 h 167<br />Gambar 107 ViewPortImage.java PAGEREF _Toc302718573 h 169<br />Gambar 108 ViewPortImage.java PAGEREF _Toc302718574 h 169<br />Gambar 109 TextAreaImage.java PAGEREF _Toc302718575 h 171<br />Gambar 110 TextAreaImage.java PAGEREF _Toc302718576 h 171<br />Gambar 111 ViewPortImageGlass.java PAGEREF _Toc302718577 h 173<br />Gambar 112 Contoh JWindow PAGEREF _Toc302718578 h 174<br />Gambar 113 WindowAbout.java PAGEREF _Toc302718579 h 176<br />Gambar 114 WindowAbout.java saat menampilkan AboutScreen PAGEREF _Toc302718580 h 176<br />Gambar 115 WindowSplashScreen.java saat splashscreen PAGEREF _Toc302718581 h 178<br />Gambar 116 WindowSplashScreen.java saat form muncul PAGEREF _Toc302718582 h 178<br />Gambar 117 WindowTooltip.java PAGEREF _Toc302718583 h 180<br />Gambar 118 WindowTooltip.java saat window tooltip muncul PAGEREF _Toc302718584 h 180<br />Gambar 119 FileRender.java PAGEREF _Toc302718585 h 183<br />Gambar 120 FileRenderLeaf.java PAGEREF _Toc302718586 h 185<br />Gambar 121 TreeColor.java PAGEREF _Toc302718587 h 187<br />Gambar 122 TreeBackground.java PAGEREF _Toc302718588 h 189<br />Gambar 123 TreeBackground.java PAGEREF _Toc302718589 h 191<br />Gambar 124 TreeGlass.java PAGEREF _Toc302718590 h 194<br />Gambar 125 TreeEdited.java PAGEREF _Toc302718591 h 195<br />Gambar 126 TreeEditedComboBox.java PAGEREF _Toc302718592 h 196<br />Gambar 127 TreeEditedChekBox.java PAGEREF _Toc302718593 h 198<br />Gambar 128 TreeColorEditor.java PAGEREF _Toc302718594 h 200<br />Gambar 129 Color Editor PAGEREF _Toc302718595 h 201<br />Gambar 130 TreeFileEditor.java PAGEREF _Toc302718596 h 204<br />Gambar 131 File Editor PAGEREF _Toc302718597 h 204<br />Gambar 132 TreeFileEditorYesNo.java PAGEREF _Toc302718598 h 208<br />Gambar 133 File Editor PAGEREF _Toc302718599 h 208<br />Gambar 134 Yes No Editor PAGEREF _Toc302718600 h 209<br />Gambar 135 TreeFileEditorYesNo saat memilih NO PAGEREF _Toc302718601 h 209<br />Gambar 136 TreeFileEditorYesNo saat memilih YES PAGEREF _Toc302718602 h 210<br />Gambar 137 TableColor.java PAGEREF _Toc302718603 h 213<br />Gambar 138 TableGradient.java PAGEREF _Toc302718604 h 215<br />Gambar 139 PanelAlamat.java PAGEREF _Toc302718605 h 216<br />Gambar 140 PanelAlamat2.java PAGEREF _Toc302718606 h 217<br />Gambar 141 TableAlamat.java PAGEREF _Toc302718607 h 219<br />Gambar 142 TableAlamat.java PAGEREF _Toc302718608 h 220<br />Gambar 143 New File PAGEREF _Toc302718609 h 222<br />Gambar 144 New Bean Form PAGEREF _Toc302718610 h 223<br />Gambar 145 New File PAGEREF _Toc302718611 h 224<br />Gambar 146 NetBeans GUI Builder PAGEREF _Toc302718612 h 224<br />Gambar 147 Choose Bean PAGEREF _Toc302718613 h 226<br />Gambar 148 Choose Bean PAGEREF _Toc302718614 h 226<br />Gambar 149 Tampilan GUI Builder PAGEREF _Toc302718615 h 226<br />Gambar 150 Tampilan akhir render PAGEREF _Toc302718616 h 226<br />Gambar 151 TableAlamatCool.java PAGEREF _Toc302718617 h 229<br />Gambar 152 PanelViewPort.java PAGEREF _Toc302718618 h 230<br />Gambar 153 TableAlamatViewPort.java PAGEREF _Toc302718619 h 232<br />Gambar 154 TableEditorComboBox.java PAGEREF _Toc302718620 h 234<br />Gambar 155 TableEditorChekBox.java PAGEREF _Toc302718621 h 235<br />Gambar 156 Panel render nama PAGEREF _Toc302718622 h 236<br />Gambar 157 Panel render jeniskelamin PAGEREF _Toc302718623 h 236<br />Gambar 158 Panel render menikah PAGEREF _Toc302718624 h 236<br />Gambar 159 TableEditorStylist saat mengedit nama PAGEREF _Toc302718625 h 241<br />Gambar 160 TableEditorStylist saat mengedit jenis kelamin PAGEREF _Toc302718626 h 241<br />Gambar 161 TableEditorStylist saat mengedit menikah PAGEREF _Toc302718627 h 242<br />Gambar 162 TableColorEditor.java PAGEREF _Toc302718628 h 244<br />Gambar 163 Color Editor PAGEREF _Toc302718629 h 245<br />Gambar 164 TableNumberEditor.java PAGEREF _Toc302718630 h 248<br />Gambar 165 TableNumberEditor saat mengedit umur PAGEREF _Toc302718631 h 248<br />Gambar 166 Panel editor alamat PAGEREF _Toc302718632 h 249<br />Gambar 167 TableAlamatCoolEditor.java PAGEREF _Toc302718633 h 251<br />Gambar 168 Editor Alamat PAGEREF _Toc302718634 h 252<br />Gambar 169 TableSorter.java PAGEREF _Toc302718635 h 253<br />Gambar 170 TableSorter saat terurut secara ascending PAGEREF _Toc302718636 h 254<br />Gambar 171 TableSorter saat mengurut secara descending PAGEREF _Toc302718637 h 254<br />Gambar 172 TableSorterGood saat mengurut ascending PAGEREF _Toc302718638 h 256<br />Gambar 173 TableSorterGood saat mengurut descending PAGEREF _Toc302718639 h 256<br />Gambar 174 TableSorterFilter.java PAGEREF _Toc302718640 h 258<br />Gambar 175 TableSorterFilter saat difilter PAGEREF _Toc302718641 h 259<br />Gambar 176 TableCSV.java PAGEREF _Toc302718642 h 262<br />Gambar 177 Save Dialog PAGEREF _Toc302718643 h 262<br />Gambar 178 File CSV PAGEREF _Toc302718644 h 263<br />Gambar 179 Microsoft Offive Excel 2007 PAGEREF _Toc302718645 h 263<br />Gambar 180 Microsoft Office Excel 2007 PAGEREF _Toc302718646 h 264<br />Gambar 181 Get External Data PAGEREF _Toc302718647 h 264<br />Gambar 182 Import Text File PAGEREF _Toc302718648 h 265<br />Gambar 183 Text Import Wizard PAGEREF _Toc302718649 h 266<br />Gambar 184 Text Import Wizard PAGEREF _Toc302718650 h 267<br />Gambar 185 Text Import Wizard PAGEREF _Toc302718651 h 268<br />Gambar 186 Import Data PAGEREF _Toc302718652 h 268<br />Gambar 187 Microsoft Office Excel 2007 PAGEREF _Toc302718653 h 269<br />Gambar 188 OpenOffice Calc PAGEREF _Toc302718654 h 270<br />Gambar 189 Menu Open PAGEREF _Toc302718655 h 270<br />Gambar 190 Open Dialog PAGEREF _Toc302718656 h 271<br />Gambar 191 Text Import PAGEREF _Toc302718657 h 272<br />Gambar 192 OpenOffice Calc PAGEREF _Toc302718658 h 272<br />Gambar 193 TableHTML.java PAGEREF _Toc302718659 h 276<br />Gambar 194 Save Dialog PAGEREF _Toc302718660 h 276<br />Gambar 195 File HTML PAGEREF _Toc302718661 h 277<br />Gambar 196 Mozilla Firefox PAGEREF _Toc302718662 h 277<br />Gambar 197 TextPaneHightLight.java PAGEREF _Toc302718663 h 280<br />Gambar 198 TextPaneHightLight saat hightlight PAGEREF _Toc302718664 h 280<br />Gambar 199 Posisi GlassPane PAGEREF _Toc302718665 h 281<br />Gambar 200 GlassPaneGradientApp.java PAGEREF _Toc302718666 h 282<br />Gambar 201 GlassPaneGradient2App.java PAGEREF _Toc302718667 h 283<br />Gambar 202 Form yang menggunakan GlassPaneBlock PAGEREF _Toc302718668 h 285<br />Gambar 203 Saat form diblock oleh GlassPaneBlock PAGEREF _Toc302718669 h 285<br />Gambar 204 GlassPaneBlock2App.java PAGEREF _Toc302718670 h 287<br />Gambar 205 GlassPaneBlock2App saat diblock PAGEREF _Toc302718671 h 287<br />Gambar 206 Form yang menggunakan GlassPaneWarning PAGEREF _Toc302718672 h 289<br />Gambar 207 Form yang menggunakan GlassPaneWarning PAGEREF _Toc302718673 h 289<br />Gambar 208 Form yang menggunakan GlassPaneTransition PAGEREF _Toc302718674 h 291<br />Gambar 209 Saat GlassPaneTransition memulai transisi PAGEREF _Toc302718675 h 292<br />Gambar 210 Form yang menggunakan GlassPaneTransitionRotasi PAGEREF _Toc302718676 h 294<br />Gambar 211 Saat GlassPaneTransitionRotasi memulai transisi PAGEREF _Toc302718677 h 295<br />Gambar 212 TableTransition.java PAGEREF _Toc302718678 h 297<br />Gambar 213 TableTransition saat memulai transisi PAGEREF _Toc302718679 h 297<br />Gambar 214 GlassPaneFileDragApp.java PAGEREF _Toc302718680 h 301<br />Gambar 215 GlassPaneFileDragApp saat glasspane menampilkan gambar saat file didrag PAGEREF _Toc302718681 h 301<br />Gambar 216 GlassPaneFileDragApp saat file drag didrop PAGEREF _Toc302718682 h 302<br />Gambar 217 GlassPaneImageDragApp.java PAGEREF _Toc302718683 h 306<br />Gambar 218 GlassPaneImageDragApp saat user mendrag file gambar PAGEREF _Toc302718684 h 307<br />Gambar 219 GlassPaneImageDragApp saat user mendrag file selain gambar PAGEREF _Toc302718685 h 307<br />Gambar 220 GlassPaneMessageApp.java PAGEREF _Toc302718686 h 310<br />Gambar 221 GlassPaneMessageApp saat menampilkan pesan PAGEREF _Toc302718687 h 311<br />Gambar 222 GlassPanePanelApp.java PAGEREF _Toc302718688 h 313<br />Gambar 223 GlassPanePanelApp saat menampilkan panel PAGEREF _Toc302718689 h 313<br />Gambar 224 GlassPanePanelApp.java PAGEREF _Toc302718690 h 314<br />Gambar 225 GlassPaneProgressApp.java PAGEREF _Toc302718691 h 316<br />Gambar 226 GlassPaneProgressApp saat proses progress berjalan PAGEREF _Toc302718692 h 317<br />Gambar 227 GlassPaneProgress2App.java PAGEREF _Toc302718693 h 319<br />Gambar 228 GlassPaneProgress2App saat progress berjalan PAGEREF _Toc302718694 h 319<br />Gambar 229 Posisi JLayeredPane dalam JFrame PAGEREF _Toc302718695 h 320<br />Gambar 230 SampleLayer.java PAGEREF _Toc302718696 h 322<br />Gambar 231 LayerUpDown saat panel merah diatas PAGEREF _Toc302718697 h 324<br />Gambar 232 LayerUpDown saat panel biru diatas PAGEREF _Toc302718698 h 324<br />Gambar 233 LayerGlassPane.java PAGEREF _Toc302718699 h 327<br />Gambar 234 LayerGlassPane saat menampilkan pesan PAGEREF _Toc302718700 h 327<br />Gambar 235 LayerGlassPane saat menampilkan progress PAGEREF _Toc302718701 h 328<br />Gambar 236 FormLogIn.java PAGEREF _Toc302718702 h 329<br />Gambar 237 FormIdentitas.java PAGEREF _Toc302718703 h 330<br />Gambar 238 NotePad.java PAGEREF _Toc302718704 h 331<br />Gambar 239 FontBrowser.java PAGEREF _Toc302718705 h 332<br />Gambar 240 TableMahasiswa.java PAGEREF _Toc302718706 h 332<br />Gambar 241 Choose Install Location PAGEREF _Toc302718707 h 333<br />Gambar 242 Installing PAGEREF _Toc302718708 h 334<br />Gambar 243 Complete Setup PAGEREF _Toc302718709 h 334<br />Gambar 244 License Agreement PAGEREF _Toc302718710 h 335<br />Gambar 245 Custom Setup PAGEREF _Toc302718711 h 336<br />Gambar 246 Installing PAGEREF _Toc302718712 h 336<br />Gambar 247 Custom Setup PAGEREF _Toc302718713 h 337<br />Gambar 248 Installing Java PAGEREF _Toc302718714 h 338<br />Gambar 249 Wizard Completed PAGEREF _Toc302718715 h 338<br />Gambar 250 Ekstrak JavaDoc PAGEREF _Toc302718716 h 339<br />Gambar 251 Extrak File PAGEREF _Toc302718717 h 339<br />Gambar 252 Ekstrak File PAGEREF _Toc302718718 h 340<br />Gambar 253 Proses Ekstrak PAGEREF _Toc302718719 h 340<br />Gambar 254 NetBeans Installer PAGEREF _Toc302718720 h 341<br />Gambar 255 License Agreement PAGEREF _Toc302718721 h 342<br />Gambar 256 NetBeans IDE Installation PAGEREF _Toc302718722 h 343<br />Gambar 257 Summary PAGEREF _Toc302718723 h 344<br />Gambar 258 Ekstrak Eclipse Java PAGEREF _Toc302718724 h 344<br />Gambar 259 Ekstrak File PAGEREF _Toc302718725 h 345<br />Gambar 260 Proses EKstrak PAGEREF _Toc302718726 h 345<br />Gambar 261 File Eclipse.EXE PAGEREF _Toc302718727 h 346<br />Persiapan<br />Sebelum saya mulai menjelaskan, menceramahi ataupun mengajarkan hal-hal yang saya ketahui yang mungkin belum anda ketahui ataupun yang sudah anda ketahui saya akan memberitahu dulu tentang dasar Extreem Swing.<br />Swing dan AWT<br />Swing sebenarnya adalah sebuah pengembangan dari library GUI AWT (Abstract Window Toolkit), oleh karena itu kita bisa menemukan metode-metode yang ada di AWT pada Swing karena memang Swing keturunan AWT.<br />Dalam AWT mungkin kita sudah biasa dengan yang mengoveride metode paint(), namun dalam Swing kita tidak dianjurkan untuk mengoveride metode ini, kita dianjurkan untuk mengoveride metode paintComponent().<br />Jadi pelajaran bab ini adalah “ingat jangan mengoveride metode paint(), tapi overide metode paintComponent()”<br />Misal jika kita akan mengoveride metode paintComponent() sebuah JPanel :<br />import java.awt.Graphics;import javax.swing.JPanel;/** * * @author usu */public class SamplePanel extends JPanel { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); }}<br />Project SwingMakeOver<br />Project SwingMakeOver merupakan file source code untuk buku ini. Ada 2 versi, yaitu untuk NetBeans dan Eclipse.<br />Project SwingMakeOver dan NetBeans<br />Jika anda menggunakan Eclipse, silahkan loncat ke subbab selanjutnya.<br />Mungkin anda bingung kenapa saya selalu mendahulukan NetBeans daripada Eclipse, bukan saya tak menyukai Eclipse, tapi karena hampir 90% pembuatan source code ini saya buat dalam NetBeans dan selain itu NetBeans juga satu-satunya IDE untuk Swing yang bisa dibilang terbaik dibandingkan IDE yang lainnya, tapi kalo soal Code Editor, ya tak dapat dipungkiri lagi Eclipse masih memimpin.<br />Sebenarnya tanpa saya buat tutorial ini anda pun pasti sudah tau cara membua sebuah project dalam NetBeans, yach ini sich itung – itung membuka lembaran baru, hehehe . <br />OK seperti kebanyakan Aplikasi untuk membuka sebuah file pasti lewat menu File. Dan dalam NetBeans untuk membuka Project anda bila lewat menu File > Open Project<br />Gambar 21 Menu Open Project<br />Lalu pilih project SwingMakeOver<br />Gambar 22 Open Project<br />Dan selesai, sekarang anda akan melihat project SwingMakeOver di Project Pallete<br />Gambar 23 Project Explorer<br />Project SwingMakeOver dan Eclipse<br />Jika anda menggunakan selain Eclipse IDE atau NetBeans IDE, anda cukup mengcopy paste source code yang ada dalam folder src.<br />Dalam Eclipse untuk membuka sebuah project, kita tak bisa langsung membuka project seperti yang dilakukan pada NetBeans, tapi kita bisa memanfaatkan metode Import untuk membuka sebuah project lewat menu File > Import.<br />Gambar 24 Menu Import<br />Lalu pilih Existing Project into Workspace<br />Gambar 25 Import<br />Pilih Slect root Directory lalu Browse<br />Gambar 26 Import<br />Pilihlah folder SwingMakeOver<br />Gambar 27 Browse For Folder<br />Dan klik button Finish<br />Gambar 28 Import<br />Selesai. Sekarang anda bisa melihat project SwingMakeOver di project explorer<br />Gambar 29 Package Explorer<br />JPanel<br />Pemanasan<br />Mungkin ini yang kedua kalinya saya bilang JANGAN MENGOVERIDE METODE paint(Graphics) TAPI OVERIDE METODE paintComponent(Graphics). Mengapa demikian, karena jika kita mengoveride metode paint(Graphics), maka dengan demikian kita juga mengoveride metode paintComponent(Graphics), paintBorder(Graphics) dan paintChildren(Graphics). Kecuali emang anda ingin mengoveride seluruh metode tadi, maka gunakan paint(Graphics).<br />Pada bab ini kita akan banyak sekali membahas tentang menggambar dan mewarnai. Dalam paintComponent(Graphics) kita bisa melakukan semuanya, baik itu menggambar, mewarnai, bahkan memberi efek – efek yang mungkin jarang kita lihat dalam bahasa pemrograman visual yang lain. Nah bagaimana tertarik bukan? OK let’s EXTREEM!<br />Memanipulasi paintComponent()<br />Seperti yang telah saya beritahu sebelumnya, Extreem Swing akan banyak sekali menemui dengan metode paintComponent(), karena inilah salah satu kelebihan Swing dibandingkan bahasa pemrograman visual lainnya.<br />Menggambar Bentuk<br />Salah satu yanag bisa kita lakukan dalam metode paintComponent() adalah menggambar bentuk, baik itu kotak, lingkaran atau sesuati yang kita inginkan. Dan perlu diketahui parameter yang digunakan paintComponent() adalah Graphics, namun yang kita perlukan adalah Graphics2D, sehingga kita perlu mengconvert Graphics menjadi Graphics2D :<br />protected void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create();}<br />Selain itu untuk menggambar bentuk dengan Graphics2D kita bisa menggunakan metode draw(Shape), sehingga kita bisa menggambar seluruh bentuk yang menjadi keturunan class Shape seperti Rectangle2D, Ellipse2D, atau RoundRectangle2D.<br />Kotak Lancip<br />Untuk membuat atau menggambar kotak dalam sebuah JPanel kita bisa membuatnya dalam metode paintComponent(). Dan untuk membuat kotak kita harus menggunakan class Rectangle2D.Double atau Rectangle2D.Float.<br />Untuk membuat kotak lancip gunakan kode dibawah ini :<br />protected void paintComponent( Graphics g) { super.paintComponent(g); Rectangle2D.Double kotak = new Rectangle2D.Double(int x, int y, int lebar, int tinggi); Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color warna); g2.draw(kotak);}<br />PanelKotak.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelKotak extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelKotak()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Rectangle2D.Double kotak = new Rectangle2D.Double(10, 10, 100, 100); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(kotak); }}<br />Gambar 30 PanelKotak.java<br />PanelKotak2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelKotak2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelKotak2()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); Rectangle2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new Rectangle2D.Double(x, y, width, height); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 31 PanelKotak2.java<br />Kotak Tumpul<br />Untuk membuat kotak kotak yang ujungnya tak lancip kita bisa menggunakan class RoundRectangle2D.<br />Untuk membuat kotak tumpul gunakan kode dibawah ini :<br />protected void paintComponent(Graphics g) { super.paintComponent(g); RoundRectangle2D kotak = new RoundRectangle2D.Double(int x, int y, int lebar, int tinggi, int roundx, int roundy); Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color warna); g2.draw(kotak); }<br />PanelRound.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.RoundRectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelRound extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelRound()); frame.setBounds(100, 100, 300, 200); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final RoundRectangle2D kotak = new RoundRectangle2D.Double(10, 10, 100, 100, 20, 20); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(kotak); }}<br />Gambar 32 PanelRound.java<br />PanelRound2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.RoundRectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelRound2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelRound2()); frame.setBounds(100, 100, 300, 200); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); RoundRectangle2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new RoundRectangle2D.Double(x, y, width, height, 20, 20); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 33 PanelRound2.java<br />Lingkaran <br />Sama seperti halnya membuat kotak, kita juga dapat menggambar lingkaran di JPanel anda dapat menggunakan class Ellipse2D.<br />Untuk membuat lingkaran, gunakan kode dibawah ini :<br />protected void paintComponent(Graphics g) { super.paintComponent(g); Ellipse2D.Double lingkaran = new Ellipse2D.Double(int x, int y, int lebar, int tinggi); Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color warna); g2.draw(lingkaran);}<br />PanelLingkaran.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Ellipse2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLingkaran extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelLingkaran()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Ellipse2D.Double lingkaran = new Ellipse2D.Double(10, 10, 100, 100); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(lingkaran); }}<br />Gambar 34 PanelLingkaran .java<br />PanelLingkaran2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Ellipse2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLingkaran2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelLingkaran2()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); Ellipse2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new Ellipse2D.Double(x, y, width, height); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 35 PanelLingkaran2.java<br />Bentuk Lain <br />Selain kotak atau lingkaran, anda juga bisa menggambar bentuk sesuai dengan yang anda inginkan anda dapat menggunakan class GeneralPath<br />protected void paintComponent(Graphics g) { super.paintComponent(g); GeneralPath path = new GeneralPath(); path.moveTo(int x, int y); // titik awal path path... path... path.closePath(); // menutup path Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color warna); g2.draw(path); }<br />PanelBentukLain.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelBentukLain extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelBentukLain()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Gambar 36 PanelBentukLain.java<br />Perlu diketahui untuk membuat GeneralPath, kita harus menentukan titik awal dulu dengan menggunakan metode moveTo(x,y) karena jika tidak menggunakannya maka akan terjadi Error, dan untuk menutup GeneralPath gunakan metode closePath(), sehingga titik terakhir path akan otomatis disambungkan dengan titik awal, karena jika tidak maka path akan terbuka.<br />Mewarnai Bentuk dengan Solid Color<br />Untuk mewarnai bentuk baik itu kotak ataupun lingkaran, kita cukup menggunakan metode fill(Shape) milik Graphics2D.<br />Kotak Lancip <br />Gunakan kode untuk membuat kotak lalu beri metode fill() :<br />PanelKotak.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelKotak extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelKotak()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Rectangle2D.Double kotak = new Rectangle2D.Double(10, 10, 100, 100); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.RED); g2.fill(kotak); g2.setColor(Color.BLACK); g2.draw(kotak); }}<br />Gambar 37 PanelKotak.java<br />PanelKotak2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import java.util.Random;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelKotak2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelKotak2()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } private final Random generator = new Random(); @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); Rectangle2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new Rectangle2D.Double(x, y, width, height); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(this.generator.nextInt(255), this.generator .nextInt(255), this.generator.nextInt(255))); g2.fill(kotak); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 38 PanelKotak2.java<br />Kotak Tumpul<br />Gunakan kode untuk membuat kotak Round lalu beri metode fill() :<br />PanelRound.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.RoundRectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelRound extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelRound()); frame.setBounds(100, 100, 300, 200); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final RoundRectangle2D kotak = new RoundRectangle2D.Double(10, 10, 100, 100, 20, 20); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.RED); g2.fill(kotak); g2.setColor(Color.BLACK); g2.draw(kotak); }}<br />Gambar 39 PanelRound.java<br />PanelRound2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.RoundRectangle2D;import java.util.Random;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelRound2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelRound2()); frame.setBounds(100, 100, 300, 200); frame.setVisible(true); } }); } private final Random generator = new Random(); @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); RoundRectangle2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new RoundRectangle2D.Double(x, y, width, height, 20, 20); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(this.generator.nextInt(255), this.generator .nextInt(255), this.generator.nextInt(255))); g2.fill(kotak); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 40 PanelRound2.java<br />Lingkaran<br />Gunakan kode untuk membuat lingkaran lalu beri metode fill() :<br />PanelLingkaran.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Ellipse2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLingkaran extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelLingkaran()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Ellipse2D.Double lingkaran = new Ellipse2D.Double(10, 10, 100, 100); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.RED); g2.fill(lingkaran); g2.setColor(Color.BLACK); g2.draw(lingkaran); }}<br />Gambar 41 PanelLingkaran.java<br />PanelLingkaran2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Ellipse2D;import java.util.Random;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLingkaran2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelLingkaran2()); frame.setVisible(true); } }); } private final Random generator = new Random(); @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); Ellipse2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new Ellipse2D.Double(x, y, width, height); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(this.generator.nextInt(255), this.generator .nextInt(255), this.generator.nextInt(255))); g2.fill(kotak); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 42 PanelLingkaran2.java<br />Bentuk Lain <br />Gunakan kode untuk menggambar bentuk lain lalu tambahkan metode fill() :<br />PanelBentukLain.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelBentukLain extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelBentukLain()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.RED); g2.fill(path); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Gambar 43 PanelBentukLain.java<br />Mewarnai Bentuk dengan Gradient Color<br />Mungkin saat ini jika kita memberi warna latar sebuah JPanel dengan warna solid bisa dibilang sudah kuno. Saat ini aplikasi lebih menonjolkan efek 3D dibandingkan efek 2D, jadi mau gak mau kita harus menggunakan warna gradient untuk memunculkan efek 3D<br />Linear Gradient<br />Untuk membuat linear gradient, gunakan kode dibawah ini :<br />protected void paintComponent(Graphics g) { super.paintComponent(g); Shape path = ... // Buat bentuk yang akan diwarnai GradientPaint paint = new GradientPaint(int x1, int y1, Color warna1,int x2, int y2, Color warna); Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path); }<br />PanelLinear.java<br />package pelajaran3;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLinear extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelLinear()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final GradientPaint paint = new GradientPaint(10, 10, Color.RED, getWidth() - 10, 10, Color.BLUE); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Gambar 44 PanelLinear.java<br />Radial Gradient<br />Untuk membuat gradient lingkaran anda dapat menggunakan kode seperti dibawah :<br />protected void paintComponent(Graphics g) { super.paintComponent(g); Shape path = ... // Buat bentuk Point center = ... float radius = ... float[] fractions = ... Color[] colors = ... RadialGradientPaint paint = new RadialGradientPaint(center, radius, fractions, colors); Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path); }<br />PanelRadial.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;import java.awt.RadialGradientPaint;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelRadial extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelRadial()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final Point center = new Point(getWidth() / 2, getHeight() / 2); final float radius = 100; final float[] fractions = new float[] { 0.0F, 1.0F }; final Color[] colors = new Color[] { Color.RED, Color.BLUE }; final RadialGradientPaint paint = new RadialGradientPaint(center, radius, fractions, colors); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Gambar 45 PanelRadial.java<br />Multiple Linear Gradient<br />Kadang andan perlu membuat linear gradient dengan banyak warna, untuk membuatnya anda bisa menggunakan kode seperti dibawah ini :<br />protected void paintComponent(Graphics g) { super.paintComponent(g); Shape path = ... Point start = ... Point end = ... float[] fractions = ... Color[] colors = ... LinearGradientPaint paint = new LinearGradientPaint(start, end, fractions, colors); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path);}<br />PanelLinearMultiple.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.LinearGradientPaint;import java.awt.Point;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLinearMultiple extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelLinearMultiple()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final Point start = new Point(10, 10); final Point end = new Point(getWidth() - 10, 10); final float[] fractions = new float[] { 0.0F, 0.5F, 1.0F }; final Color[] colors = new Color[] { Color.RED, Color.BLUE, Color.YELLOW }; final LinearGradientPaint paint = new LinearGradientPaint(start, end, fractions, colors); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Gambar 46 PanelLinearMultiple.java<br />Multiple Radial Gradient<br />Seperti halnya membuat linear gradient dengan banyak warna, anda pun pasti kadang memerlukan warna radiel gradient yang lebih dari dua warna. Dan untuk membuatnya sama halnya seperti membuat gambar dengan radial gradient namun dengan menggunakan float[] fractions lebih dari dua dan Color[] colors lebih dari dua :<br />PanelRadialMultiple.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;import java.awt.RadialGradientPaint;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelRadialMultiple extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelRadialMultiple()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final Point center = new Point(getWidth() / 2, getHeight() / 2); final float radius = getHeight(); final float[] fractions = new float[] { 0.0F, 0.5F, 1.0F }; final Color[] colors = new Color[] { Color.RED, Color.BLUE, Color.YELLOW }; final RadialGradientPaint paint = new RadialGradientPaint(center, radius, fractions, colors); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(paint); g2.fill(path); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Gambar 47 PanelRadialMultiple.java<br />Antialiasing<br />Sebenarnya subbab ini bisa dibilang kelanjutan dari subbab “Memanupulasi paintComponent()”, karena memang subbab ini sangat terkait dengan subbab sebelumnya.<br />Mungkin anda yang sering memainkan Game PC, telah mengenal kata antialiasing atau dengan kata lain mempertajam gambar dengan cara memberi sedikit efek blur, contoh gambar yang belum kita beri antialiashing adalah gamba – gambar yang tadi kita buat dalam subbab sebelumnya :<br />Gambar 48 PanelLingkaran sebelum antialiasing<br />Terlihat dengan jelas kalo pingiran gambar lingkaran tadi tidak halus. Karena memang belum diberi antialiashing. Sehingga untuk memberi kehalusan pada gambar kita perlu memberi efek antialiasing pada gambar tersebut.<br />Untuk membuat antialiashin ON, gunakan :<br />g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);<br />PanelLingkaranAntialiashing.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.Ellipse2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLingkaranAntialiashing extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelLingkaranAntialiashing()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Ellipse2D.Double lingkaran = new Ellipse2D.Double(10, 10, 100, 100); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.RED); g2.fill(lingkaran); g2.setColor(Color.BLACK); g2.draw(lingkaran); }}<br />Gambar 49 PanelLingkaranAntialiashing.java<br />Sekarang anda bisa melihat perbedaan gambar sebelum dan setelah diberi efek antialiashing. Contoh lain :<br />Sebelum diberi efek antialiasing<br />Gambar 50 PanelLinear sebelum antialiasing<br />PanelLinearMultipleAntialiashing.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.LinearGradientPaint;import java.awt.Point;import java.awt.RenderingHints;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelLinearMultipleAntialiashing extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelLinearMultipleAntialiashing()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final GeneralPath path = new GeneralPath(); path.moveTo(10, 10); path.lineTo(10, getHeight() - 10); path.curveTo(10, getHeight() - 10, getWidth() / 2, 10, getWidth() - 10, getHeight() - 10); path.lineTo(getWidth() - 10, 10); path.closePath(); final Point start = new Point(10, 10); final Point end = new Point(getWidth() - 10, 10); final float[] fractions = new float[] { 0.0F, 0.5F, 1.0F }; final Color[] colors = new Color[] { Color.RED, Color.BLUE, Color.YELLOW }; final LinearGradientPaint paint = new LinearGradientPaint(start, end, fractions, colors); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(path); g2.setColor(Color.BLACK); g2.draw(path); }}<br />Setelah diberi efek antialiasing<br />Gambar 51 PanelLinearMultipleAntialiashing.java<br />Alpha<br />Alpha yang saya maksud adalah teknik untuk membuat gambar atau warna menjadi tranparan. Sebenarnya ada 2 teknik, yang pertama adalah dengan memanipulasi warna (Color) tersebut dan yang kedua adalah dengan menggunakan Composite :<br />Color<br />Sebelumnya kita harus tahu untuk membuat object Color dengan mengatur alpha ada dua konstruktor :<br />Color warna = new Color(int red, int green, int blue, int alpha);<br />Dengan ketentuan bahwa nilai setiap parameter tidak lebih dari 255 dan tak kurang dari 0 dan semakin kecil nilai parameter alpha maka warna akan semakin tranparan.<br />Color warna = new Color(float red, float green, float blue, float alpha);<br />Dengan ketentuan bahwa nilai setiap parameter tidak lebih dari 1F dan tak kurang dari 0F sama seperti konstruktor sebelumnya semakin kecil nilai alphanya maka warna akan semakin tranparan.<br />PanelAlpha.java<br />package pelajaran3;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelAlpha extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelAlpha()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Rectangle2D.Double kotak = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); final Rectangle2D.Double kotak2 = new Rectangle2D.Double(10, 10, getWidth() - 20, getHeight() - 20); final Color dark = new Color(0F, 0F, 0F, 0F); final Color light = new Color(1F, 0F, 0F, 0.5F); final GradientPaint paint = new GradientPaint(10, 10, dark, 10, getHeight() - 20, light); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLUE); g2.fill(kotak); g2.setPaint(paint); g2.fill(kotak2); }}<br />Gambar 52 PanelAlpha.java<br />Anda bisa melihat pada Color dark, saya buat alphanya bernilai 0F sehingga warna tersebut diperlihatkan secara tranparan tergantung nilai alphanya.<br />Composite<br />Selain dengan memanipulasi warna anda juga bisa menggunakan Composite pada Graphics2D. Untuk menggunakan Composite gunakan kode dibawah ini :<br />g2.setComposite(AlphaComposite.SrcOver.derive(float value));<br />PanelComposite.java<br />package pelajaran3;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelComposite extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new PanelComposite()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Rectangle2D.Double kotak = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); final Rectangle2D.Double kotak2 = new Rectangle2D.Double(10, 10, getWidth() - 20, getHeight() - 20); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(Color.BLUE); g2.fill(kotak); g2.setComposite(AlphaComposite.SrcOver.derive(0.5F)); g2.setPaint(Color.RED); g2.fill(kotak2); }}<br />Gambar 53 PanelComposite.java<br />Dengan memberi nilai AlphaComposite 0.5F maka warna merah akan ditampilkan tranparan 50%, tergantung nilai alpha.<br />Perlu diketahui! Berhati – hatilah dalam penempatan AlphaComposite. Saya menempatkan setComposite() sebelum setPaint(Color.RED) sehingga dengan demikian gambar sebelumnya tak akan diberi efek tranparan, sedangkan setelah pemanggilan metode setComposite(), maka gambar akan diberi efek tranparan sesuai dengan tingkat tranparansi yang kita berikan.<br />Image<br />Selain menggambar bentuk – bentuk yang dalam java dibilang Shape, kita juga dapat menggambar objek Image. Dan seperti penjelasan subbab sebelumnya hal inipun tak luput dari metode paintComponent() :<br />protected void paintComponent(final Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); g2.drawImage(Image gambar, int x, int y, ImageObserver observer); }<br />PanelImage.java<br />package pelajaran3;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import javax.swing.ImageIcon;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelImage extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setBounds(100, 100, 300, 300); frame.add(new PanelImage()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Image gambar = new ImageIcon(getClass().getResource("/pelajaran3/My Computer.png")) .getImage(); final Graphics2D g2 = (Graphics2D) g.create(); g2.drawImage(gambar, 10, 10, null); }}<br />Gambar 54 PanelImage.java<br />PanelImage2.java<br />package pelajaran3;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.geom.Rectangle2D;import java.util.Random;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelKotak2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 300, 200); frame.add(new PanelKotak2()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } private final Random generator = new Random(); @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); Rectangle2D.Double kotak = null; int height = getHeight(); int width = getWidth(); int x = 0; int y = 0; while ((height > 10) && (width > 10)) { kotak = new Rectangle2D.Double(x, y, width, height); final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(this.generator.nextInt(255), this.generator .nextInt(255), this.generator.nextInt(255))); g2.fill(kotak); g2.setColor(Color.BLACK); g2.draw(kotak); x += 10; y += 10; height -= 20; width -= 20; } }}<br />Gambar 55 PanelImage2.java<br />Efek Kaca<br />Kali ini saya akan memberi tahu cara yang sangat berguna, yaitu efek kaca untuk gambar. Buatlah class EfekGambar seperti yang ada dibawah ini :<br />EfekGambar.java<br />package pelajaran3;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics2D;import java.awt.Image;import java.awt.image.BufferedImage;/** * @author usu */public final class EfekGambar { public static final BufferedImage getBuffered(final Image source) { final int width = source.getWidth(null); final int height = source.getHeight(null); final BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) dest.getGraphics(); g2.drawImage(source, 0, 0, null); g2.dispose(); return dest; } public static final BufferedImage getEfekKaca(final BufferedImage source) { final BufferedImage dest = new BufferedImage(source.getWidth(), source.getHeight() + source.getHeight() / 2, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) dest.getGraphics(); g2.drawImage(source, 0, 0, null); g2.scale(1, -1); g2.drawImage(source, 0, -source.getHeight() * 2, null); g2.scale(1, -1); g2.translate(0, source.getHeight()); g2.setPaint(new GradientPaint(0, 0, new Color(1f, 1f, 1f, 0.3f), 0, source.getHeight() / 2, new Color(1f, 1f, 1f, 0f))); g2.setComposite(AlphaComposite.DstIn); g2.fillRect(0, 0, source.getWidth(), source.getHeight()); g2.dispose(); return dest; } public static final BufferedImage getEfekKaca(final Image source) { return EfekGambar.getEfekKaca(EfekGambar.getBuffered(source)); }}<br />Class diatas digunakan sebagai class library untuk efek kaca, misal kita akan merubah gambar panel yang tadi sebelumnya kita gambar :<br />protected void paintComponent(final Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); g2.drawImage(EfekGambar.getEfekKaca(Image gambar), int x, int y, ImageObserver observer); }<br />PanelImageKaca.java<br />package pelajaran3;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import javax.swing.ImageIcon;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelImageKaca extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setBounds(100, 100, 300, 300); frame.add(new PanelImageKaca()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Image gambar = new ImageIcon(getClass().getResource("/pelajaran3/AIM.png")).getImage(); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(new GradientPaint(0, 0, Color.BLUE, 0, gambar.getHeight(null), Color.BLACK)); g2.fillRect(0, 0, getWidth(), getHeight()); g2.drawImage(EfekGambar.getEfekKaca(gambar), 10, 10, null); }}<br />Gambar 56 PanelImageKaca.java<br />PanelImageKaca2.java<br />package pelajaran3;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import javax.swing.ImageIcon;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelImageKaca2 extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setBounds(100, 100, 300, 300); frame.add(new PanelImageKaca2()); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Image gambar = new ImageIcon(getClass().getResource( "/pelajaran3/My Computer.png")).getImage(); final Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(new GradientPaint(0, 0, Color.BLUE, 0, gambar.getHeight(null), Color.BLACK)); g2.fillRect(0, 0, getWidth(), getHeight()); g2.drawImage(EfekGambar.getEfekKaca(gambar), 10, 10, null); }}<br />Gambar 57 PanelImageKaca2.java<br />Kesimpulan<br />Mungkin anda bertanya – tanya, apakah penting untuk mengetahui cara mengambar dan mewarnai dalam JPanel untuk membuat aplikasi berbasis Swing. <br />Ya tentu saja!!! Saat ini jarang sekali kita temukan aplikasi yang memiliki tampilan standar seperti jaman ketika kita menggunakan Windows 98, yang sangat kaku. Saat ini kita perlu membuat aplikasi yang selain powerfull tapi juga memiliki daya tarik atau memiliki kemewahan dalam desain, misal saja saya pernah membuat aplikasi MyOpenOffice :<br />Gambar 58 MyOpenOffice Login<br />Gambar 59 MyOpenOffice Menu<br />Gambar 60 MyOpenOffice Contact<br />Dan untuk membuat tampilan aplikasi seperti diatas, kita harus menguasai teknik menggambar dan mewarnai dalam JPanel.<br />Sebenarnya selain di JPanel anda juga bisa membuat gambar hampir disemua component Swing dengan mengoveride metode paintComponent() baik itu dalam Jbutton, JLabel ataupun dalam component – component swing lainnya.<br />Dari penjelasan tadi diatas, anda sudah bisa membuat JPanel yang memiliki efek – efek yang memukau contohnya :<br />PanelEfect.java<br />package pelajaran3;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.GeneralPath;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class PanelEfect extends JPanel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setBounds(100, 100, 400, 400); frame.add(new PanelEfect()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint paint = new GradientPaint(0, 0, Color.BLACK, 0, getHeight(), Color.RED); g2.setPaint(paint); g2.fillRect(0, 0, getWidth(), getHeight()); final int width = getWidth(); final int height = getHeight() * 5 / 100; final Color light = new Color(1F, 1F, 1F, 0.5F); final Color dark = new Color(1F, 1F, 1F, 0.0F); paint = new GradientPaint(0, 0, light, 0, height, dark); GeneralPath path = new GeneralPath(); path.moveTo(0, 0); path.lineTo(0, height); path.curveTo(0, height, width / 2, height / 2, width, height); path.lineTo(width, 0); path.closePath(); g2.setPaint(paint); g2.fill(path); paint = new GradientPaint(0, getHeight(), light, 0, getHeight() - height, dark); path = new GeneralPath(); path.moveTo(0, getHeight()); path.lineTo(0, getHeight() - height); path.curveTo(0, getHeight() - height, width / 2, getHeight() - height / 2, width, getHeight() - height); path.lineTo(width, getHeight()); path.closePath(); g2.setPaint(paint); g2.fill(path); }}<br />Gambar 61 PanelEfect.java<br />JButton<br />Glass<br />Tombol Kotak Lancip<br />Salah satu teknik yang dapat membuat JButton terlihat lebih indah adalah efek glass. Dan sekali lagi untuk membuat efek glass kita perlu mengoveride metode paintComponent();<br />ButtonGlass.java<br />package pelajaran4;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.Rectangle2D;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class ButtonGlass extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new JPanel(new FlowLayout()); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); panel.add(new ButtonGlass("TOMBOL")); frame.setVisible(true); } }); } public ButtonGlass(final String title) { super(title); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); final GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); final Rectangle2D.Double kotak = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); }}<br />Gambar 62 ButtonGlass.java<br />ButtonGlass2.java<br />package pelajaran4;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.Rectangle2D;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;import pelajaran3.PanelEfect;/** * @author usu */public class ButtonGlass2 extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new PanelEfect(); panel.setLayout(null); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); final ButtonGlass2 glass = new ButtonGlass2("TOMBOL"); panel.add(glass); glass.setBounds(100, 100, 100, 25); frame.setVisible(true); } }); } public ButtonGlass2(final String title) { super(title); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); final GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); final Rectangle2D.Double kotak = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); }}<br />Gambar 63 ButtonGlass2.java<br />Satu hal yang harus diingat dalam pembuatan JButton glass adalah merubah atau menghapus gambar JButton sebelumnya dengan cara :<br /> setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false);<br />Tombol Kotak Luncul<br />Kadang menggunakan button berbentuk kotak agak terlihat kaku sehingga untuk membuatnya tidak kaku saya sarankan untuk membuat button berbentuk round :<br />ButtonGlassRound.java<br />package pelajaran4;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.RoundRectangle2D;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class ButtonGlassRound extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new JPanel(new FlowLayout()); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); panel.add(new ButtonGlassRound("TOMBOL")); frame.setVisible(true); } }); } public ButtonGlassRound(final String title) { super(title); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); final GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); final RoundRectangle2D.Double kotak = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), getHeight(), getHeight()); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); }}<br />Gambar 64 ButtonGlassRound.java<br />ButtonGlassRound2.java<br />package pelajaran4;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.RoundRectangle2D;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;import pelajaran3.PanelEfect;/** * @author usu */public class ButtonGlassRound2 extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new PanelEfect(); panel.setLayout(null); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); final ButtonGlassRound2 glass = new ButtonGlassRound2("TOMBOL"); panel.add(glass); glass.setBounds(100, 100, 100, 25); frame.setVisible(true); } }); } public ButtonGlassRound2(final String title) { super(title); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); final GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); final RoundRectangle2D.Double kotak = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), getHeight(), getHeight()); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); }}<br />Gambar 65 ButtonGlassRound2.java<br />Image<br />Mungkin semuanya sudah tahu kalo untuk menampilkan gambar dalam JButton, kita hanya perlu menggunakan metode setIcon(), namun yang saya maksudkan adalah menampilkan gambar dengan efek kaca seperti pada pelajaran JPanel sebelumnya.<br />BufferedImage image = EfekGambar.getEfekKaca(Image gambar);Button.setIcon(new ImageIcon(image));<br />ButtonImage.java<br />package pelajaran4;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.RoundRectangle2D;import java.awt.image.BufferedImage;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;import pelajaran3.EfekGambar;/** * @author usu */public class ButtonImage extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new JPanel(new FlowLayout()); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); panel.add(new ButtonImage()); frame.pack(); frame.setVisible(true); } }); } public ButtonImage() { super(); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); final ImageIcon icon = new ImageIcon(getClass().getResource("/pelajaran3/AIM.png")); final BufferedImage image = EfekGambar.getEfekKaca(icon.getImage()); setIcon(new ImageIcon(image)); } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); final GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); final RoundRectangle2D.Double kotak = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 50, 50); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); }}<br />Gambar 66 ButtonImage.java<br />Pada kode diatas, saya membuat gambar di letakan di atas glass, hal ini karena saya memanggil metode super.paintComponent() di urutan paling bawah sehingga gambar dari JButton akan di gambar diatas JBUtton Glass, kecuali anda membalikkan letaknya :<br />@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Color light = new Color(1F, 1F, 1F, 0.7F); Color dark = new Color(1F, 1F, 1F, 0F); GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); RoundRectangle2D.Double kotak = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 50, 50); Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); }<br />Gambar 67 ButtonImage menggunakan glass diatas<br />Mouse<br />Salah satu perbedaan JButton dengan JPanel adalah interaksinya dengan Mouse, ketika mouse ditekan atau ketika mouse diatas JButton biasanya tampilan JButton berubah, sehingga jika kita membuat button seperti button – buton sebelumnya, maka akan terlihat kaku.<br />Over<br />Salah satu interaksi dengan mouse adalah ketika mouse diatas button (over), dan agar mempermudah kita sewaktu koding, maka kita harus membuat metode yang mengecek apakah mouse ada diatas JButton atau tidak:<br />private boolean over;private boolean isOver(){ return over;}private void setOver(boolean value){ over = value;}<br />Lalu tambahkan mouse listener :<br />addMouseListener(new MouseAdapter() { public void mouseEntered(final MouseEvent e) { setOver(true); } public void mouseExited(final MouseEvent e) { setOver(false); }});<br />ButtonOver.java<br />package pelajaran4;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.geom.RoundRectangle2D;import java.awt.image.BufferedImage;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;import pelajaran3.EfekGambar;/** * @author usu */public class ButtonOver extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new JPanel(new FlowLayout()); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); panel.add(new ButtonOver()); frame.pack(); frame.setVisible(true); } }); } private boolean over; public ButtonOver() { super(); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); final ImageIcon icon = new ImageIcon(getClass().getResource("/pelajaran3/AIM.png")); final BufferedImage image = EfekGambar.getEfekKaca(icon.getImage()); setIcon(new ImageIcon(image)); setOver(false); addMouseListener(new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { setOver(true); } @Override public void mouseExited(final MouseEvent e) { setOver(false); } }); } public boolean isOver() { return this.over; } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); GradientPaint paint = null; if (this.over) { paint = new GradientPaint(0, 0, dark, 0, getHeight(), light); } else { paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); } final RoundRectangle2D.Double kotak = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 50, 50); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); } public void setOver(final boolean over) { this.over = over; repaint(); }}<br />Ketika mouse keluar dari button dan masuk ke button:<br />Gambar 68 ButtonOver.java saat mouse exit<br />Gambar 69 ButtonOver.java saat mouse over<br />Press<br />Selain interaksi ketika mose over kita juga perlu melakukan interaksi ketika mouse di press (tekan) :<br />private boolean press;private boolean over;private boolean isPress(){ return press;}private void setPress(boolean value){ press = value;}private boolean isOver(){ return over;}private void setOver(boolean value){ over = value;}<br />Dan jangan lupa menambahkan mouse listener :<br />addMouseListener(new MouseAdapter() { public void mouseEntered(final MouseEvent e) { setOver(true); } public void mouseExited(final MouseEvent e) { setOver(false); } public void mousePressed(final MouseEvent e) { setPress(true); } public void mouseReleased(final MouseEvent e) { setPress(false); }});<br />ButtonOverPress.java<br />package pelajaran4;import java.awt.Color;import java.awt.FlowLayout;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.geom.RoundRectangle2D;import java.awt.image.BufferedImage;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;import pelajaran3.EfekGambar;/** * @author usu */public class ButtonOverPress extends JButton { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JPanel panel = new JPanel(new FlowLayout()); panel.setBackground(Color.RED); frame.add(panel); frame.setBounds(100, 100, 300, 200); panel.add(new ButtonOverPress()); frame.pack(); frame.setVisible(true); } }); } private boolean over; private boolean press; public ButtonOverPress() { super(); setFocusPainted(false); setBorderPainted(false); setContentAreaFilled(false); final ImageIcon icon = new ImageIcon(getClass().getResource("/pelajaran3/AIM.png")); final BufferedImage image = EfekGambar.getEfekKaca(icon.getImage()); setIcon(new ImageIcon(image)); setOver(false); addMouseListener(new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { setOver(true); } @Override public void mouseExited(final MouseEvent e) { setOver(false); } @Override public void mousePressed(final MouseEvent e) { setPress(true); } @Override public void mouseReleased(final MouseEvent e) { setPress(false); } }); } public boolean isOver() { return this.over; } public boolean isPress() { return this.press; } @Override protected void paintComponent(final Graphics g) { final Color light = new Color(1F, 1F, 1F, 0.7F); final Color dark = new Color(1F, 1F, 1F, 0F); GradientPaint paint = null; if (this.over) { if (this.press) { paint = new GradientPaint(0, 0, light, 0, getHeight(), light); } else { paint = new GradientPaint(0, 0, dark, 0, getHeight(), light); } } else { paint = new GradientPaint(0, 0, light, 0, getHeight(), dark); } final RoundRectangle2D.Double kotak = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 50, 50); final Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(paint); g2.fill(kotak); super.paintComponent(g); } public void setOver(final boolean over) { this.over = over; repaint(); } public void setPress(final boolean press) { this.press = press; repaint(); }}<br />Ketika mouse diluar button, diatas button dan tak diklik, dan diatas button dan diklik :<br />Gambar 70 ButtonOverPress.java saat mouse exit<br /> <br />Gambar 71 ButtonOverPress.java saat mouse over<br /> <br />Gambar 72 ButtonOverPress.java saat mouse press<br />Kesimpulan<br />Untuk JButton mau gak mau anda harus membuat atau memanipulasi gambar yang dapat berinteraksi dengan Mouse, agar hasil manipulasi JButton anda benar – benar terlihat seperti JButton.<br />Contoh – contoh diatas hanyalah sebagian kecil dari daya kreativitas anda, jadi berkreasilah untuk membuat Extreem JButton.<br />JLabel<br />Drop Shadow Text<br />Kadang kita hanya membuaat JLabel sebagai label biasa, namun sebenarnya kita juga dapat membuat label – label yang luar biasa, contohnya kita akan membuat label dengan drop shadow.<br />LabelDropShadow.java<br />package pelajaran5;import java.awt.Color;import java.awt.Dimension;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import javax.swing.JLabel;import javax.swing.SwingUtilities;import javax.swing.WindowConstants;import pelajaran1.Frame;/** * @author usu */public class LabelDropShadow extends JLabel { public static void main(final String[] usu) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Frame frame = new Frame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setBounds(100, 100, 300, 200); final LabelDropShadow label = new LabelDropShadow(); label.setText("Eko Kurniawan"); label.setFont(label.getFont().deriveFont(50F)); label.setDistance(2); frame.add(label); frame.setVisible(true); } }); } private int distance; private Color dropShadowColor; public LabelDropShadow() { super(); setDistance(3); setForeground(Color.GRAY); setDropShadowColor(Color.BLACK); } public int getDistance() { return this.distance; } public Color getDropShadowColor() { return this.dropShadowColor; } @Override public Dimension getPreferredSize() { final Dimension d = super.getPreferredSize(); d.height += getDistance(); d.width += getDistance(); return d; } @Override protected void paintComponent(final Graphics g) { final FontMetrics metric = getFontMetrics(getFont())

×