?? listdemo.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.Command;import com.sun.lwuit.Dialog;import com.sun.lwuit.Form;import com.sun.lwuit.List;import com.sun.lwuit.events.ActionEvent;import com.sun.lwuit.events.ActionListener;import com.sun.lwuit.layouts.BorderLayout;import com.sun.lwuit.list.DefaultListModel;/** *本例演示如何使用List控件 */public class ListDemo implements ActionListener { public Form form = new Form("ListDemo"); private Command backCommand = new Command("Back", 1); private String[] str_list = { "aaaaaaaaaaaa", "bbbbbbbbbbbb", "ccccccccccccc", "ddddddddddddd" }; ListDemo(){ form.setLayout(new BorderLayout()); form.addCommand(backCommand); form.setScrollable(true); //列表控件,盡管列表控件占用不少面積,但實際上跟普通的Componet一樣 DefaultListModel myListModel = new DefaultListModel(str_list); List list = new List(myListModel); list.getStyle().setBgTransparency(100); //按鈕控件 Button button = new Button("test"); form.addComponent(BorderLayout.CENTER,list); form.addComponent(BorderLayout.NORTH,button); list.addActionListener(this); form.setCommandListener(this); } public void actionPerformed(ActionEvent arg0) { try{//處理列表事件 String str=((List)(arg0.getSource())).getSelectedItem().toString(); Dialog.show("ListDemo", str, "OK", null); }catch(Exception e)//處理COMMAND事件 { Command command=arg0.getCommand(); if(command==backCommand) UIDemoMIDlet.backToMainMenu(); } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -