- 爱易网页
-
Java教程
- 设计可组建的j2me UI(七) Choice
日期:2014-05-20 浏览次数:20808 次
设计可组装的j2me UI(七) Choice
?? 艾,不想解释了。贴代码算了
java 代码
?
- ?
- ?
- ?
- ?
- ??
- package?org.pook.ui;??
- ??
- import?javax.microedition.lcdui.Graphics;??
- import?javax.microedition.lcdui.Image;??
- ??
- import?org.pook.ui.core.Platform;??
- ???
- ???
- ??
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ??
- public?class?Choice?extends?Part?{??
- ??????
- ???????
- ????private?boolean??select;??
- ??????
- ??????
- ????private?Image[]?imageElements;??
- ???
- ???
- ??????
- ????public?Choice(String?label,??
- ????????????Image[]?imageElements,?boolean??select)?{??
- ????????super(0,?0,?0,?0);??
- ????????if(label?==?null)??
- ????????????label?=?"";??
- ????????this.label?=?label;??
- ????????this.select?=?select;??
- ????????this.imageElements?=?imageElements;??
- ???????
- ????}??
- ??
- ???????
- ????public?void?paint(Graphics?g)?{??
- ????????paintChoiceImpl(g);??
- ??
- ????}??
- ??
- ????private?void?paintChoiceImpl(Graphics?g)?{??
- ???????
- ????????paintChoice(g);??
- ??????????
- ????}??
- ??
- ??????
- ??????
- ????private?void?paintChoice(Graphics?g)?{??
- ????????g.drawImage(select?imageElements[0]:imageElements[1],view[X],?view[Y],??
- ????????????????????Graphics.TOP|Graphics.LEFT);??
- ????????paintLabel(g);??
- ??????????
- ????}??
- ????private?void?paintLabel(Graphics?g)?{??
- ????????if(label.equals(""))??
- ????????????return;??
- ????????g.setColor(fontColor);??
- ????????g.drawString(label,view[X]?+?imageElements[0].getWidth()?+?4,?view[Y]-2,?Graphics.TOP?|?Graphics.LEFT);??
- ??????????
- ????????if(hasFocus)??
- ????????????paintSelect(g);??
- ????}??
- ??????
- ???????
- ??
- ??????
- ????private?void?paintSelect(Graphics?g)?{??
- ????????g.drawRect(view[X]?-?1,?view[Y]??-?1,???
- ???????????????????imageElements[0].getWidth()??+?1,??
- ??????????????????imageElements[0].getHeight()?+?1);??
- ???????????????????
- ??????????
- ????}??
- ??
- ??
- ????public?void?onClick(int?keyCode)?{??
- ????????if(keyCode?==?Platform.KEY_ENTER???
- ????????????????&&?hasFocus)??
- ????????????select?=?!select;??
- ??
- ????}??
- ??
- ??
- ????public?boolean?isSelect()?{??
- ????????return?select;??
- ????}??
- ??
- ??
- ????public?void?setSelect(boolean?select)?{??
- ????????this.select?=?select;??
- ????}??
- ??
- }??
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。