📄 visualmidlet.java
字号:
/*
* VisualMidlet.java
*
* Created on 2007年4月12日, 下午1:43
*/
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import java.io.PrintStream;
import javax.microedition.midlet.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
/**
*
* @author Administrator
*/
public class VisualMidlet extends MIDlet implements CommandListener {
/** Creates a new instance of VisualMidlet */
public VisualMidlet() {
initialize();
}
private List ChooseDemo;
private Ticker ticker1;
private Ticker ticker2;
private TextBox Damao;
private Ticker ticker3;
private Command exitCommand1;
private List DaPan;
private Ticker ticker4;
private List ZongHe;
private Ticker ticker5;
private Command backCommand1;
private Command backCommand2;
private Command backCommand12;
private Command okCommand1;
private Command okCommand2;
private Command okCommand3;
private Command backCommand3;
private Command okCommand4;
private List ZiXun;
private Ticker ticker6;
private Command backCommand4;
private Command okCommand5;
private Form form1;
private Ticker ticker7;
private StringItem stringItem1;
private StringItem stringItem2;
private StringItem stringItem3;
private StringItem stringItem4;
private Command backCommand5;
private Command okCommand6;
private List GuPiaoXiangQing;
private Command backCommand6;
private Command okCommand7;
private List TuXing;
private Ticker ticker8;
private Ticker ticker9;
private Command backCommand7;
String[] data = null;
private String ddkl;
HttpConnection c;
InputStream is;
// private String dapan;
public String conv;
String StockCode;
/** Called by the system to indicate that a command has been invoked on a particular displayable.
* @param command the Command that ws invoked
* @param displayable the Displayable on which the command was invoked
*
*/
public String run(){
StockCode = get_Damao().getString();
Thread thread=new Thread(){
public void run(){
try{
c=(HttpConnection)Connector.open("http://finance.yahoo.com/d/quotes.csv?s="+ StockCode +"&f=sl1d1t1c1ohgv&e=.csv");
//判断连接是否正常
int status=c.getResponseCode();
if(status!=HttpConnection.HTTP_OK)
throw new IOException("Response code not ok");
else{
is=c.openInputStream();//打开输入流,读入数据
byte[] b = new byte[256];
int length = is.read(b, 0, b.length);
if (length > 0)
{
String ad=new String(b, 0, length);
data=split(ad ,",");
String code=data[0];
String recentPrice=data[1];
String date=data[2];
String time=data[3];
String zd=data[4];
String kaipan=data[5];
String highest=data[6];
String lowest=data[7];
String deal=data[8];
ddkl="股票行情如下:" + "\n"
+"交易代码: "+code+"\n"
+"最近交易价: "+recentPrice+"\n"
+"交易日期: "+date+"\n"
+"交易时间: "+time+"\n"
+"涨跌: "+zd+"\n"
+"开盘: "+kaipan+"\n"
+"今日价格幅度:"+lowest+"---"+highest+"\n"
+"成交量: "+deal;
//dapan=code+recentPrice+zd+kaipan;
// tb.setString(ddkl);
}
// Display.getDisplay(this).setCurrent(tb);
//}
}
} catch (IOException e) {
}
finally{
if(is!=null)
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
if(c!=null)
try {
c.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}; thread.start();
return ddkl;
}
private static String[] split(String original,String regex)
{
// 取子串的起始位置
int startIndex = 0;
// 将结果数据先放入Vector中
Vector v = new Vector();
//返回的结果字符串数组
String[] str = null;
// 存储取子串时起始位置
int index = 0;
// 获得匹配子串的位置
startIndex = original.indexOf(regex);
// System.out.println("0" + startIndex);
//如果起始字符串的位置小于字符串的长度,则证明没有取到字符串末尾。
//-1代表取到了末尾
while(startIndex < original.length() && startIndex != -1)
{
String temp = original.substring(index,startIndex);
//System.out.println(" " + startIndex);
//取子串
v.addElement(temp);
//设置取子串的起始位置
index = startIndex + regex.length();
//获得匹配子串的位置
startIndex = original.indexOf(regex,startIndex + regex.length());
}
//取结束的子串
v.addElement(original.substring(index + 1 - regex.length()));
//将Vector对象转换成数组
str = new String[v.size()];
for(int i=0;i<v.size();i++)
{
str[i] = (String)v.elementAt(i);
}
//返回生成的数组
return str;
}
public void commandAction(Command command, Displayable displayable) {
// Insert global pre-action code here
if (displayable == ChooseDemo) {
if (command == ChooseDemo.SELECT_COMMAND) {
switch (get_ChooseDemo().getSelectedIndex()) {
case 0:
// Insert pre-action code here
getDisplay().setCurrent(get_Damao());
// Insert post-action code here
break;
case 1:
// Insert pre-action code here
getDisplay().setCurrent(get_DaPan());
// Insert post-action code here
break;
case 2:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 3:
// Insert pre-action code here
getDisplay().setCurrent(get_ZongHe());
// Insert post-action code here
break;
case 4:
// Insert pre-action code here
getDisplay().setCurrent(get_ZiXun());
// Insert post-action code here
break;
case 5:
// Insert pre-action code here
getDisplay().setCurrent(get_form1());
// Insert post-action code here
break;
case 6:
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
break;
}
} else if (command == exitCommand1) {
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
}
} else if (displayable == DaPan) {
if (command == DaPan.SELECT_COMMAND) {
switch (get_DaPan().getSelectedIndex()) {
case 0:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 1:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 2:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 3:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
}
} else if (command == backCommand2) {
// Insert pre-action code here
getDisplay().setCurrent(get_ChooseDemo());
// Insert post-action code here
} else if (command == okCommand2) {
// Insert pre-action code here
// Do nothing
// Insert post-action code here
}
} else if (displayable == ZongHe) {
if (command == ZongHe.SELECT_COMMAND) {
switch (get_ZongHe().getSelectedIndex()) {
case 0:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 1:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 2:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 3:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 4:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 5:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 6:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 7:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
}
} else if (command == backCommand3) {
// Insert pre-action code here
getDisplay().setCurrent(get_ChooseDemo());
// Insert post-action code here
} else if (command == okCommand4) {
// Insert pre-action code here
// Do nothing
// Insert post-action code here
}
} else if (displayable == Damao) {
if (command == okCommand1) {
// Insert pre-action code here
getDisplay().setCurrent(get_GuPiaoXiangQing());
// Insert post-action code here
} else if (command == backCommand1) {
// Insert pre-action code here
getDisplay().setCurrent(get_ChooseDemo());
// Insert post-action code here
}
} else if (displayable == ZiXun) {
if (command == ZiXun.SELECT_COMMAND) {
switch (get_ZiXun().getSelectedIndex()) {
case 0:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 1:
// Insert pre-action code here
// Do nothing
// Insert post-action code here
break;
case 2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -