📄 select.java
字号:
package remote.display;// standardimport java.io.ByteArrayInputStream;import java.util.Hashtable;import java.util.Stack;//micro editionimport javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;import javax.microedition.midlet.*;import javax.microedition.io.*;import java.io.*;class Select extends GameCanvas implements Runnable{ int screenWidth; int screenHeight; private Graphics g; private Display display; Font font_label; Font font_text; int Textfield_height; int Textfield_width; int choice; int type; public String selected_file; String first_field, second_field, third_field; String temp_first,temp_second,temp_third; public Thread thread; DisplayMain main; public boolean select_pressed; protected Select(Display dis, String f, String s, String t, int c, DisplayMain m) { super(true); screenWidth =128; screenHeight=160; font_label = Font.getFont (Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM); font_text = Font.getFont (Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); int Text_height = 0; Text_height += font_label.getHeight(); Text_height += font_text.getHeight(); Textfield_height=Text_height+2; Textfield_width=screenWidth; first_field =f; second_field =s; third_field =t; main = m; type = c; //set the full screen mode setFullScreenMode(true); select_pressed=false; this.display = dis; thread =new Thread(this); thread.start(); g = this.getGraphics(); draw(); } public void draw () { choice = 0; draw_choice(choice); } private void draw_image(String image_name, int x, int y, int anchor){ Image pic =null; try{ pic =Image.createImage("/"+image_name); } catch (IOException e) { System.out.println ("load png resource error" + e.getMessage()); } g.drawImage (pic, x, y, anchor); } private void draw_textfield (String label , String text, int x, int y) { g.setColor(0,0,0); g.setFont(font_label); g.drawString(label, x, y, Graphics.TOP|Graphics.LEFT); g.setFont(font_text); g.drawString(text, x, font_label.getHeight()+y, Graphics.TOP|Graphics.LEFT); } private void draw_select_pic(int x, int y) { int[] maskArray; maskArray = new int[Textfield_width*Textfield_height]; for (int i = 0; i < Textfield_width*Textfield_height; i++) { if (i<Textfield_width*3|| i >= Textfield_width*Textfield_height-Textfield_width*3){ maskArray[i]=0xCDEEEEEE; //set to gery color }else{ maskArray[i] = 0xCDFFD163; //set to orange color } } g.drawRGB(maskArray,0,Textfield_width,x, y, Textfield_width, Textfield_height,true); } public void draw_choice(int c) { //drawing g.setColor(255,255,255); g.fillRect(0,0,screenWidth,screenHeight); draw_image ("select_bg.png", screenWidth, screenHeight,Graphics.BOTTOM|Graphics.RIGHT); if (type==0) { draw_image("connection_text.png",screenWidth/2,screenHeight*3/100, Graphics.TOP| Graphics.HCENTER); } if (type==1) { draw_image("transfer_text.png",screenWidth/2,screenHeight*3/100, Graphics.TOP|Graphics.HCENTER); } if (type ==2) { draw_image("setting_text.png",screenWidth/2,screenHeight*3/100, Graphics.TOP|Graphics.HCENTER); } if (c ==0) { draw_select_pic(0,screenHeight/7); } if (c==1) { draw_select_pic(0,screenHeight/7+font_label.getHeight()+font_text.getHeight()); } if (c==2) { draw_select_pic(0,screenHeight/7+(font_label.getHeight()+font_text.getHeight())*2); } //first temp_first =first_field.substring(0,first_field.length()); if (font_text.stringWidth(first_field) >screenWidth*95/100){ for (int i=0; i<first_field.length();i++) { temp_first=first_field.substring(0,i); if (font_text.stringWidth(temp_first) >screenWidth*95/100){ temp_first = temp_first.substring(0,i-3) +"..."; break; } } } //second temp_second =second_field.substring(0,second_field.length()); if (font_text.stringWidth(second_field) >screenWidth*95/100){ for (int i=0; i<second_field.length();i++) { temp_second=second_field.substring(0,i); if (font_text.stringWidth(temp_second) >screenWidth*95/100){ temp_second = temp_second.substring(0,i-3) +"..."; break; } } } //third temp_third =third_field.substring(0,third_field.length()); if (font_text.stringWidth(third_field) >screenWidth*95/100){ for (int i=0; i<third_field.length();i++) { temp_third=third_field.substring(0,i); if (font_text.stringWidth(temp_third) >screenWidth*95/100){ temp_third = temp_third.substring(0,i-3) +"..."; break; } } } if (type==0) { draw_textfield("IP",temp_first,5,screenHeight/7); draw_textfield("Login name",temp_second,5,screenHeight/7+font_label.getHeight()+font_text.getHeight()); int temp; String display_pw=""; temp =third_field.length(); for (int i=0; i<temp; i++) { display_pw+="*"; } temp_third =display_pw.substring(0,third_field.length()); if (font_text.stringWidth(third_field) >screenWidth*95/100){ for (int i=0; i<third_field.length();i++) { temp_third=display_pw.substring(0,i); if (font_text.stringWidth(temp_third) >screenWidth*95/100){ temp_third = temp_third.substring(0,i-3) +"..."; break; } } } draw_textfield("Password",temp_third,5,screenHeight/7+(font_label.getHeight()+font_text.getHeight())*2); } if (type ==1) { draw_textfield("Email",temp_first,5,screenHeight/7); draw_textfield("Title",temp_second,5,screenHeight/7+font_label.getHeight()+font_text.getHeight()); draw_textfield("Content",temp_third,5,screenHeight/7+(font_label.getHeight()+font_text.getHeight())*2); draw_file_selected(); } if (type ==2) { draw_textfield("Sound Effect",temp_first,5,screenHeight/7); draw_textfield("Default IP address",temp_second,5,screenHeight/7+font_label.getHeight()+font_text.getHeight()); } flushGraphics(); } private void draw_file_selected() { String temp; String content="File: " +selected_file+" "; int k=0; int l=0; int j=0; g.setColor(0,0,0); g.setFont(font_text); if (font_text.stringWidth(content) >screenWidth*95/100){ for (int i=0; i<content.length();i++) { //if (content.charAt(i)==' ') { temp=content.substring(k,i); if (font_text.stringWidth(temp) >screenWidth*95/100){ temp = content.substring(k,j); g.drawString(temp,5, screenHeight/7+(font_label.getHeight()+font_text.getHeight())*3+(font_text.getHeight()*l) ,Graphics.TOP|Graphics.LEFT); l++; k=j; temp=content.substring(k,content.length()); if (font_text.stringWidth(temp) <=screenWidth*95/100) { g.drawString(temp,5, screenHeight/7+(font_label.getHeight()+font_text.getHeight())*3+(font_text.getHeight()*l) ,Graphics.TOP|Graphics.LEFT); } } j=i; } //} } else { g.drawString(content ,5, screenHeight/7+(font_label.getHeight()+font_text.getHeight())*3 ,Graphics.TOP|Graphics.LEFT); } } public String get_first_field() { return first_field; } public String get_seconf_field() { return second_field; } public String get_third_field() { return third_field; } public void set_first_field(String f) { first_field=f; } public void set_second_field(String s) { second_field=s; } public void set_third_field(String t) { third_field=t; } public void key_Pressed() { int keyState =getKeyStates(); if ((keyState & UP_PRESSED) !=0) { choice --; if (type==2) { if (choice<0) { choice =1; } } if (choice <0) { choice =2; } draw_choice(choice); } if ((keyState & DOWN_PRESSED) !=0) { choice ++; if (type==2) { if (choice >1) { choice=0; } } if (choice >2) { choice =0; } draw_choice(choice); } if ((keyState & FIRE_PRESSED) !=0) { if (type ==2) { if (choice ==0) { if (first_field.equals("Open")){ first_field ="Close"; main.sound_setting=false; String abc="0"; main.data_sound=abc.getBytes(); try{ main.rs.setRecord(2,main.data_sound,0,1); }catch (Exception e){ System.out.println(e); } } else{ first_field="Open"; main.sound_setting=true; String abc="1"; main.data_sound=abc.getBytes(); try{ main.rs.setRecord(2,main.data_sound,0,1); }catch (Exception e){ System.out.println(e); } } draw_choice(choice); } if (choice ==1) { select_pressed =true; main.textbox("",second_field,"",choice,type); } }else { select_pressed =true; main.textbox(first_field, second_field, third_field,choice,type); } } } public void run() { while (!select_pressed) { key_Pressed(); try { Thread.sleep(100); }catch (InterruptedException ie) {} } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -