📄 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(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -