⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 choice.java

📁 这个是用系统时间产生随机数应用的一个小程序
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;

public class choice extends MIDlet implements CommandListener
{ Random rand;
   int time;
   Display display;
   Form form1;
   canvasForm canvasform; 
   TextField tf1;
   TextField tf2;
   TextField tf3;
   TextField tf4;
   Command okCommand;
   Command exitCommand;

 
   public choice(){
	
	   display=Display.getDisplay(this);
	   canvasform=new canvasForm();
	   form1=new Form("input somethings");
	   rand=new Random();
	   tf1=new TextField("1:","",20,TextField.ANY);
	   tf2=new TextField("2:","",20,TextField.ANY);
	   tf3=new TextField("3:","",20,TextField.ANY);
	   tf4=new TextField("4:","",20,TextField.ANY);
	   okCommand=new Command("FINAL ONE",Command.OK,2);
	   exitCommand = new Command("EXIT",Command.EXIT,2);
	   form1.append(tf1);
	   form1.append(tf2);
	   form1.append(tf3);
	   form1.append(tf4);
	   form1.addCommand(okCommand);
	   form1.addCommand(exitCommand);
	   form1.setCommandListener(this);
	   
   }
protected void destroyApp(boolean unconditional) {}
protected void pauseApp() {}
protected void startApp()  {
display.setCurrent(form1);

}
class canvasForm extends Canvas implements CommandListener{
	
	Command backCommand;
	int face=Font.FACE_MONOSPACE;
	int size=Font.SIZE_LARGE;
	int style=Font.STYLE_BOLD;
	public  canvasForm()
 {
	 backCommand = new Command("BACK",Command.BACK,2);
	addCommand(backCommand);
	setCommandListener(this);
}
protected void paint(Graphics g) {
	g.setColor(0xfffacd);
	g.fillRect(0, 0, getWidth(), getHeight());
	g.setColor(0);
	time=Math.abs(rand.nextInt()%4);
	g.setFont(Font.getFont(face,style,size));
	if(time==0)
	{g.drawString("it's maybe good for u:", 0, 0, Graphics.LEFT|Graphics.TOP);	
	g.drawString(tf1.getString(), getWidth()/2, 50, Graphics.HCENTER|Graphics.TOP);}
	else if(time==1)
	{g.drawString("it's maybe good for u:", 0, 0, Graphics.LEFT|Graphics.TOP);	
	g.drawString(tf2.getString(), getWidth()/2, 50, Graphics.HCENTER|Graphics.TOP);}
	else if(time==2)
	{g.drawString("it's maybe good for u:", 0, 0, Graphics.LEFT|Graphics.TOP);	
	g.drawString(tf3.getString(), getWidth()/2, 50, Graphics.HCENTER|Graphics.TOP);}
	else if(time==3)
	{g.drawString("it's maybe good for u:", 0, 0, Graphics.LEFT|Graphics.TOP);	
	g.drawString(tf4.getString(), getWidth()/2, 50, Graphics.HCENTER|Graphics.TOP);}
	
}

public void commandAction(Command cmd, Displayable disp) {
	if(cmd==backCommand)
		display.setCurrent(form1);	


}

}

public void commandAction(Command cmd, Displayable disp) {
if(cmd==okCommand)
{display.setCurrent(canvasform);

}
if(cmd==exitCommand)
{ 
destroyApp(false);
notifyDestroyed();
}	
}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -