4

I'm going to draw some sort of glassy buttons in java me (targeting devices with MIDP 2.0). An Example: enter image description here

Actually I need to impelement Gradient and Bevel-Emboss effects in Java ME, do you have any opinion or "guideline" on how to implement this?

EDIT: Now I know how to draw gradient background, but That is not sufficient. Is it possible to draw such glassy button in Java ME? I've worked with C# and I can draw these kinds of glassy buttons there, but I'm struggling on how to simulate something like these buttons in Java ME or at least something near to them, Note that I'm looking for a good guidance and help to move forward.

Do I need to provide more information? If so, please let me know. Thanks In advance.

Harry.B
  • 621
  • 5
  • 18
  • 1
    OMG! I can't beleive that someone put bounty on my question! Thank you so much, I'm still working on the problem and any help would be greatly appreciated. – Harry.B May 30 '11 at 19:33
  • Do you want to draw such buttons on a Canvas or a Form? Do the buttons have constant height? (Or at least a few predefined heights) – Oleh Prypin May 31 '11 at 09:57
  • @BlaXpirit: The buttons have a few predefined sizes. Consider a form which has some buttons that interact with user. Thanks in advance. – Harry.B May 31 '11 at 12:25

3 Answers3

2

You can use LWUIT framework for developing java-me (MIDP 2.0) applications. Its good GUI framework for java-me application. Here you can create the theme manually using ResourceEdit. For more info see this discussion and LWUIT blog also.

Community
  • 1
  • 1
bharath
  • 14,283
  • 16
  • 57
  • 95
2

You can do it by using an alpha gradient paint. Heres an example:

Graphics2D g = (Graphics2D)screen.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setFont(new Font("Serif", Font.BOLD, 30));
Color c1 = new Color(0,0,0,0);
Color c2 = new Color(0,0,0,100);
GradientPaint gradient = new GradientPaint(10,8,c1,10,40,c2,true);

g.setColor(Color.GREEN);
g.fillRect(0, 0, screen.width, screen.height);
g.setColor(Color.BLACK);
g.setPaint(gradient);
g.fillRoundRect(100, 100, 200, 50, 25, 25);
g.setPaint(Color.BLACK);
g.drawRoundRect(100, 100, 200, 50, 25, 25);
g.drawString("Hello World!", 118, 135);

it will look like this:

Button with green background

Stas Jaro
  • 4,747
  • 5
  • 31
  • 53
  • Thanks a lot. Does "Graphics2D" and "GradientPaint" classes exists in J2ME standard SDK? or should I have to install separate package? and Are these classes compatible with MIDP 2.0? – Harry.B Jun 05 '11 at 12:28
  • 1
    Yes. Instead of using Graphics just use the class Graphics2D. Graphics is just a stripped down version of graphics2d. You can get all the imports you need for this from java.awt.*; including the gradient paint. You can play around with the gradient paint settings to get the look you want for your button. Make sure to reset your paint (setPaint(color.black);) after you finish drawing the gradients. – Stas Jaro Jun 07 '11 at 11:23
1

yoy can not do so in me because it dont have such reach effect on UI

get image that have effect like that gredient and make it transparent using

btn.getStyle().setBgTransparency(100) // from 0-255

note: you must use images that is already semi transparent , if not than setBgTransparency would not work properly

I can not recommend you to use canvas

i recommend you to use use LWUIT

it have many more effects ads you required ,like

btnBuzz.getStyle().setBorder(Border.createBevelLowered());

it have different layout as well

Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
  • Thanks, How much size does this framework adds to my final project? and Does it support MIDP 2.0 ? – Harry.B May 31 '11 at 12:45
  • yes, it supports MIDP 2.0, 2.1 as wel, it will cost you about 700kb only, you can also get source and remove unused classes – Nirmal- thInk beYond May 31 '11 at 13:22
  • 2
    I'm agree with Nirmal, LWUIT is awesome. I used for a project and it looks great. – vsm Jun 01 '11 at 04:19
  • Thanks, Now I'm looking for a guide on how to accomplish my task using LWUIT. What's your suggestion? For example, 1)Creating a transparent gradient background 2)Drawing Bevel Border,3)... ? – Harry.B Jun 01 '11 at 07:03
  • start with this tutorial:http://lwuit.java.net/tutorial/index.html, create demo app, u will get idea, its too simple – Nirmal- thInk beYond Jun 01 '11 at 08:38