📄 uidemomidlet.java
字号:
/* * Copyright ? 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */package com.sun.lwuit.uidemo;import com.sun.lwuit.Button;import com.sun.lwuit.animations.CommonTransitions;import com.sun.lwuit.Command;import com.sun.lwuit.Component;import com.sun.lwuit.Dialog;import com.sun.lwuit.Display;import com.sun.lwuit.Form;import com.sun.lwuit.Image;import com.sun.lwuit.Label;import com.sun.lwuit.animations.Transition;import com.sun.lwuit.events.ActionEvent;import com.sun.lwuit.events.ActionListener;import com.sun.lwuit.events.FocusListener;import com.sun.lwuit.layouts.GridLayout;import com.sun.lwuit.plaf.Style;import com.sun.lwuit.plaf.UIManager;import com.sun.lwuit.util.Resources;import java.util.Hashtable;public class UIDemoMIDlet extends javax.microedition.midlet.MIDlet implements ActionListener { private static final Command runCommand = new Command("Run", 1); private static final Command exitCommand = new Command("Exit", 2); private static final Command backCommand = new Command("Back", 3); private static final Demo[] DEMOS = new Demo[]{//每个成员代表九宫图之一 new AnimationDemo(), new AnimationDemo(), new AnimationDemo(), new AnimationDemo(), new AnimationDemo(),new AnimationDemo(),new AnimationDemo(),new AnimationDemo(), new AnimationDemo() }; private Demo currentDemo; private static Transition componentTransitions; private Hashtable demosHash = new Hashtable(); private static Form mainMenu;//主窗体 private int cols; private int elementWidth; protected void startApp() { try { Display.init(this); Resources r = Resources.open("/res/resources.res");//读取资源文件 setMainForm(r); } catch (Throwable ex) { ex.printStackTrace(); Dialog.show("Exception", ex.getMessage(), "OK", null);//hellogv最爱的提示框弹出方式 } } protected void pauseApp() { } protected void destroyApp(boolean arg0) { } public static void setTransition(Transition in, Transition out) { mainMenu.setTransitionInAnimator(in); mainMenu.setTransitionOutAnimator(out); } public static void setMenuTransition(Transition in, Transition out) { mainMenu.setMenuTransitions(in, out); UIManager.getInstance().getLookAndFeel().setDefaultMenuTransitionIn(in); UIManager.getInstance().getLookAndFeel().setDefaultMenuTransitionOut(out); } public static void setComponentTransition(Transition t) { componentTransitions = t; mainMenu.setSmoothScrolling(false); } public static Transition getComponentTransition() { return componentTransitions; } private void setMainForm(Resources r) { //设置主题 UIManager.getInstance().setThemeProps(r.getTheme("businessTheme")); mainMenu = new MainScreenForm("LWUIT Demo") ; int width = Display.getInstance().getDisplayWidth(); //取得全屏的宽度 elementWidth = 0; //*******************窗体弹出的效果,可以实现类似IPhone、S1智能机的Touch Flo的动态窗体切换效果!********************** mainMenu.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 500)); //*************************************************************************************************************** Image[] selectedImages = new Image[DEMOS.length];//按钮被选中时的图片 Image[] unselectedImages = new Image[DEMOS.length];//按钮未被选中的图片 final ButtonActionListener bAListner = new ButtonActionListener(); for (int i = 0; i < DEMOS.length; i++) { //---------读取选中时的图片 selectedImages[i] = r.getImage("Image "+String.valueOf(i+1)); //--------读取未被选中的图片 unselectedImages[i] = r.getImage("Image "+String.valueOf(i+1)); final Button b = new Button(String.valueOf(i+1), unselectedImages[i]) { public Image getPressedIcon() { Image i = getIcon(); return i.scaled((int) (i.getWidth() * 0.8), (int) (i.getHeight() * 0.8)); } }; b.setRolloverIcon(selectedImages[i]); Style s = b.getStyle(); s.setBorder(null); s.setBgTransparency(0); s.setBgSelectionColor(0xffffff); b.setAlignment(Label.CENTER); b.setTextPosition(Label.BOTTOM); mainMenu.addComponent(b); b.addActionListener(bAListner); //按钮焦点处理 b.addFocusListener(new FocusListener() { public void focusGained(Component cmp) {//按钮取得焦点时 if (componentTransitions != null) { mainMenu.replace(b, b, componentTransitions); } } public void focusLost(Component cmp) {}//按钮失去焦点时 }); demosHash.put(b, DEMOS[i]); elementWidth = Math.max(b.getPreferredW(), elementWidth); } //Calculate the number of columns for the GridLayout according to the //screen width cols = width / elementWidth; int rows = DEMOS.length / cols; mainMenu.setLayout(new GridLayout(rows, cols)); mainMenu.addCommand(exitCommand); mainMenu.addCommand(runCommand); mainMenu.setCommandListener(this); mainMenu.show(); } /** * Command控件处理函数 */ public void actionPerformed(ActionEvent evt) { Command cmd = evt.getCommand(); switch (cmd.getId()) { case 1: currentDemo = ((Demo) (demosHash.get(mainMenu.getFocused()))); currentDemo.run(backCommand, this); break; case 2: notifyDestroyed(); break; case 3: currentDemo.cleanup(); mainMenu.refreshTheme(); mainMenu.show(); // for series 40 devices System.gc(); System.gc(); break; } } /** * Button控件处理函数 */ private class ButtonActionListener implements ActionListener { public void actionPerformed(ActionEvent evt) { currentDemo = ((Demo) (demosHash.get(evt.getSource()))); currentDemo.run(backCommand, UIDemoMIDlet.this); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -