📄 networkingtest.java
字号:
import java.util.*;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
public class NetworkingTest extends javax.microedition.midlet.MIDlet
{
private Form form;
public NetworkingTest() throws IOException
{
// Setup the UI
form = new Form("Http Dump");
}
protected void pauseApp()
{
}
protected void startApp() throws MIDletStateChangeException
{
// display our UI
Display.getDisplay(this).setCurrent(form);
// create a new thread for the networking (inline class)
Thread t = new Thread()
{
// declare a run method - not called until the thread is started
// (see t.start below)
public void run()
{
communicate();
}
};
// start the thread (execute the contents of the run method above)
t.start();
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
private void communicate()
{
try
{
// Create a HTTP connection to the java.sun.com site
InputStream inStream = Connector.openInputStream("http://java.sun.com/");
// Open the result and stream the first chunk into a byte buffer
byte[] buffer = new byte[255];
int bytesRead = inStream.read(buffer);
if (bytesRead > 0)
{
inStream.close();
// Turn the result into a string and display it
String webString = new String(buffer, 0, bytesRead);
System.out.println(webString);
form.append(webString);
}
}
catch (IOException io)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -