`
wangxc
  • 浏览: 210533 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

J2ME中关于Lwuit的标签的综合使用

    博客分类:
  • J2ME
阅读更多
J2ME中关于Lwuit的标签的综合使用

由于我使用的主题对中文支持不好,希望大家下载或编辑一些好的主题。


package com.mopietek;

import java.io.IOException;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.sun.lwuit.Button;
import com.sun.lwuit.ButtonGroup;
import com.sun.lwuit.CheckBox;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Graphics;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.Painter;
import com.sun.lwuit.RadioButton;
import com.sun.lwuit.TabbedPane;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.animations.Transition;
import com.sun.lwuit.animations.Transition3D;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.geom.Dimension;
import com.sun.lwuit.geom.Rectangle;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.layouts.GridLayout;
import com.sun.lwuit.plaf.Style;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.table.Table;
import com.sun.lwuit.util.Resources;

public class ComponentMIDlet extends MIDlet implements ActionListener{

	public Form mainForm;
	public List mexampleList;
	public Command mBackCommand;
	
	
	protected void startApp() throws MIDletStateChangeException {
		
		if(mainForm == null){
			Display.init(this);
		try {
			Resources res = Resources.open("/javaTheme.res");
			UIManager.getInstance().setThemeProps(res.getTheme("javaTheme"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			
		Form f = new Form("测试组件");
		mainForm = f;
		f.setLayout(new BorderLayout());
		List exampleList = new List();
		mexampleList = exampleList;
		exampleList.addItem("Labels");
		exampleList.addItem("Buttons");
		exampleList.addItem("More Buttons");
		exampleList.addItem("List and ComboBox");
		exampleList.addItem("Text");
		exampleList.addItem("Layouts");
		exampleList.addItem("Events");
		exampleList.addItem("Style");
		exampleList.addItem("TabbedPane");
		exampleList.addItem("Painter");
		exampleList.addItem("Exit");
		exampleList.addActionListener(this);
		
		f.addComponent(BorderLayout.CENTER,exampleList);
		
		mBackCommand = new Command("返回");

		}
		
		mainForm.show();
	}
	
	protected void destroyApp(boolean unconditional)
			throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub
		
	}

	

	public void actionPerformed(ActionEvent ae) {
		
		if(ae.getSource() == mexampleList){
			//选中的List列表
			String selection = (String)mexampleList.getSelectedItem();
			if(selection.equals("Labels")){
				showLabels();
			}
			else if(selection.equals("Buttons")){
				showButtons();
			}
			else if(selection.equals("More Buttons")){
				showMoreButtons();
			}
			else if(selection.equals("List and ComboBox")){
				showListAndComboBox();
			}
			else if(selection.equals("Text")){
				showText();
			}
			else if(selection.equals("Layouts")){
				showLayouts();
			}
			else if(selection.equals("Events")){
				showEvents();
			}
			else if(selection.equals("Style")){
				showStyle();
			}
			else if(selection.equals("TabbedPane")){
				showTabbedPane();
			}
			else if(selection.equals("Painter")){
				showPainter();
			}
			else if(selection.equals("Exit")){
				try {
					destroyApp(true);
				} catch (MIDletStateChangeException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		        notifyDestroyed();
			}
			
		}
		
		if(ae.getCommand() == mBackCommand){
			mainForm.show();
		}
		
	}
	
	public void showLabels(){
		
		Form f = new Form("测试Label");
		f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
		Label label1 = new Label("label1");
		Image image = null;
		try {
			 image = Image.createImage("/baldy.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Label label2 = new Label(image);
		Label label3 = new Label(image);
		label3.setText("label3");
		label3.setTextPosition(Component.BOTTOM);

		f.addComponent(label1);
		f.addComponent(label2);
		f.addComponent(label3);
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
	}
	
	public void showButtons(){
		
		Form f = new Form("测试Button");
		
		try {
			 Button button1 = new Button("ClickMe");
			 button1.setTextPosition(Component.BOTTOM);
			 Image	image = Image.createImage("/baldy.png");
			 Button button2 = new Button(image);
			 Button button3 = new Button("Pic",image);
			 button3.setTextPosition(Component.BOTTOM);
			 f.addComponent(button1);
			 f.addComponent(button2);
			 f.addComponent(button3);
				
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
	}
	
	public void showMoreButtons(){
		
		Form f = new Form("MoreButtons");
		
		ButtonGroup buttonGroup = new ButtonGroup();
		
		RadioButton rb1 = new RadioButton("Mike");
		RadioButton rb2 = new RadioButton("Coffer");
		RadioButton rb3 = new RadioButton("Tea");
		rb1.addActionListener(this);
		rb2.addActionListener(this);
		rb3.addActionListener(this);
		
		buttonGroup.add(rb1);
		buttonGroup.add(rb2);
		buttonGroup.add(rb3);
		
		f.addComponent(rb1);
		f.addComponent(rb2);
		f.addComponent(rb3);
		
		
		CheckBox checkBox1 = new CheckBox("checkBox1");
		CheckBox checkBox2 = new CheckBox("checkBox2");
		CheckBox checkBox3 = new CheckBox("checkBox3");
		CheckBox checkBox4 = new CheckBox("checkBox4");
		CheckBox checkBox5 = new CheckBox("checkBox5");
		CheckBox checkBox6 = new CheckBox("checkBox6");
		
		f.addComponent(checkBox1);
		f.addComponent(checkBox2);
		f.addComponent(checkBox3);
		f.addComponent(checkBox4);
		f.addComponent(checkBox5);
		f.addComponent(checkBox6);
		
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
		
		
	}
	
	public void showListAndComboBox(){
		
		Form f = new Form("List and ComboBox");
		
		List list = new List();
		list.addItem("red");
		list.addItem("green");
		list.addItem("yellow");
		list.addItem("blue");
		list.addItem("white");
		
		ComboBox comboBox = new ComboBox(list.getModel());
		f.addComponent(list);
		f.addComponent(comboBox);
		
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
		
		
	}
	
	public void showText(){
		
		
		
		Form f = new Form("测试 Text组件");
		TextField textField = new TextField("this is write content in textField");
		
		TextArea textArea = new TextArea("this is write content in TextArea!",5,20);
		textArea.setMaxSize(512);
		
		f.addComponent(textField);
		f.addComponent(textArea);
		
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
		
		
	}
	
	public void showLayouts(){
		
		Form f = new Form("Text Layouts");
		f.setLayout(new BorderLayout());
		
		
		try{
			Image image = Image.createImage("/baldy.png");
			
			Label label = new Label(image);
			label.setAlignment(Component.CENTER);
            label.setText("Label in Layouts");
            label.setTextPosition(Component.BOTTOM);
            
//          Container buttonContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
            Container buttonContainer = new Container();
            GridLayout exampleLayout = new GridLayout(3,2);
            buttonContainer.setLayout(exampleLayout);
            buttonContainer.addComponent(new Button("Add"));
            buttonContainer.addComponent(new Button("Remove"));
            buttonContainer.addComponent(new Button("Edit"));
            buttonContainer.addComponent(new Button("Send"));
            buttonContainer.addComponent(new Button("Receive"));
            buttonContainer.addComponent(new Button("Exit"));
            
            f.addComponent(BorderLayout.NORTH,label);
            f.addComponent(BorderLayout.CENTER,buttonContainer);
            
            f.addCommand(mBackCommand);
            f.setCommandListener(this);
            f.show();
            
            
			
		}catch(IOException e){
			e.printStackTrace();
		}
		
	}
	
	public void showEvents(){
	
		Form f = new Form("Test Events");
		f.setLayout(new BorderLayout());
		
	    final Button button = new Button("Click Me");
		button.addActionListener(new ActionListener(){
             int i = 0;
			public void actionPerformed(ActionEvent av) {
                     i++;
                     button.setText("NO."+i+"Clicked");
			}
			
		});
		
		f.addComponent(BorderLayout.NORTH,button);
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
		
	}
	
	public void showStyle(){
		
		Form f = new Form("Style");
		f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
		
		Label label1 = new Label("No using Style");
		//设置标签为透明色
		Label label2 = new Label("Transparent");
		label2.getStyle().setBgTransparency(0);
		//改变标签背景色
		Label label3 = new Label("Change the BackGroud Color and Font Color");
		Style style = label3.getStyle();
		style.setBgColor(0xaa00ff);
		//字体颜色为白色
		style.setFgColor(0xffffff);
		//设置margin的大小
		Label label4 = new Label("Margin around is 10px");
		label4.getStyle().setMargin(10,10,10, 10);
		//设置padding的大小
		Label label5 = new Label("Padding around is 20px");
		label5.getStyle().setPadding(20,20,20,20);
		
		f.addComponent(label1);
		f.addComponent(label2);
		f.addComponent(label3);
		f.addComponent(label4);
		f.addComponent(label5);
		
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
		
		
		
		
		
		
		
		
		
	}
	
	public void showTabbedPane(){
		
		Form f = new Form("TabbedPane");
		f.setLayout(new BorderLayout());
		
		TabbedPane tabbedPane = new TabbedPane(TabbedPane.TOP);
		tabbedPane.addTab("tab1", new Label("this is label One"));
		tabbedPane.addTab("Tab2", new Label("this is label Two"));
		f.addComponent(BorderLayout.NORTH, tabbedPane);
		f.addCommand(mBackCommand);
		f.setCommandListener(this);
		f.show();
	}
	
	public void showPainter(){
		
		Form f = new Form("Painter");

	    try {
	      Label label = new Label("Baldy");

	      Image image = Image.createImage("/baldy.png");
	      Label pictureLabel = new Label(image);

	      Label bottomText = new Label(image);
	      bottomText.setText("Baldassare");
	      bottomText.setTextPosition(Component.BOTTOM);

	      f.addComponent(label);
	      f.addComponent(pictureLabel);
	      f.addComponent(bottomText);
	    } catch (IOException ioe) {
	      System.out.println(ioe);
	    }
	    
	    final int bg = f.getStyle().getBgColor();
	    final int fg = f.getStyle().getFgColor();
	    
	    f.getStyle().setBgPainter(new Painter() {
	        public void paint(Graphics g, Rectangle rect) {
	            int s = 12;
	            
	            Dimension size = rect.getSize();
	            int rx = rect.getX();
	            int ry = rect.getY();
	            int rw = size.getWidth();
	            int rh = size.getHeight();
	            
	            g.setColor(bg);
	            g.fillRect(rx, ry, rw, rh);
	            //画棱形
	            g.setColor(fg);
	            for (int y = 0; y < rh; y += 2 * s) {
	              for (int x = 0; x < rw; x += s) {
	                g.fillTriangle(rx + x, ry + y + s, rx + x + s / 2, ry + y,        rx + x + s, ry + y + s);
	                g.fillTriangle(rx + x, ry + y + s, rx + x + s / 2, ry + y + 2 *s, rx + x + s, ry + y + s);
	              }
	            }
	        }
	    });

	    f.addCommand(mBackCommand);
	    f.setCommandListener(this);
	    
	    //增加3D特效                                                                //时间  //true为逆时针翻转(向右翻转) false为顺时针翻转(向左翻转)
	    Transition t = Transition3D.createCube(400, true);
	    if (t == null)   //当t为null时,通过 CommonTransitions创建特效 //第一参数为type , 第二参数 为翻转, 第三参数时间
	      t = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 700);
	    f.setTransitionInAnimator(t);
	    
	    t = Transition3D.createCube(400, false);
	    if (t == null)                    // type是"SLIDE_VERTICAL"为上下切换,SLIDE_HORIZONTAL为左右切换
	      t = CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 700);
	    f.setTransitionOutAnimator(t);

	    f.show();
	}

}


  • 大小: 1.8 KB
  • 大小: 8 KB
分享到:
评论

相关推荐

    lwuit.rar_J2ME lwuit_LWUIT_j2me_j2me LWU_九宫

    标题中的"lwuit.rar_J2ME lwuit_LWUIT_j2me_j2me LWU_九宫"表明这是一个与LWUIT相关的压缩包,内容可能包含了实现J2ME平台上九宫图功能的代码或资源。 九宫图是一种常见的界面布局方式,通常用于显示多个小视图,如...

    lwuit.rar_J2ME ui_LWUIT_j2me

    在LWUIT中,模型负责管理应用程序的数据和业务逻辑,视图负责显示数据和接收用户输入,控制器则作为两者之间的桥梁,处理用户的交互事件并更新模型或视图。 LWUIT包含了一系列的组件,如按钮、文本框、列表、表单、...

    lwuit_demo_src.rar_DEMO_J2ME lwuit de_LWUIT_lwuit demo

    在标签中提到了"demo j2me",这表明这个示例是针对J2ME平台的。J2ME是Java的一个子集,主要用于嵌入式系统和移动设备。通过LWUIT,开发者可以使用Java编写跨平台的移动应用,而无需关心底层硬件的差异。 "lwuit_de...

    j2me ui lwuit 1.3

    1. **组件库**:LWUIT 包含了一套丰富的组件集合,如按钮、文本框、标签、列表、表格等,这些组件都经过优化,可以在资源有限的 J2ME 设备上高效运行。开发者可以利用这些组件快速搭建应用程序的界面。 2. **样式和...

    J2ME文件浏览器(LWUIT版)

    - **TreeView组件**:LWUIT中的TreeView可以用来表示文件系统的层级结构。每个节点都包含一个图标(文件或目录)、文本(文件名或目录名)以及可能的子节点。 - **FileSystemModel**:这是J2ME中用于处理文件系统...

    J2ME+UI框架LWUIT开发手册

    2. **创建项目**:在开发环境中新建一个J2ME项目,并导入LWUIT库。 3. **定义主题**:使用LWUIT的ThemeResoure类来创建和配置主题,可以指定颜色、字体、图像等资源。 4. **设计界面**:使用LWUIT的组件来构建应用...

    J2ME LWUIT 之九宫图

    在J2ME和LWUIT中实现九宫图,首先需要理解LWUIT的基础组件,如Container(容器)和Component(组件)。Container可以容纳多个Component,如Button、Label等,通过自定义布局管理器,我们可以创建出九宫格的效果。...

    lwuit实例 lwuit j2me 界面

    描述中提到的“最新开源 j2me 资源代码”可能是指包含LWUIT库的最新版本或者是一些开发者社区共享的示例代码库,这些资源有助于开发者理解和学习如何在Eclipse这样的集成开发环境中使用LWUIT。Eclipse是一个广泛使用...

    j2me天气预报(lwuit)

    【J2ME天气预报(LWUIT)】是一款利用Java Micro Edition...总的来说,"j2me天气预报(lwuit)"是一个集成了网络通信、数据解析、本地存储和UI设计的综合项目,对于学习J2ME和LWUIT的开发者来说,是一个很好的实践案例。

    LWUIT,j2me教程

    LWUIT,j2me教程,LWUIT 简介 教程与文档 问答LWUIT是一个轻量级JavaME UI工具包。特性:类似Swing 的MVC架构,支持多种布局(Layouts),皮肤更换,字体,触摸屏,动画效果...

    j2me lwuit 1.4 源码+示例

    LWUIT(Lightweight User Interface Toolkit)是J2ME中的一个UI库,旨在提供更高效、更美观的用户界面设计能力。LWUIT 1.4版本在原有的基础上进行了优化和增强,使得开发者能够更加便捷地创建出具有吸引力的图形用户...

    J2ME入门教程与LWUIT实例

    J2ME入门教程与LWUIT实例,主要给新手提供

    J2ME中用LWUIT画简单的指针时钟

    J2ME中用LWUIT画简单的指针时钟 by thriller at http://tyche.cn LWUIT(The Lightweight UI Toolkit)是一个轻量级JavaME 用户界面工具包。LWUIT类似Swing 的MVC架构, 支持多种布局(Layouts), 皮肤更换, 字体, ...

    LWUIT j2me UI例子

    1. **组件使用**:如何添加和配置LWUIT中的按钮、文本框、列表等基本组件。 2. **布局管理**:理解并实践GridLayout、BoxLayout、FlowLayout、FormLayout等布局方式,以及如何自定义布局。 3. **主题定制**:学习...

    j2me记事本lwuit高级界面

    本项目为j2me实现的记事本程序,包括新建 保存 读取 修改 等功能,内建lwuit类库,实现了aero效果。(本项目创建平台为NetBeans6.8)

    J2me 轻量级UI控件-lwuit1.2.1

    总的来说,LWUIT 1.2.1为J2ME开发者提供了一个强大且富有表现力的UI框架,虽然其大小可能不适合所有设备,但通过合理的优化和利用,可以在许多移动应用中实现令人满意的用户体验。对于那些寻求超越MIDP标准UI限制的...

    J2me中文教程 pdf

    J2me中文教程.pdf J2me中文教程.pdf

    J2ME中文输入Demo

    在J2ME中,使用Unicode编码处理中文字符至关重要,因为它能确保正确地存储和传输中文字符。 3. **输入法引擎** 中文输入法通常涉及到拼音输入、笔画输入或五笔字型等。在J2ME平台上,由于资源限制,拼音输入是最...

    最新LWUIT_1_5

    通过这个压缩包中的LWUIT_1_5,开发者可以获得完整的库文件和相关的文档,以开始或升级他们基于J2ME的手机应用开发。使用LWUIT可以显著提升应用程序的视觉效果,提高用户满意度,同时减轻开发者在界面设计方面的负担...

Global site tag (gtag.js) - Google Analytics