Pages

Sunday, October 16, 2011

Line Arts - Android Live Wallpaper

Hello Guys,
  This article is not a tutorial on Android canvas or Android Live Wallpaper. Given below is the code snippet of Android Canvas that draws a line diagram of Actors Dhanush and Chaya Singh from the movie 'Thiruda Thirudi'.  The code was originally written by me using C and then modified to fit Android Canvas.
   I made a live wall paper out of it and it is available in Android market as Free  for 2.1 or more versions of Android. The app supports all screen sizes and rotates the wall paper based on the angle in which the phone is tilted. However, via settings, you can enable/disable rotation based on sensor and control the gradient change speed. You can double tap on the screen to scale the image to your choice.

 https://market.android.com/details?id=com.sudhan.livewp&feature=search_result





If you are looking for Live Wall Paper Tutorial, check it out here,
    http://developer.android.com/resources/articles/live-wallpapers.html http://www.vogella.de/articles/AndroidLiveWallpaper/article.html http://blog.androgames.net/58/android-live-wallpaper-tutorial/
Code Snippet:


/* Draw Dhanush And Chaya Singh */
void drawLineDiagram(Canvas canvas) 
{
int x = 120, y = 5;
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStrokeWidth(0);
paint.setStyle(Paint.Style.STROKE);
canvas.drawLine(130 - x, 452 + y, 128 - x,448 + y, paint);
canvas.drawLine(128 - x, 448 + y, 126 - x,450 + y, paint);
canvas.drawLine(126 - x, 450 + y, 110 - x,449 + y, paint);
canvas.drawLine(110 - x, 449 + y, 110 - x,436 + y, paint);
canvas.drawLine(110 - x, 436 + y, 107 - x,433 + y, paint);
canvas.drawLine(107 - x, 433 + y, 111 - x,415 + y, paint);
canvas.drawLine(111 - x, 415 + y, 120 - x,395 + y, paint);
canvas.drawLine(120 - x, 395 + y, 121 - x,395 + y, paint);
canvas.drawLine(121 - x, 395 + y, 122 - x,394 + y, paint);
canvas.drawLine(122 - x, 394 + y, 132 - x,350 + y, paint);
canvas.drawLine(132 - x, 350 + y, 133 - x,350 + y, paint);
canvas.drawLine(133 - x, 350 + y, 135 - x,348 + y, paint);
canvas.drawLine(135 - x, 348 + y, 135 - x,345 + y, paint);
canvas.drawLine(135 - x, 345 + y, 138 - x,339 + y, paint);
canvas.drawLine(138 - x, 339 + y, 143 - x,337 + y, paint);
canvas.drawLine(143 - x, 337 + y, 144 - x,336 + y, paint);
canvas.drawLine(144 - x, 336 + y, 144 - x,330 + y, paint);
canvas.drawLine(144 - x, 330 + y, 147 - x,327 + y, paint);
canvas.drawLine(147 - x, 327 + y, 147 - x,324 + y, paint);
canvas.drawLine(147 - x, 324 + y, 148 - x,323 + y, paint);
canvas.drawLine(148 - x, 323 + y, 149 - x,322 + y, paint);
canvas.drawLine(149 - x, 322 + y, 149 - x,321 + y, paint);
canvas.drawLine(149 - x, 321 + y, 148 - x,318 + y, paint);
canvas.drawLine(148 - x, 318 + y, 148 - x,317 + y, paint);
canvas.drawLine(148 - x, 317 + y, 150 - x,314 + y, paint);
canvas.drawLine(150 - x, 314 + y, 150 - x,285 + y, paint);
canvas.drawLine(150 - x, 285 + y, 148 - x,283 + y, paint);
canvas.drawLine(148 - x, 283 + y, 151 - x,280 + y, paint);
canvas.drawLine(151 - x, 280 + y, 151 - x,278 + y, paint);
canvas.drawLine(151 - x, 278 + y, 150 - x,277 + y, paint);
canvas.drawLine(150 - x, 277 + y, 152 - x,276 + y, paint);
canvas.drawLine(152 - x, 276 + y, 151 - x,262 + y, paint);
canvas.drawLine(151 - x, 262 + y, 149 - x,260 + y, paint);
canvas.drawLine(149 - x, 260 + y, 146 - x,250 + y, paint);
canvas.drawLine(146 - x, 250 + y, 145 - x,249 + y, paint);
canvas.drawLine(145 - x, 249 + y, 144 - x,248 + y, paint);
canvas.drawLine(144 - x, 248 + y, 143 - x,248 + y, paint);
canvas.drawLine(143 - x, 248 + y, 137 - x,246 + y, paint);
canvas.drawLine(137 - x, 246 + y, 137 - x,242 + y, paint);
canvas.drawLine(137 - x, 242 + y, 139 - x,240 + y, paint);
canvas.drawLine(139 - x, 240 + y, 141 - x,240 + y, paint);
canvas.drawLine(141 - x, 240 + y, 145 - x,239 + y, paint);
canvas.drawLine(145 - x, 239 + y, 146 - x,236 + y, paint);
canvas.drawLine(146 - x, 236 + y, 140 - x,230 + y, paint);
canvas.drawLine(140 - x, 230 + y, 144 - x,222 + y, paint);
canvas.drawLine(144 - x, 222 + y, 139 - x,223 + y, paint);
canvas.drawLine(139 - x, 223 + y, 140 - x,220 + y, paint);
canvas.drawLine(140 - x, 220 + y, 146 - x,215 + y, paint);
canvas.drawLine(146 - x, 215 + y, 147 - x,210 + y, paint);
canvas.drawLine(147 - x, 210 + y, 150 - x,208 + y, paint);
canvas.drawLine(150 - x, 208 + y, 158 - x,196 + y, paint);
canvas.drawLine(158 - x, 196 + y, 150 - x,192 + y, paint);
canvas.drawLine(150 - x, 192 + y, 140 - x,182 + y, paint);
canvas.drawLine(140 - x, 182 + y, 125 - x,192 + y, paint);
canvas.drawLine(100 - x, 197 + y, 98 - x,187 + y, paint);
canvas.drawLine(98 - x, 187 + y, 102 - x,188 + y, paint);
canvas.drawLine(98 - x, 187 + y, 102 - x,175 + y, paint);
canvas.drawLine(102 - x, 175 + y, 100 - x,173 + y, paint);
canvas.drawLine(100 - x, 173 + y, 102 - x,171 + y, paint);
canvas.drawLine(102 - x, 171 + y, 108 - x,155 + y, paint);
canvas.drawLine(108 - x, 155 + y, 106 - x,155 + y, paint);
canvas.drawLine(106 - x, 155 + y, 114 - x,137 + y, paint);
canvas.drawLine(121 - x, 127 + y, 126 - x,122 + y, paint);
canvas.drawLine(126 - x, 122 + y, 128 - x,122 + y, paint);
canvas.drawLine(128 - x, 122 + y, 132 - x,118 + y, paint);
canvas.drawLine(132 - x, 118 + y, 130 - x,116 + y, paint);
canvas.drawLine(130 - x, 116 + y, 135 - x,114 + y, paint);
canvas.drawLine(135 - x, 114 + y, 136 - x,110 + y, paint);
canvas.drawLine(136 - x, 110 + y, 140 - x,109 + y, paint);
canvas.drawLine(140 - x, 109 + y, 142 - x,105 + y, paint);
canvas.drawLine(142 - x, 105 + y, 140 - x,104 + y, paint);
canvas.drawLine(140 - x, 104 + y, 137 - x,100 + y, paint);
canvas.drawLine(137 - x, 100 + y, 126 - x,75 + y, paint);
canvas.drawLine(126 - x, 75 + y, 127 - x,67 + y, paint);
canvas.drawLine(127 - x, 67 + y, 129 - x,60 + y, paint);
canvas.drawLine(129 - x, 60 + y, 128 - x,50 + y, paint);
canvas.drawLine(128 - x, 50 + y, 132 - x,47 + y, paint);
canvas.drawLine(132 - x, 47 + y, 140 - x,43 + y, paint);
canvas.drawLine(140 - x, 43 + y, 140 - x,40 + y, paint);
canvas.drawLine(140 - x, 40 + y, 147 - x,41 + y, paint);
canvas.drawLine(147 - x, 41 + y, 150 - x,42 + y, paint);
canvas.drawLine(150 - x, 42 + y, 148 - x,38 + y, paint);
canvas.drawLine(148 - x, 38 + y, 154 - x,43 + y, paint);
canvas.drawLine(154 - x, 43 + y, 157 - x,43 + y, paint);
canvas.drawLine(157 - x, 43 + y, 159 - x,41 + y, paint);
canvas.drawLine(159 - x, 41 + y, 161 - x,42 + y, paint);
canvas.drawLine(161 - x, 42 + y, 170 - x,41 + y, paint);
canvas.drawLine(170 - x, 41 + y, 177 - x,44 + y, paint);
canvas.drawLine(177 - x, 44 + y, 184 - x,48 + y, paint);
canvas.drawLine(184 - x, 48 + y, 190 - x,57 + y, paint);
canvas.drawLine(190 - x, 57 + y, 188 - x,58 + y, paint);
canvas.drawLine(188 - x, 58 + y, 189 - x,62 + y, paint);
canvas.drawLine(189 - x, 62 + y, 186 - x,64 + y, paint);
canvas.drawLine(186 - x, 64 + y, 188 - x,68 + y, paint);
canvas.drawLine(188 - x, 68 + y, 188 - x,69 + y, paint);
canvas.drawLine(188 - x, 69 + y, 187 - x,70 + y, paint);
canvas.drawLine(187 - x, 70 + y, 193 - x,78 + y, paint);
canvas.drawLine(193 - x, 78 + y, 193 - x,80 + y, paint);
canvas.drawLine(193 - x, 80 + y, 189 - x,82 + y, paint);
canvas.drawLine(189 - x, 82 + y, 189 - x,85 + y, paint);
canvas.drawLine(189 - x, 85 + y, 186 - x,88 + y, paint);
canvas.drawLine(187 - x, 88 + y, 189 - x,90 + y, paint);
canvas.drawLine(189 - x, 90 + y, 188 - x,94 + y, paint);
canvas.drawLine(188 - x, 94 + y, 190 - x,99 + y, paint);
canvas.drawLine(190 - x, 99 + y, 190 - x,100 + y, paint);
canvas.drawLine(190 - x, 100 + y, 189 - x,101 + y, paint);
canvas.drawLine(189 - x, 101 + y, 186 - x,103 + y, paint);
canvas.drawLine(186 - x, 103 + y, 176 - x,101 + y, paint);
canvas.drawLine(176 - x, 101 + y, 170 - x,107 + y, paint);
canvas.drawLine(170 - x, 107 + y, 175 - x,112 + y, paint);
canvas.drawLine(175 - x, 112 + y, 178 - x,116 + y, paint);
canvas.drawLine(178 - x, 116 + y, 182 - x,119 + y, paint);
canvas.drawLine(182 - x, 119 + y, 186 - x,121 + y, paint);
canvas.drawLine(186 - x, 121 + y, 189 - x,124 + y, paint);
canvas.drawLine(189 - x, 124 + y, 193 - x,128 + y, paint);
canvas.drawLine(193 - x, 128 + y, 196 - x,132 + y, paint);
canvas.drawLine(196 - x, 132 + y, 197 - x,135 + y, paint);
canvas.drawLine(197 - x, 135 + y, 199 - x,140 + y, paint);
canvas.drawLine(199 - x, 140 + y, 205 - x,150 + y, paint);
canvas.drawLine(205 - x, 150 + y, 205 - x,152 + y, paint);
canvas.drawLine(205 - x, 152 + y, 207 - x,155 + y, paint);
canvas.drawLine(207 - x, 155 + y, 208 - x,160 + y, paint);
canvas.drawLine(208 - x, 160 + y, 207 - x,163 + y, paint);
canvas.drawLine(207 - x, 163 + y, 207 - x,165 + y, paint);
canvas.drawLine(207 - x, 165 + y, 208 - x,167 + y, paint);
canvas.drawLine(208 - x, 167 + y, 210 - x,169 + y, paint);
canvas.drawLine(210 - x, 169 + y, 212 - x,170 + y, paint);
canvas.drawLine(212 - x, 170 + y, 212 - x,172 + y, paint);
canvas.drawLine(212 - x, 172 + y, 213 - x,176 + y, paint);
canvas.drawLine(213 - x, 176 + y, 214 - x,182 + y, paint);
canvas.drawLine(214 - x, 182 + y, 218 - x,186 + y, paint);
canvas.drawLine(218 - x, 186 + y, 217 - x,189 + y, paint);
canvas.drawLine(217 - x, 189 + y, 222 - x,191 + y, paint);
canvas.drawLine(222 - x, 191 + y, 225 - x,189 + y, paint);
canvas.drawLine(225 - x, 189 + y, 238 - x,191 + y, paint);
canvas.drawLine(238 - x, 191 + y, 240 - x,192 + y, paint);
canvas.drawLine(240 - x, 192 + y, 244 - x,192 + y, paint);
canvas.drawLine(244 - x, 192 + y, 251 - x,189 + y, paint);
canvas.drawLine(264 - x, 215 + y, 261 - x,215 + y, paint);
canvas.drawLine(261 - x, 215 + y, 261 - x,222 + y, paint);
canvas.drawLine(261 - x, 222 + y, 259 - x,222 + y, paint);
canvas.drawLine(259 - x, 222 + y, 259 - x,224 + y, paint);
canvas.drawLine(259 - x, 224 + y, 257 - x,224 + y, paint);
canvas.drawLine(257 - x, 224 + y, 257 - x,226 + y, paint);
canvas.drawLine(257 - x, 226 + y, 255 - x,226 + y, paint);
canvas.drawLine(255 - x, 226 + y, 255 - x,229 + y, paint);
canvas.drawLine(255 - x, 229 + y, 253 - x,229 + y, paint);
canvas.drawLine(253 - x, 229 + y, 250 - x,228 + y, paint);
canvas.drawLine(250 - x, 228 + y, 249 - x,228 + y, paint);
canvas.drawLine(249 - x, 228 + y, 247 - x,226 + y, paint);
canvas.drawLine(247 - x, 226 + y, 242 - x,223 + y, paint);
canvas.drawLine(242 - x, 223 + y, 241 - x,225 + y, paint);
canvas.drawLine(241 - x, 225 + y, 239 - x,227 + y, paint);
canvas.drawLine(239 - x, 227 + y, 241 - x,229 + y, paint);
canvas.drawLine(241 - x, 229 + y, 241 - x,231 + y, paint);
canvas.drawLine(241 - x, 231 + y, 244 - x,233 + y, paint);
canvas.drawLine(244 - x, 233 + y, 242 - x,237 + y, paint);
canvas.drawLine(242 - x, 237 + y, 232 - x,236 + y, paint);
canvas.drawLine(232 - x, 236 + y, 222 - x,232 + y, paint);
canvas.drawLine(222 - x, 232 + y, 220 - x,232 + y, paint);
canvas.drawLine(220 - x, 232 + y, 219 - x,235 + y, paint);
canvas.drawLine(219 - x, 235 + y, 219 - x,237 + y, paint);
canvas.drawLine(219 - x, 237 + y, 217 - x,239 + y, paint);
canvas.drawLine(217 - x, 239 + y, 214 - x,241 + y, paint);
canvas.drawLine(214 - x, 241 + y, 213 - x,239 + y, paint);
canvas.drawLine(213 - x, 239 + y, 211 - x,241 + y, paint);
canvas.drawLine(211 - x, 241 + y, 211 - x,243 + y, paint);
canvas.drawLine(211 - x, 243 + y, 209 - x,243 + y, paint);
canvas.drawLine(209 - x, 243 + y, 209 - x,245 + y, paint);
canvas.drawLine(209 - x, 245 + y, 204 - x,243 + y, paint);
canvas.drawLine(204 - x, 243 + y, 203 - x,251 + y, paint);
canvas.drawLine(203 - x, 251 + y, 206 - x,252 + y, paint);
canvas.drawLine(206 - x, 252 + y, 209 - x,255 + y, paint);
canvas.drawLine(209 - x, 255 + y, 207 - x,257 + y, paint);
canvas.drawLine(207 - x, 257 + y, 203 - x,255 + y, paint);
canvas.drawLine(203 - x, 255 + y, 200 - x,258 + y, paint);
canvas.drawLine(200 - x, 258 + y, 208 - x,264 + y, paint);
canvas.drawLine(208 - x, 264 + y, 208 - x,266 + y, paint);
canvas.drawLine(208 - x, 266 + y, 210 - x,268 + y, paint);
canvas.drawLine(210 - x, 268 + y, 230 - x,283 + y, paint);
canvas.drawLine(230 - x, 283 + y, 232 - x,283 + y, paint);
canvas.drawLine(232 - x, 283 + y, 234 - x,285 + y, paint);
canvas.drawLine(234 - x, 285 + y, 242 - x,295 + y, paint);
canvas.drawLine(264 - x, 215 + y, 266 - x,217 + y, paint);
canvas.drawLine(266 - x, 217 + y, 267 - x,225 + y, paint);
canvas.drawLine(267 - x, 225 + y, 267 - x,223 + y, paint);
canvas.drawLine(267 - x, 223 + y, 272 - x,231 + y, paint);
canvas.drawLine(272 - x, 231 + y, 274 - x,231 + y, paint);
canvas.drawLine(274 - x, 231 + y, 274 - x,232 + y, paint);
canvas.drawLine(274 - x, 232 + y, 273 - x,237 + y, paint);
canvas.drawLine(273 - x, 237 + y, 273 - x,239 + y, paint);
canvas.drawLine(273 - x, 239 + y, 275 - x,241 + y, paint);
canvas.drawLine(275 - x, 241 + y, 276 - x,241 + y, paint);
canvas.drawLine(276 - x, 241 + y, 276 - x,243 + y, paint);
canvas.drawLine(276 - x, 243 + y, 273 - x,245 + y, paint);
canvas.drawLine(273 - x, 245 + y, 273 - x,247 + y, paint);
canvas.drawLine(273 - x, 247 + y, 272 - x,248 + y, paint);
canvas.drawLine(272 - x, 248 + y, 271 - x,250 + y, paint);
canvas.drawLine(271 - x, 250 + y, 265 - x,265 + y, paint);
canvas.drawLine(265 - x, 265 + y, 250 - x,285 + y, paint);
canvas.drawLine(250 - x, 285 + y, 247 - x,287 + y, paint);
canvas.drawLine(247 - x, 287 + y, 245 - x,290 + y, paint);
canvas.drawLine(245 - x, 290 + y, 242 - x,295 + y, paint);
canvas.drawLine(168 - x, 451 + y, 171 - x,448 + y, paint);
canvas.drawLine(171 - x, 448 + y, 171 - x,445 + y, paint);
canvas.drawLine(171 - x, 445 + y, 170 - x,443 + y, paint);
canvas.drawLine(170 - x, 443 + y, 169 - x,442 + y, paint);
canvas.drawLine(169 - x, 442 + y, 160 - x,439 + y, paint);
canvas.drawLine(160 - x, 439 + y, 167 - x,412 + y, paint);
canvas.drawLine(167 - x, 412 + y, 169 - x,403 + y, paint);
canvas.drawLine(169 - x, 403 + y, 168 - x,395 + y, paint);
canvas.drawLine(168 - x, 395 + y, 170 - x,392 + y, paint);
canvas.drawLine(170 - x, 392 + y, 173 - x,380 + y, paint);
canvas.drawLine(173 - x, 380 + y, 173 - x,378 + y, paint);
canvas.drawLine(173 - x, 378 + y, 175 - x,376 + y, paint);
canvas.drawLine(175 - x, 376 + y, 173 - x,374 + y, paint);
canvas.drawLine(173 - x, 374 + y, 173 - x,371 + y, paint);
canvas.drawLine(173 - x, 371 + y, 172 - x,363 + y, paint);
canvas.drawLine(172 - x, 363 + y, 172 - x,355 + y, paint);
canvas.drawLine(172 - x, 355 + y, 174 - x,353 + y, paint);
canvas.drawLine(174 - x, 353 + y, 172 - x,350 + y, paint);
canvas.drawLine(172 - x, 350 + y, 173 - x,342 + y, paint);
canvas.drawLine(173 - x, 342 + y, 173 - x,344 + y, paint);
canvas.drawLine(173 - x, 344 + y, 174 - x,342 + y, paint);
canvas.drawLine(174 - x, 342 + y, 174 - x,340 + y, paint);
canvas.drawLine(174 - x, 340 + y, 182 - x,364 + y, paint);
canvas.drawLine(182 - x, 364 + y, 188 - x,363 + y, paint);
canvas.drawLine(188 - x, 363 + y, 186 - x,361 + y, paint);
canvas.drawLine(186 - x, 361 + y, 175 - x,337 + y, paint);
canvas.drawLine(175 - x, 337 + y, 177 - x,328 + y, paint);
canvas.drawLine(177 - x, 328 + y, 177 - x,325 + y, paint);
canvas.drawLine(177 - x, 325 + y, 178 - x,323 + y, paint);
canvas.drawLine(178 - x, 323 + y, 180 - x,320 + y, paint);
canvas.drawLine(180 - x, 320 + y, 188 - x,295 + y, paint);
canvas.drawLine(188 - x, 295 + y, 190 - x,295 + y, paint);
canvas.drawLine(190 - x, 295 + y, 222 - x,323 + y, paint);
canvas.drawLine(222 - x, 323 + y, 222 - x,325 + y, paint);
canvas.drawLine(222 - x, 325 + y, 221 - x,334 + y, paint);
canvas.drawLine(221 - x, 334 + y, 221 - x,336 + y, paint);
canvas.drawLine(221 - x, 336 + y, 219 - x,355 + y, paint);
canvas.drawLine(219 - x, 355 + y, 217 - x,370 + y, paint);
canvas.drawLine(217 - x, 370 + y, 215 - x,390 + y, paint);
canvas.drawLine(215 - x, 390 + y, 214 - x,400 + y, paint);
canvas.drawLine(214 - x, 400 + y, 209 - x,405 + y, paint);
canvas.drawLine(209 - x, 405 + y, 209 - x,407 + y, paint);
canvas.drawLine(209 - x, 407 + y, 211 - x,409 + y, paint);
canvas.drawLine(211 - x, 409 + y, 213 - x,410 + y, paint);
canvas.drawLine(213 - x, 410 + y, 215 - x,412 + y, paint);
canvas.drawLine(215 - x, 412 + y, 215 - x,413 + y, paint);
canvas.drawLine(215 - x, 413 + y, 212 - x,420 + y, paint);
canvas.drawLine(212 - x, 420 + y, 210 - x,422 + y, paint);
canvas.drawLine(210 - x, 422 + y, 207 - x,423 + y, paint);
canvas.drawLine(207 - x, 423 + y, 207 - x,426 + y, paint);
canvas.drawLine(207 - x, 426 + y, 204 - x,430 + y, paint);
canvas.drawLine(204 - x, 430 + y, 195 - x,433 + y, paint);
canvas.drawLine(195 - x, 433 + y, 194 - x,439 + y, paint);
canvas.drawLine(194 - x, 439 + y, 195 - x,442 + y, paint);
canvas.drawLine(195 - x, 442 + y, 197 - x,444 + y, paint);
canvas.drawLine(197 - x, 444 + y, 220 - x,444 + y, paint);
canvas.drawLine(220 - x, 444 + y, 230 - x,442 + y, paint);
canvas.drawLine(230 - x, 442 + y, 240 - x,445 + y, paint);
canvas.drawLine(240 - x, 445 + y, 242 - x,445 + y, paint);
canvas.drawLine(242 - x, 445 + y, 252 - x,442 + y, paint);
canvas.drawLine(252 - x, 442 + y, 263 - x,446 + y, paint);
canvas.drawLine(263 - x, 446 + y, 267 - x,446 + y, paint);
canvas.drawLine(267 - x, 446 + y, 285 - x,443 + y, paint);
canvas.drawLine(285 - x, 443 + y, 286 - x,441 + y, paint);
canvas.drawLine(286 - x, 441 + y, 288 - x,439 + y, paint);
canvas.drawLine(288 - x, 439 + y, 288 - x,433 + y, paint);
canvas.drawLine(288 - x, 433 + y, 285 - x,431 + y, paint);
canvas.drawLine(285 - x, 431 + y, 284 - x,430 + y, paint);
canvas.drawLine(284 - x, 430 + y, 275 - x,429 + y, paint);
canvas.drawLine(275 - x, 429 + y, 265 - x,422 + y, paint);
canvas.drawLine(265 - x, 422 + y, 265 - x,420 + y, paint);
canvas.drawLine(265 - x, 420 + y, 262 - x,417 + y, paint);
canvas.drawLine(262 - x, 417 + y, 267 - x,415 + y, paint);
canvas.drawLine(267 - x, 415 + y, 266 - x,408 + y, paint);
canvas.drawLine(266 - x, 408 + y, 267 - x,406 + y, paint);
canvas.drawLine(267 - x, 407 + y, 270 - x,413 + y, paint);
canvas.drawLine(270 - x, 413 + y, 272 - x,413 + y, paint);
canvas.drawLine(272 - x, 413 + y, 273 - x,411 + y, paint);
canvas.drawLine(273 - x, 411 + y, 275 - x,413 + y, paint);
canvas.drawLine(275 - x, 413 + y, 276 - x,413 + y, paint);
canvas.drawLine(276 - x, 413 + y, 281 - x,408 + y, paint);
canvas.drawLine(281 - x, 408 + y, 283 - x,409 + y, paint);
canvas.drawLine(283 - x, 409 + y, 278 - x,402 + y, paint);
canvas.drawLine(278 - x, 402 + y, 271 - x,365 + y, paint);
canvas.drawLine(271 - x, 365 + y, 272 - x,364 + y, paint);
canvas.drawLine(272 - x, 364 + y, 271 - x,363 + y, paint);
canvas.drawLine(271 - x, 363 + y, 268 - x,340 + y, paint);
canvas.drawLine(268 - x, 340 + y, 285 - x,300 + y, paint);
canvas.drawLine(251 - x, 189 + y, 253 - x,191 + y, paint);
canvas.drawLine(253 - x, 191 + y, 255 - x,189 + y, paint);
canvas.drawLine(255 - x, 189 + y, 253 - x,187 + y, paint);
canvas.drawLine(253 - x, 187 + y, 253 - x,185 + y, paint);
canvas.drawLine(253 - x, 185 + y, 254 - x,181 + y, paint);
canvas.drawLine(242 - x, 157 + y, 250 - x,147 + y, paint);
canvas.drawLine(250 - x, 147 + y, 255 - x,144 + y, paint);
canvas.drawLine(255 - x, 144 + y, 257 - x,142 + y, paint);
canvas.drawLine(257 - x, 142 + y, 261 - x,141 + y, paint);
canvas.drawLine(261 - x, 141 + y, 267 - x,135 + y, paint);
canvas.drawLine(267 - x, 135 + y, 268 - x,131 + y, paint);
canvas.drawLine(268 - x, 131 + y, 275 - x,125 + y, paint);
canvas.drawLine(275 - x, 125 + y, 276 - x,122 + y, paint);
canvas.drawLine(276 - x, 122 + y, 278 - x,121 + y, paint);
canvas.drawLine(278 - x, 121 + y, 277 - x,109 + y, paint);
canvas.drawLine(277 - x, 109 + y, 275 - x,109 + y, paint);
canvas.drawLine(275 - x, 109 + y, 271 - x,110 + y, paint);
canvas.drawLine(271 - x, 110 + y, 268 - x,111 + y, paint);
canvas.drawLine(268 - x, 111 + y, 264 - x,111 + y, paint);
canvas.drawLine(264 - x, 111 + y, 261 - x,110 + y, paint);
canvas.drawLine(261 - x, 110 + y, 261 - x,106 + y, paint);
canvas.drawLine(261 - x, 106 + y, 262 - x,105 + y, paint);
canvas.drawLine(262 - x, 105 + y, 258 - x,102 + y, paint);
canvas.drawLine(258 - x, 102 + y, 258 - x,101 + y, paint);
canvas.drawLine(258 - x, 101 + y, 264 - x,99 + y, paint);
canvas.drawLine(264 - x, 99 + y, 264 - x,98 + y, paint);
canvas.drawLine(264 - x, 98 + y, 259 - x,96 + y, paint);
canvas.drawLine(259 - x, 96 + y, 259 - x,95 + y, paint);
canvas.drawLine(259 - x, 95 + y, 261 - x,93 + y, paint);
canvas.drawLine(261 - x, 93 + y, 261 - x,92 + y, paint);
canvas.drawLine(261 - x, 92 + y, 257 - x,90 + y, paint);
canvas.drawLine(257 - x, 90 + y, 257 - x,88 + y, paint);
canvas.drawLine(257 - x, 88 + y, 260 - x,84 + y, paint);
canvas.drawLine(260 - x, 84 + y, 264 - x,80 + y, paint);
canvas.drawLine(264 - x, 80 + y, 264 - x,79 + y, paint);
canvas.drawLine(264 - x, 79 + y, 262 - x,77 + y, paint);
canvas.drawLine(262 - x, 77 + y, 262 - x,75 + y, paint);
canvas.drawLine(285 - x, 52 + y, 288 - x,52 + y, paint);
canvas.drawLine(288 - x, 52 + y, 290 - x,50 + y, paint);
canvas.drawLine(290 - x, 50 + y, 295 - x,42 + y, paint);
canvas.drawLine(312 - x, 42 + y, 314 - x,48 + y, paint);
canvas.drawLine(314 - x, 48 + y, 333 - x,129 + y, paint);
canvas.drawLine(318 - x, 120 + y, 312 - x,90 + y, paint);
canvas.drawLine(312 - x, 90 + y, 302 - x,98 + y, paint);
canvas.drawLine(302 - x, 98 + y, 300 - x,101 + y, paint);
canvas.drawLine(300 - x, 101 + y, 299 - x,102 + y, paint);
canvas.drawLine(299 - x, 102 + y, 299 - x,103 + y, paint);
canvas.drawLine(299 - x, 103 + y, 301 - x,110 + y, paint);
canvas.drawLine(301 - x, 110 + y, 301 - x,111 + y, paint);
canvas.drawLine(301 - x, 111 + y, 302 - x,112 + y, paint);
canvas.drawLine(302 - x, 112 + y, 314 - x,122 + y, paint);
canvas.drawLine(314 - x, 122 + y, 318 - x,120 + y, paint);
canvas.drawLine(333 - x, 129 + y, 337 - x,133 + y, paint);
canvas.drawLine(337 - x, 133 + y, 339 - x,133 + y, paint);
canvas.drawLine(339 - x, 133 + y, 342 - x,136 + y, paint);
canvas.drawLine(342 - x, 136 + y, 348 - x,140 + y, paint);
canvas.drawLine(348 - x, 140 + y, 352 - x,142 + y, paint);
canvas.drawLine(352 - x, 142 + y, 356 - x,146 + y, paint);
canvas.drawLine(356 - x, 146 + y, 360 - x,147 + y, paint);
canvas.drawLine(360 - x, 147 + y, 385 - x,152 + y, paint);
canvas.drawLine(385 - x, 152 + y, 389 - x,154 + y, paint);
canvas.drawLine(389 - x, 154 + y, 405 - x,156 + y, paint);
canvas.drawLine(405 - x, 156 + y, 409 - x,162 + y, paint);
canvas.drawLine(409 - x, 162 + y, 422 - x,164 + y, paint);
canvas.drawLine(422 - x, 164 + y, 422 - x,166 + y, paint);
canvas.drawLine(422 - x, 166 + y, 435 - x,168 + y, paint);
canvas.drawLine(435 - x, 168 + y, 437 - x,167 + y, paint);
canvas.drawLine(437 - x, 167 + y, 445 - x,169 + y, paint);
canvas.drawLine(445 - x, 169 + y, 448 - x,169 + y, paint);
canvas.drawLine(448 - x, 169 + y, 452 - x,171 + y, paint);
canvas.drawLine(452 - x, 171 + y, 453 - x,172 + y, paint);
canvas.drawLine(453 - x, 172 + y, 451 - x,174 + y, paint);
canvas.drawLine(451 - x, 174 + y, 448 - x,174 + y, paint);
canvas.drawLine(448 - x, 174 + y, 444 - x,175 + y, paint);
canvas.drawLine(444 - x, 175 + y, 438 - x,176 + y, paint);
canvas.drawLine(438 - x, 176 + y, 435 - x,176 + y, paint);
canvas.drawLine(435 - x, 176 + y, 434 - x,175 + y, paint);
canvas.drawLine(434 - x, 175 + y, 436 - x,179 + y, paint);
canvas.drawLine(436 - x, 179 + y, 437 - x,179 + y, paint);
canvas.drawLine(437 - x, 179 + y, 435 - x,181 + y, paint);
canvas.drawLine(435 - x, 181 + y, 430 - x,179 + y, paint);
canvas.drawLine(430 - x, 179 + y, 420 - x,178 + y, paint);
canvas.drawLine(420 - x, 178 + y, 415 - x,175 + y, paint);
canvas.drawLine(415 - x, 175 + y, 413 - x,173 + y, paint);
canvas.drawLine(413 - x, 173 + y, 411 - x,173 + y, paint);
canvas.drawLine(411 - x, 173 + y, 406 - x,174 + y, paint);
canvas.drawLine(406 - x, 174 + y, 404 - x,178 + y, paint);
canvas.drawLine(404 - x, 178 + y, 404 - x,180 + y, paint);
canvas.drawLine(404 - x, 180 + y, 405 - x,183 + y, paint);
canvas.drawLine(405 - x, 183 + y, 407 - x,186 + y, paint);
canvas.drawLine(407 - x, 186 + y, 407 - x,188 + y, paint);
canvas.drawLine(407 - x, 188 + y, 406 - x,191 + y, paint);
canvas.drawLine(406 - x, 191 + y, 405 - x,194 + y, paint);
canvas.drawLine(405 - x, 194 + y, 402 - x,195 + y, paint);
canvas.drawLine(402 - x, 195 + y, 399 - x,197 + y, paint);
canvas.drawLine(399 - x, 197 + y, 395 - x,199 + y, paint);
canvas.drawLine(395 - x, 199 + y, 392 - x,198 + y, paint);
canvas.drawLine(392 - x, 198 + y, 389 - x,196 + y, paint);
canvas.drawLine(389 - x, 196 + y, 370 - x,180 + y, paint);
canvas.drawLine(370 - x, 180 + y, 360 - x,176 + y, paint);
canvas.drawLine(360 - x, 176 + y, 355 - x,173 + y, paint);
canvas.drawLine(355 - x, 173 + y, 352 - x,172 + y, paint);
canvas.drawLine(352 - x, 172 + y, 354 - x,177 + y, paint);
canvas.drawLine(354 - x, 177 + y, 353 - x,178 + y, paint);
canvas.drawLine(353 - x, 178 + y, 353 - x,179 + y, paint);
canvas.drawLine(353 - x, 179 + y, 351 - x,177 + y, paint);
canvas.drawLine(351 - x, 177 + y, 351 - x,184 + y, paint);
canvas.drawLine(351 - x, 184 + y, 349 - x,183 + y, paint);
canvas.drawLine(349 - x, 183 + y, 346 - x,186 + y, paint);
canvas.drawLine(346 - x, 186 + y, 345 - x,189 + y, paint);
canvas.drawLine(345 - x, 189 + y, 343 - x,189 + y, paint);
canvas.drawLine(343 - x, 189 + y, 341 - x,180 + y, paint);
canvas.drawLine(341 - x, 180 + y, 339 - x,180 + y, paint);
canvas.drawLine(339 - x, 180 + y, 338 - x,183 + y, paint);
canvas.drawLine(338 - x, 183 + y, 336 - x,177 + y, paint);
canvas.drawLine(336 - x, 177 + y, 338 - x,174 + y, paint);
canvas.drawLine(338 - x, 174 + y, 337 - x,168 + y, paint);
canvas.drawLine(337 - x, 168 + y, 334 - x,166 + y, paint);
canvas.drawLine(334 - x, 166 + y, 332 - x,164 + y, paint);
canvas.drawLine(332 - x, 164 + y, 330 - x,163 + y, paint);
canvas.drawLine(330 - x, 163 + y, 326 - x,163 + y, paint);
canvas.drawLine(326 - x, 163 + y, 322 - x,174 + y, paint);
canvas.drawLine(322 - x, 174 + y, 320 - x,177 + y, paint);
canvas.drawLine(320 - x, 177 + y, 319 - x,180 + y, paint);
canvas.drawLine(319 - x, 180 + y, 316 - x,182 + y, paint);
canvas.drawLine(316 - x, 182 + y, 316 - x,184 + y, paint);
canvas.drawLine(316 - x, 184 + y, 312 - x,189 + y, paint);
canvas.drawLine(312 - x, 189 + y, 310 - x,193 + y, paint);
canvas.drawLine(310 - x, 193 + y, 310 - x,195 + y, paint);
canvas.drawLine(310 - x, 195 + y, 323 - x,207 + y, paint);
canvas.drawLine(323 - x, 207 + y, 325 - x,209 + y, paint);
canvas.drawLine(325 - x, 209 + y, 337 - x,217 + y, paint);
canvas.drawLine(337 - x, 217 + y, 342 - x,222 + y, paint);
canvas.drawLine(342 - x, 222 + y, 344 - x,225 + y, paint);
canvas.drawLine(344 - x, 225 + y, 346 - x,227 + y, paint);
canvas.drawLine(346 - x, 227 + y, 347 - x,229 + y, paint);
canvas.drawLine(285 - x, 300 + y, 288 - x,300 + y, paint);
canvas.drawLine(288 - x, 300 + y, 293 - x,325 + y, paint);
canvas.drawLine(293 - x, 325 + y, 295 - x,328 + y, paint);
canvas.drawLine(295 - x, 328 + y, 300 - x,355 + y, paint);
canvas.drawLine(300 - x, 355 + y, 299 - x,359 + y, paint);
canvas.drawLine(299 - x, 359 + y, 299 - x,360 + y, paint);
canvas.drawLine(299 - x, 360 + y, 304 - x,403 + y, paint);
canvas.drawLine(304 - x, 403 + y, 302 - x,405 + y, paint);
canvas.drawLine(302 - x, 405 + y, 301 - x,415 + y, paint);
canvas.drawLine(301 - x, 415 + y, 308 - x,418 + y, paint);
canvas.drawLine(308 - x, 418 + y, 311 - x,408 + y, paint);
canvas.drawLine(311 - x, 408 + y, 313 - x,407 + y, paint);
canvas.drawLine(313 - x, 407 + y, 315 - x,410 + y, paint);
canvas.drawLine(315 - x, 410 + y, 317 - x,409 + y, paint);
canvas.drawLine(317 - x, 409 + y, 318 - x,409 + y, paint);
canvas.drawLine(318 - x, 409 + y, 320 - x,415 + y, paint);
canvas.drawLine(300 - x, 432 + y, 306 - x,432 + y, paint);
canvas.drawLine(306 - x, 432 + y, 307 - x,431 + y, paint);
canvas.drawLine(307 - x, 431 + y, 313 - x,427 + y, paint);
canvas.drawLine(313 - x, 427 + y, 320 - x,415 + y, paint);
canvas.drawLine(300 - x, 432 + y, 297 - x,436 + y, paint);
canvas.drawLine(297 - x, 436 + y, 297 - x,437 + y, paint);
canvas.drawLine(297 - x, 437 + y, 299 - x,440 + y, paint);
canvas.drawLine(299 - x, 440 + y, 301 - x,442 + y, paint);
canvas.drawLine(301 - x, 442 + y, 302 - x,443 + y, paint);
canvas.drawLine(302 - x, 443 + y, 336 - x,443 + y, paint);
canvas.drawLine(336 - x, 443 + y, 340 - x,439 + y, paint);
canvas.drawLine(340 - x, 439 + y, 341 - x,439 + y, paint);
canvas.drawLine(341 - x, 439 + y, 344 - x,443 + y, paint);
canvas.drawLine(344 - x, 443 + y, 355 - x,441 + y, paint);
canvas.drawLine(355 - x, 441 + y, 357 - x,427 + y, paint);
canvas.drawLine(357 - x, 427 + y, 354 - x,425 + y, paint);
canvas.drawLine(354 - x, 425 + y, 353 - x,423 + y, paint);
canvas.drawLine(353 - x, 423 + y, 349 - x,417 + y, paint);
canvas.drawLine(349 - x, 417 + y, 346 - x,415 + y, paint);
canvas.drawLine(346 - x, 415 + y, 344 - x,413 + y, paint);
canvas.drawLine(344 - x, 413 + y, 344 - x,412 + y, paint);
canvas.drawLine(344 - x, 412 + y, 341 - x,400 + y, paint);
canvas.drawLine(341 - x, 400 + y, 338 - x,397 + y, paint);
canvas.drawLine(338 - x, 397 + y, 337 - x,394 + y, paint);
canvas.drawLine(337 - x, 394 + y, 338 - x,384 + y, paint);
canvas.drawLine(338 - x, 384 + y, 336 - x,360 + y, paint);
canvas.drawLine(336 - x, 360 + y, 333 - x,340 + y, paint);
canvas.drawLine(333 - x, 340 + y, 331 - x,330 + y, paint);
canvas.drawLine(331 - x, 330 + y, 330 - x,320 + y, paint);
canvas.drawLine(330 - x, 320 + y, 335 - x,290 + y, paint);
canvas.drawLine(335 - x, 290 + y, 337 - x,284 + y, paint);
canvas.drawLine(337 - x, 284 + y, 339 - x,281 + y, paint);
canvas.drawLine(339 - x, 281 + y, 341 - x,278 + y, paint);
canvas.drawLine(341 - x, 278 + y, 342 - x,277 + y, paint);
canvas.drawLine(342 - x, 277 + y, 343 - x,274 + y, paint);
canvas.drawLine(343 - x, 274 + y, 344 - x,273 + y, paint);
canvas.drawLine(344 - x, 273 + y, 346 - x,270 + y, paint);
canvas.drawLine(155 - x, 455 + y, 169 - x,450 + y, paint);
canvas.drawLine(346 - x, 270 + y, 348 - x,268 + y, paint);
canvas.drawLine(254 - x, 182 + y, 252 - x,180 + y, paint);
canvas.drawLine(100 - x, 196 + y, 103 - x,199 + y, paint);
canvas.drawLine(103 - x, 199 + y, 105 - x,199 + y, paint);
canvas.drawLine(105 - x, 199 + y, 125 - x,192 + y, paint);
canvas.drawLine(114 - x, 137 + y, 118 - x,129 + y, paint);
canvas.drawLine(119 - x, 129 + y, 120 - x,126 + y, paint);
canvas.drawLine(308 - x, 36 + y, 312 - x,43 + y, paint);
canvas.drawLine(308 - x, 36 + y, 304 - x,36 + y, paint);
canvas.drawLine(304 - x, 36 + y, 295 - x,42 + y, paint);
canvas.drawLine(280 - x, 52 + y, 285 - x,52 + y, paint);
canvas.drawLine(262 - x, 75 + y, 265 - x,65 + y, paint);
canvas.drawLine(265 - x, 65 + y, 268 - x,60 + y, paint);
canvas.drawLine(268 - x, 60 + y, 274 - x,53 + y, paint);
canvas.drawLine(274 - x, 53 + y, 280 - x,52 + y, paint);
RectF oval = new RectF(130 - x, 448 + y, 180 - x,455 + y);
canvas.drawArc(oval, 88, 92, false, paint);
oval = new RectF(312 - x, 207 + y, 350 - x,293 + y);
canvas.drawArc(oval, 330, 55, false, paint);
oval = new RectF(242 - x, 127 + y, 277 - x,183 + y);
canvas.drawArc(oval, 115, 62, false, paint);


}

Wednesday, October 5, 2011

J2EE WebApp - For Beginners


This article is for beginners who want to try out their first J2EE application. It explains the step by step process to create a web application using JSF 2.0, Rich Faces 3.3 for UI and MYSQL5.5 for database and Jboss 5.0.1GA server for deployment.


    Set up MYSQL5.5

     
  • Download and install the MYSQL Installer pack (32bit or 64bit) from http://dev.mysql.com/downloads/installer/


  • Remember and save the root password for MYSQL that you create during the installation.


  • MYSQL Services will start listening to port 3306 after successful installation.


  • Start MYSQL Command Line Client from Start Menu  and enter the root password.


  • Create a database.  Give the command,  ‘create database company ;’ (without quotes) and hit enter. You will see the response ‘Query OK, 1 row affected’.


  • Create User Id/Password for that database. Give the command, ‘grant all privileges on company.* to johnsmith@localhost identified by 'password-1';’. Here the user name is ‘johnsmith’ and password is ‘password-1’. You will need this user id/password for accessing any table with the ‘company’ database.

  •        
  • Set the ‘company’ database as default. Give the command, ‘use company;’


  • Create a table. Give the command, ‘create table EMPLOYEE (employeeFirstName varchar(20), employeeLastName varchar(20), upddttm DATE);’


  • Insert a sample record into the table. Give the command, ‘insert into EMPLOYEE (employeeFirstName,employeeLastName,upddttm) values ('Alex','Roger',current_timestamp);’



    • Set up JBOSS 5.0.1GA


  • Download and install JBOSS 5.0.1GA from http://www.jboss.org/jbossas/downloads


  • To tell Jboss to connect to your MYSQL5.5 during server startup, drop a file named ‘mysql-ds.xml’ inside the ‘ /server/default/deploy’ folder.


  • The contents of the mysql-ds.xml should contain the connection url, user name, password for the database it wants to connect.



    1. <datasources>
          <local-tx-datasource>
           <jndi-name>MySqlDS</jndi-name>
           <connection-url>jdbc:mysql://localhost:3306/company</connection-url>
           <driver-class>com.mysql.jdbc.Driver</driver-class>
           <user-name>johnsmith</user-name>
           <password>password-1</password>
           <min-pool-size>2</min-pool-size>
           <max-pool-size>10</max-pool-size>
           </local-tx-datasource>
      </datasources>


  • Please note, you have to provide optimized values for the Database connection pooling as per your database usage. Too many or too less will result in performance degrade.



    • Set up Web Application:


  • I assume, you have Eclipse 3.5 or above and JDK 1.6 installed on your machine. I also assume, you have JSF 2.0 libraries (Say Mojara 2.0) on your machine.


  • On Eclipse, Create a new Dynamic Web project – SampleWeb, with target runtime as Jboss 5.0, Dynamic Web Module version 2.5, Added to SampleWebEAR and with Context root ‘SampleWeb’. Check the ‘Generate web.xml deployment descriptor’ option in the Wizard.


  • Right click on SampleWeb  Properties  Project Facets  Check Java Server Faces 2.0. If you see further configurations required at the bottom, click the link and browse your JSF Implementation Library.


  • Rich Faces library has certain dependencies with JSF library. This example uses Rich Faces 3.3 and JSF 2.0.


  • Before we start with our JSP file, ensure, you have the following jars in your ‘lib’ directory inside web-inf folder.


      commons-beanutils.jar
      commons-collections-3.2.1.jar
      commons-digester.jar
      commons-logging.jar
      jboss-faces.jar
      jsf-api.jar
      jsf-impl.jar
      richfaces-api-3.3.3.Final.jar
      richfaces-impl-3.3.3.Final.jar
      richfaces-ui-3.3.3.Final.jar



  • Your web.xml needs the below entry to support Rich Faces.



    1. <context-param>
      <param-name>org.richfaces.SKIN</param-name>
      <param-value>blueSky</param-value>
      </context-param>
      <context-param>
      <param-name>org.richfaces.CONTROL_SKINNING</param-name>
      <param-value>enable</param-value>
      </context-param>
      <filter>
      <display-name>RichFaces Filter</display-name>
      <filter-name>richfaces</filter-name>
      <filter-class>org.ajax4jsf.Filter</filter-class>
      </filter>
      <filter-mapping>
      <filter-name>richfaces</filter-name>
      <servlet-name>Faces Servlet</servlet-name>
      <dispatcher>REQUEST</dispatcher>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>INCLUDE</dispatcher>
      </filter-mapping>


  • Before we get to the Employee. jsp, let’s create a employee bean for the page.



    1. package com.example.richfaces;
      import java.sql.Connection;
      import java.sql.ResultSet;
      import java.sql.Statement;
      import javax.naming.InitialContext;
      import javax.sql.DataSource;

      public class EmployeeBean {

      private String employeeFirstName;
      private String employeeLastName;

      public String getEmployeeFirstName() {
      return employeeFirstName;
      }

      public void setEmployeeFirstName(String employeeFirstName) {
      this.employeeFirstName = employeeFirstName;
      }

      public String getEmployeeLastName() {
      return employeeLastName;
      }

      public void setEmployeeLastName(String employeeLastName) {
      this.employeeLastName = employeeLastName;
      }

      public void doGetEmployeeName() {

      InitialContext ctx = null;
      DataSource ds = null;
      Connection conn = null;
      Statement stmt = null;
      try {
      ctx = new InitialContext();
      ds = (DataSource) ctx.lookup("java:/MySqlDS");
      conn = ds.getConnection();
      stmt = conn.createStatement();
      ResultSet rs = stmt
      .executeQuery("select employeeFirstName, employeeLastName from EMPLOYEE");
      while (rs.next()) {
      setEmployeeFirstName(rs.getString(1));
      setEmployeeLastName(rs.getString(2));
      }

      rs.close();
      stmt.close();
      conn.close();

      } catch (Exception ex) {
      // Implement finally block and better Exception handling here
      ex.printStackTrace();
      }

      }

      }


  • Add the Employee Bean entry to faces-config.xml. This way, we can refer the bean from our JSP page using ‘employee’ object



    1. <?xml version="1.0" encoding="UTF-8"?>
      <faces-config
          xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
          version="2.0">
      <managed-bean>
      <description>Employee Bean</description>
      <managed-bean-name>employee</managed-bean-name>
      <managed-bean-class>com.example.richfaces.EmployeeBean</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
      <managed-property>
      <property-name>employeeFirstName</property-name>
      <property-class>java.lang.String</property-class>
      <value />
      </managed-property>
      <managed-property>
      <property-name>employeeLastName</property-name>
      <property-class>java.lang.String</property-class>
      <value />
      </managed-property>
      </managed-bean>
      </faces-config>


  • Create a new JSP File (Employee.jsp)



    1. <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <!-- RichFaces tag library declaration -->
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      <html>
      <head>
      <title>RichFaces Example</title>
      </head>
      <body>
      <f:view>
      <a4j:form>
      <rich:panel header="RichFaces Greeter" style="width: 315px">

      <a4j:commandButton value="Get Our Employee" reRender="greeting"
      action="#{employee.doGetEmployeeName}" />

      <h:panelGroup id="greeting">
      <h:outputText value="Hello, "
      rendered="#{not empty employee.employeeFirstName}" />
      <h:outputText value="#{employee.employeeFirstName}" />
      <h:outputText value="#{employee.employeeLastName}"
      rendered="#{not empty employee.employeeFirstName}" />
      </h:panelGroup>
      </rich:panel>
      </a4j:form>
      </f:view>
      </body>
      </html>


  • You are all set!! Get going..