• Tidak ada hasil yang ditemukan

Building a Java Desktop Database Application - NetBeans IDE Tutorial

N/A
N/A
Protected

Academic year: 2019

Membagikan "Building a Java Desktop Database Application - NetBeans IDE Tutorial"

Copied!
12
0
0

Teks penuh

(1)
(2)

Befor e y ou begin cr eat ing a deskt op CRUD ( cr eat e, r ead, updat e, delet e) applicat ion in t he I DE, you should alr eady have t he I DE

St art ing t he Server and Creat ing a Dat abase

Once Java DB is regist er ed wit h t he I DE, you can easily st ar t and st op t he dat abase ser ver , as well as cr eat e a new dat abase.

Righ t - click t he dat abase connect ion node (jdbc:derby://localhost:1527/car_database[nbuser on NBUSER]) an d choose Con nect .

(3)

Exp and t he conn ect ion n ode and n ot e t hat t h ere ar e sever al schem a subn odes. Righ t - click t he APP node and choose Set as

I n t he Choose Applicat ion Shell field, select Dat abase Applicat ion. e.

Click Next . f.

4 .

I n t he Mast er Table page of t he w izard, select t h e dat ab ase con nect ion f or t he CAR dat abase. The list in g for t h e dat abase should look som et hing like t he following: jdbc:derby://localhost:1527/car_database[nbuser on NBUSER]

5 .

Select t he bot t om five colum n nam es ( beginning wit h SUN_ROOF and ending wit h MODERNNESS) and click t he < but t on t o m ove t hem t o t he left colum n. Click Next .

(4)

I n t he Det ail Opt ions pan el, click Fin ish.

Reviewing t he Generat ed Part s of t he Applicat ion

(5)
(6)

Binding Cont rols t o Values in t he Table

We will now use beans bindin g feat u res t o t ie t h e valu es show n in t able cells t o t he st at e of t he cont r ols we have added. This will allow you t o chan ge t he values of cells in t he t able by using t h e sliders and checkboxes.

To b in d t h e slid e r s t o t h e ir cor r e spon d in g t a b le e le m e n t s:

I n t he for m , r ight - click t he Tir e Size slider and ch oose Bind > value. 1 .

I n t he Binding Sour ce dr op- dow n list of t h e Binding dialog b ox, select masterTable. 2 .

(7)
(8)

Choose Ru n > Ru n Main Pr oj ect t o execut e t he applicat ion.

The ru nning applicat ion should look sim ilar t o t h e screenshot sh own below . 5 .

I n t he ru nning applicat ion, select t h e fir st r ecord. 6 .

Move t he slider s and ch ange t he checkbox select ions. 7 .

Click Sav e t o save t he changes int o t h e dat ab ase. 8 .

I n t he Serv ices win dow, u se t he View Dat a com m an d again .

The values in t h e dat abase should r eflect ch anges t h at you have m ade. 9 .

Set t ing up a Cust om Com ponent

For an even m or e gr aph ic dem on st r at ion of bean s bin ding in act ion, let 's add a cust om com ponen t t h at will paint a pr eview of t he select ed car . We will bind pr oper t ies of t his com ponent t o corr espon ding t able elem ent s. Th en w hen you r un t h e applicat ion again, t he car pr eview w ill be m od if ied as you change t he select ed row and change t he values of t h e var iou s fields.

To m a k e t h e Ca r Pr e v ie w com pon e n t a v a ila b le f or t h e Ca r sAp p p r oj e ct :

I f you h ave n ot alr eady don e so, down load t he CarPreview.zip f ile. 1 .

Usin g a st and ar d zip t ool, ext r act t he archives of t he zip file. 2 .

Choose File > Open Proj ect and navigat e in t o t he ext r act ed con t ent s of t h e zip file and select t h e Car Pr eview pr oj ect . 3 .

Click Open Proj ect .

The proj ect open s in t he I DE. 4 .

Righ t - click t he Car Preview node an d choose Clean and Build.

This com piles t he files in t he proj ect so t hat you can u se t h e Car Pr eview class as a bean t hat can be dr agged an d dr opped dir ect ly on t o t he f or m .

(9)

This com pon ent was wr it t en as a Jav aBean s com ponent , so you could add it t o t he Palet t e, which wou ld be convenien t for addin g t he com ponen t t o m u lt iple app licat ions. Bu t f or n ow we w ill sim ply dr ag t h e com pon ent direct ly int o you r applicat ion dir ect ly f rom t he Pr oj ect s window.

To a dd t h e Ca r Pr e v ie w com pon e nt t o t h e a p plica t ion :

I n t he Pr oj ect s window, expand t he Car Preview > Sou rce Packages > car preview node. 1 .

Dr ag t he CarPreview.java class t o t h e for m . To in ser t it pr oper ly j u st below t he m enu s, place it over t he t able left aligned wit h t h e ot her cont r ols and snapped t o t he bot t om of t h e m en u bar, as sh ow n in t h e im age below .

2 .

Resize t he pr eview com pon ent hor izont ally over t h e en t ir e for m . 3 .

I n t he sam e w ay t hat you bou nd t he slider s an d checkboxes t o elem en t s in t he masterTable com ponent , bind all t h e binding pr oper t ies of t h e CarPr eview com pon ent t o t he cor r esponding select edElem ent at t ribu t es of t h e masterTable. Use t he Bin d popup m enu or t he Bin din g t ab in t he pr opert y sheet .

4 .

Ru n t he CarApp applicat ion again.

I n t he ru nning applicat ion, you can see t he Car Pr eview com ponen t ch ange as you select differ ent r ows in t he t able, alt er valu es in t he t able, m ove t h e sliders, an d select and deselect t he ch eckboxes.

5 .

(10)

Building and Deploying t he Applicat ion

Once you are sat isfied t h at you r applicat ion w or ks pr oper ly, you can prepar e t he applicat ion for deploym ent out side of t h e I DE. I n t his sect ion you will build t h e ap plicat ion 's dist r ibut able out put s an d r un t h e applicat ion fr om ou t side of t he I DE.

Building t he Applicat ion

The m ain bu ild com m and in t h e I DE is t he Clean and Build com m and. The Clean an d Build com m an d delet es pr eviously com piled classes and ot h er build ar t ifact s and t h en r ebu ilds t he ent ire proj ect fr om scr at ch.

N ot e s: Ther e is also a Build com m and, wh ich does not delet e old bu ild ar t ifact s, but t his com m and is disabled by default . See t he Com pile on Save sect ion of t h e Creat in g, I m por t ing, and Con figur ing Java Pr oj ect s guide for m or e inf or m at ion.

To bu ild t h e a pp lica t ion :

Choose Run > Clean and Build Main Pr oj ect ( Shift - F11 ) .

Out put f rom t he Ant build scr ipt appear s in t he Out put w in dow . I f t h e Ou t pu t window does not appear , you can op en it m anually by choosing Window > Ou t pu t > Ou t pu t .

When you clean and bu ild your pr oj ect , t he following t hings occu r:

Out put folder s t h at have been gener at ed by pr eviou s build act ions are delet ed ( " cleaned") . ( I n m ost cases, t h ese ar e t he

(11)

build and dist folder s are added t o you r pr oj ect folder ( h ereaft er r efer r ed t o as t he PROJECT_ HOME folder) .

Running t he Applicat ion Out side of t he I DE

To r u n t h e a pp lica t ion ou t sid e of t h e I D E:

Dist ribut ing t he Applicat ion t o Ot her Users

(12)

Send Feedback on Th is Tu t orial For m or e inf or m at ion on u sing beans bin ding in t h e I DE, see Binding Beans and Dat a in a Deskt op Applicat ion.

See Also

Gen eral Java Developm ent Learn ing Tr ail Net Bean s Plat form CRUD Applicat ion Tu t or ial GUI Edit or FAQ

Referensi

Dokumen terkait

#AIDS2018 | @AIDS_conference | www.aids2018.org. Click if you cannot remember

Berawal dari latar belakang ini penulis termotivasi untuk membangun aplikasi permainan, dalam hal ini adalah aplikasi yang berjalan di telepon genggam berbasis

If, at some point in the code block of a loop, you decide you need to immediately leave the loop, this can be done using a Java break statement. When a break statement

First click on the Forum link in the main menu, then on Tips &amp; Tricks in the forum list, and finally on ::post new topic::. You can write a posting in the form that pops

Berawal dari latar belakang ini penulis termotivasi untuk membangun aplikasi permainan, dalam hal ini adalah aplikasi yang berjalan di telepon genggam berbasis

Atau anda bisa men-download file .sql yang telah dibuat di SINI , dan IMPORT file tersebut pada database yang anda buat dengan nama &#34;belajar&#34; di XAMPP.. Buatlah

8. create  table  login  (Username  varchar(15)not  null,  Password  varchar(30)  not  null  ,  primary  key (Username));  &lt;&lt;Membuat  table  di  database 

Berawal dari latar belakang ini penulis termotivasi untuk membangun aplikasi permainan, dalam hal ini adalah aplikasi yang berjalan di telepon genggam berbasis Java dengan melakukan