decuongj2me
1.Thập phân sang nhị phân 2
2.Gui len 1 so neu so do la so nguyen thi cho phep dang ky con k thi bao loi 5(9%)
3.Máy tính 8(19%)
4.Giải phương trình 11(29%)
5Nhị phân sang thập phân 14(40%)
6.CHƯƠNG TRÌNH KIỂM TRA SỐ NGUYÊN TỐ18(54%)
7.CHƯƠNG TRÌNH PHẦN BLUTOOTH 22(66%)
8.Sắp xếp từ bé đến lớn 27(82%)
9.Chuyển từ hoa sang thường 31(90%)
1.Thập phân sang nhị phân
sevlet
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
protected void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String t3=request.getParameter("so");
int so=0;
so=Integer.parseInt(t3);
String so_doi=Integer.toBinaryString(so);
out.print(so_doi);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
client
package hac;
import javax.microedition.midlet.*;
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class Midlet extends MIDlet implements Runnable, CommandListener{
HttpConnection con;
Thread dk,dn;
Form fr;
Display di;
TextField t1;
StringItem st;
Command c1,c2;
InputStream in;
public void startApp() {
di=Display.getDisplay(this);
fr=new Form("Tuyen");
t1=new TextField("nhapso","",10,TextField.ANY);
c1=new Command("Send",Command.OK,1);
c2=new Command("Exit",Command.EXIT,1);
st=new StringItem("","");
fr.append(st);
fr.append(t1);
fr.addCommand(c1);
fr.addCommand(c2);
fr.setCommandListener(this);
di.setCurrent(fr);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(c==c1){
dk=new Thread(this);
dk.start(); }
if(c==c2)this.notifyDestroyed();
}
public void run(){
try{
String url,t3,t4;
t3=t1.getString();
+t3;
con=(HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
ByteArrayOutputStream data=new ByteArrayOutputStream();
in=con.openInputStream();
int ch;
while((ch=in.read())!=-1)
{data.write(ch);}
byte b[]=data.toByteArray();
String s=new String(b);
st.setText("ket qua:"+s);
}catch(Exception e){}
}
}
2.Gui len 1 so neu so do la so nguyen thi cho phep dang ky con k thi bao loi
* Server
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class NewServlet extends HttpServlet {
protected void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String t3=request.getParameter("so");
int so= Integer.parseInt(t3);
int d=0;
for(int i=2;i<=so/2;i++)
if(so%i==0)d++;
if(d==0)
out.print("ok");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
* Client
package hac;
import javax.microedition.midlet.*;
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class Midlet extends MIDlet implements Runnable, CommandListener{
HttpConnection con;
Thread dk;
Form fr,f1;
Display di;
TextField t1,t2,t3;
StringItem st;
Command c1,c2,c3;
InputStream in;
public void startApp() {
di=Display.getDisplay(this);
fr=new Form("Tuyen");
t1=new TextField("nhapso","",10,TextField.NUMERIC);
c1=new Command("Send",Command.OK,1);
c2=new Command("Exit",Command.EXIT,1);
st=new StringItem("","");
fr.append(st);
fr.append(t1);
fr.addCommand(c1);
fr.addCommand(c2);
fr.setCommandListener(this);
di.setCurrent(fr);
f1=new Form("Dangky");
t2=new TextField("User","",10,TextField.ANY);
t3=new TextField("Pass","",10,TextField.PASSWORD);
c3=new Command("Dangky",Command.OK,1);
f1.addCommand(c3);
f1.addCommand(c2);
f1.append(t3);
f1.append(t2);
f1.setCommandListener(this);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(c==c1){
dk=new Thread(this);
dk.start(); }
if(c==c3){st.setText("Hello")}
if(c==c2)this.notifyDestroyed();
}
public void run(){
try{
String url,t3,t4;
t3=t1.getString();
+t3;
con=(HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
ByteArrayOutputStream data=new ByteArrayOutputStream();
in=con.openInputStream();
int ch;
while((ch=in.read())!=-1)
{data.write(ch);}
byte b[]=data.toByteArray();
String s=new String(b);
if(s.equals("ok")){di.setCurrent(f1);
}
else
st.setText("xin loi ban qua den");
}catch(Exception e){}
}
}
3.Máy tính
sevlet
import java.io.*;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.*;
public class NewServlet extends HttpServlet {
protected void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String t1=request.getParameter("a");
String t2=request.getParameter("b");
String t3=request.getParameter("c");
int a=Integer.parseInt(t1);
int b=Integer.parseInt(t2);
String c=String.valueOf(t3);
float i;
if(c.equals("+")){i=a+b; out.print(i);}
if(c.equals("-")){i=a-b; out.print(i);}
if(c.equals("x")){i=a*b;out.print(i);}
if(c.equals(":")){i=a/b;out.print(i);}
}
}
Client
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class Midlet extends MIDlet implements Runnable, CommandListener{
HttpConnection con;
Thread dk;
Form fr;
Display di;
TextField t1,t2,t3;
StringItem st;
Command c1,c2,c3;
InputStream in;
OutputStream out;
String url=null;
public void startApp() {
di=Display.getDisplay(this);
fr=new Form("Tuyen");
t1=new TextField("nhap a:","",10,TextField.NUMERIC);
t2=new TextField("nhap b:","",10,TextField.NUMERIC);
t3=new TextField("nhap pt:","",10,TextField.ANY);
c1=new Command("Send",Command.OK,1);
c2=new Command("Exit",Command.EXIT,2);
st=new StringItem("","");
fr.append(st);
fr.append(t1);
fr.append(t2);
fr.append(t3);
fr.addCommand(c1);
fr.addCommand(c2);
fr.setCommandListener(this);
di.setCurrent(fr);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(c==c1){
dk=new Thread(this);
dk.start(); }
if(c==c2)
this.notifyDestroyed();
}
public void run(){
try{
String url,t6,t4,t5;
int k,n;
t4=t1.getString();
t5=t2.getString();
t6=t3.getString();
k=Integer.parseInt(t4);
n=Integer.parseInt(t5);
String j=String.valueOf(t6);
url="http://localhost:8080/tuyen/NewServlet?a="+t4+"&b="+t5+"&c="+t6;
con=(HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
ByteArrayOutputStream data=new ByteArrayOutputStream();
in=con.openInputStream();
int ch;
while((ch=in.read())!=-1)
{data.write(ch);}
byte b[]=data.toByteArray();
String s=new String(b);
st.setText(s);
}catch(Exception e){}
}
}
4.Giải phương trình
Server
import java.io.*;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.*;
public class NewServlet extends HttpServlet {
protected void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String t1=request.getParameter("a");
String t2=request.getParameter("b");
String t3=request.getParameter("c");
int a=Integer.parseInt(t1);
int b=Integer.parseInt(t2);
int c=Integer.parseInt(t3);
float del;
del=b*b-4*a*c;
if(del
if(del==0){float n=-b/(2*a); out.print(n);}
if(del>0)
{float n1,n2;
n1=-b+ (float)Math.sqrt(del)/(2*a);
n2=-b- (float)Math.sqrt(del)/(2*a);
out.print(n1);
out.print(n2);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
Client
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class Midlet extends MIDlet implements Runnable, CommandListener{
HttpConnection con;
Thread dk;
Form fr,f1;
Display di;
TextField t1,t2,t3;
StringItem st;
Command c1,c2,c3;
InputStream in;
public void startApp() {
di=Display.getDisplay(this);
fr=new Form("Tuyen");
t1=new TextField("nhap a:","",10,TextField.NUMERIC);
t2=new TextField("nhap b:","",10,TextField.NUMERIC);
t3=new TextField("nhap c:","",10,TextField.NUMERIC);
c1=new Command("Send",Command.OK,1);
c2=new Command("Exit",Command.EXIT,1);
st=new StringItem("","");
fr.append(st);
fr.append(t1);
fr.append(t2);
fr.append(t3);
fr.addCommand(c1);
fr.addCommand(c2);
fr.setCommandListener(this);
di.setCurrent(fr);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(c==c1){
dk=new Thread(this);
dk.start(); }
if(c==c2)
this.notifyDestroyed();
}
public void run(){
try{
String url,t6,t4,t5;
int k,n,j;
t4=t1.getString();
t5=t2.getString();
t6=t3.getString();
k=Integer.parseInt(t4);
n=Integer.parseInt(t5);
j=Integer.parseInt(t6);+t4+"&b="+t5+"&c="+t6;
con=(HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
ByteArrayOutputStream data=new ByteArrayOutputStream();
in=con.openInputStream();
int ch;
while((ch=in.read())!=-1)
{data.write(ch);}
byte b[]=data.toByteArray();
String s=new String(b);
st.setText(s);
}catch(Exception e){}
}
}
5Nhị phân sang thập phân
client
package nhi_thap;
import java.io.*;
import java. microedition .io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Midlet extends MIDlet implements CommandListener,Runnable{
Display di;
Form f1,f2;
TextField t1;
StringItem it;
Command c1,c2,c3,c4;
Thread th;
HttpConnection con;
InputStream in;
String url=null;
public void startApp() {
di=Display.getDisplay(this);
f1=new Form("nhi sang thap");
t1=new TextField("so nhi phan:","",20,TextField.ANY);
it=new StringItem("","");
f1.append(t1);
f1.append(it);
c1=new Command("connect",Command.OK,1);
c2=new Command("exit",Command.EXIT,2);
c3=new Command("back",Command.BACK,3);
c4=new Command("ok",Command.OK,4);
f1.addCommand(c1);
f1.addCommand(c2);
f1.setCommandListener(this);
}
public void pauseApp() {
di.setCurrent(f1);
}
public void destroyApp(boolean unconditional) {
}
public void connect(){
try{
con=(HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
}
catch(Exception e){
st.setText("K?t n?i l?i: "+e.getMessage());
}
}
public void in(){
String;
try{
in=con.openInputStream();
int length=(int)con.getLength();
byte server[];
if(length!=-1){
server=new byte[length];
in.read(server);
str=new String(server);
}
else
{
ByteArrayOutputStream br=new
ByteArrayOutputStream();
int ch;
while((ch=in.read())!=-1)
br.write(ch);
str=new String(br.toByteArray());
br.close();
}
st.setText(str);
}
catch(Exception e){
}
}
public synchronized void run(){
this.connect();
this.in();
}
public void commandAction(Command c, Displayable d)
{
if(c==c1)
{ +t1.getString()+"";
th=new Thread(this);
th.start();
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
Sevlet
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "NewServlet", urlPatterns = {"/NewServlet"})
public class NewServlet extends HttpServlet {
private int s;
private char key;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String t3=request.getParameter("so");
if(key=='1')
{
String st;
st = String.valueOf(t3);
char a;
int temp=0,n=1,sodoi=0;
for(int i=st.length()-1;i>=0;i--)
{
a = st.charAt(i);
temp = (int)a;
temp = temp - 48;
sodoi = sodoi + temp*n;
n=n*2;
}
out.print(sodoi);
}
else if(key=='1')
{
s=Integer.parseInt(t3);
}
String so_doi=Integer.toBinaryString(s);
out.print(so_doi);
}
}
6.CHƯƠNG TRÌNH KIỂM TRA SỐ NGUYÊN TỐ
· client
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class songuyento_c extends MIDlet implements CommandListener, Runnable {
Display di;
Form f;
TextField tf;
StringItem si;
Command c1,c2;
HttpConnection con;
InputStream in;
Thread th;
public void startApp() {
di= Display.getDisplay(this);
f= new Form ("so nguyen to");
si= new StringItem ("ket qua: ","");
c1= new Command ("Exit", Command.EXIT,1);
c2= new Command ("Test", Command.OK,1);
tf= new TextField ("Nhap so","", 3, TextField.NUMERIC);
f.append(tf);
f.append(si);
f.addCommand(c1);
f.addCommand(c2);
f.setCommandListener(null);
di.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c==c1){
notifyDestroyed();
}
else
if (c==c2){
th= new Thread(this);
th.start();
}
}
public void run() {
String t= tf.getString();
int n= Integer.parseInt(t);
String url= "http://localhost:8080/songuyento/songuyento?so="+n;
try{
String;
InputStream in=con.openInputStream();
int length=(int)con.getLength();
byte server[];
if(length!=-1){
server=new byte[length];
in.read(server);
str=new String(server);
}
else
{
ByteArrayOutputStream br=new
ByteArrayOutputStream();
int ch;
while((ch=in.read())!=-1)
br.write(ch);
str=new String(br.toByteArray());
br.close();
}
si.setText(str);
}catch(Exception e)
{
e.getMessage();
}
}}
· server
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class songuyento extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String s= request.getParameter("so");
int n= Integer.parseInt(s);
PrintWriter out= response.getWriter();
int i,kt=0;
for (i=2; i<n;i++){
if (n%i==0){
kt=kt+1;
}
}
if (kt==0){
out.print("ok");}
else
out.print("not ok");
} }
7.CHƯƠNG TRÌNH PHẦN BLUTOOTH
· Server
import javax.microedition.midlet.*;
import javax.bluetooth.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class MidletS extends MIDlet implements CommandListener, Runnable {
Display di;Form f;Command c1;LocalDevice ld;
Thread th;StreamConnectionNotifier scn;
StreamConnection sc;OutputStream out;
InputStream in;
UUID id;
String url;
public void startApp() {
di=Display.getDisplay(this);
f=new Form("dfg");
c1=new Command("stop",Command.OK,1);
f.addCommand(c1);
f.setCommandListener(this);
di.setCurrent(f);
th=new Thread(this);
th.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
}
public void run() {
try{
f.append("init Server");
ld=LocalDevice.getLocalDevice();
ld.setDiscoverable(DiscoveryAgent.GIAC);
id=new UUID("123",true);
+id;//+";name=BC;authorize=true";
f.append(url);
scn=(StreamConnectionNotifier)Connector.open(url);
f.append("wating...");
sc=scn.acceptAndOpen();
f.append("connected");
out=sc.openOutputStream();
in=sc.openInputStream();
int len=in.read();
int temp=0;
byte b[]=new byte[len];
while(temp!=len)
{
int k=in.read(b, temp, len-temp);
temp=temp+k;
}
String t=new String(b);
f.append(t);
String t1="hello C";
out.write(t1.length());
out.write(t1.getBytes());
}
catch(Exception e){
System.out.print("
loi "+e.toString());
}
}
}
· Client
import javax.microedition.midlet.*;
import javax.bluetooth.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class MidletC extends MIDlet implements Runnable, DiscoveryListener, CommandListener{
Display di;Form f;Command c1;LocalDevice ld;
Thread th;StreamConnectionNotifier scn;
StreamConnection sc;OutputStream out;
DiscoveryAgent agent;
InputStream in;
UUID id;
String url;
public void startApp() {
di=Display.getDisplay(this);
f=new Form("dfg");
c1=new Command("stop",Command.OK,1);
f.addCommand(c1);
f.setCommandListener(this);
di.setCurrent(f);
th=new Thread(this);
th.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void run() {
try{
f.append("init client");
ld=LocalDevice.getLocalDevice();
agent=ld.getDiscoveryAgent();
agent.startInquiry(DiscoveryAgent.GIAC, this);
f.append("fidding...");
}
catch(Exception e){
}
}
public void deviceDiscovered(RemoteDevice rd, DeviceClass dc) {
f.append("device:");
f.append(rd.getBluetoothAddress());
try{
UUID ids[]=new UUID[1];
ids[0]=new UUID("123",true);
agent.searchServices(null, ids, rd, this);
}
catch(Exception e){
System.out.print("dv:"+e.toString());
}
}
public void inquiryCompleted(int i) {
}
public void serviceSearchCompleted(int i, int i1) {
try{
sc=(StreamConnection)Connector.open(url);
out=sc.openOutputStream();
in=sc.openInputStream();
String t1="hello S";
out.write(t1.length());
out.write(t1.getBytes());
int len=in.read();
int temp=0;
byte b[]=new byte[len];
while(temp!=len)
{
int k=in.read(b, temp, len-temp);
temp=temp+k;
}
String t=new String(b);
f.append(t);
}
catch(Exception e){
System.out.print(e.toString());
}
}
public void servicesDiscovered(int i, ServiceRecord[] srs) {
url=srs[0].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);
f.append(url);
}
public void commandAction(Command c, Displayable d) {
}
}
8.Sắp xếp từ bé đến lớn
//client
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class sxep extends MIDlet implements Runnable,CommandListener {
Display di;
Form f;
TextField tf1;
StringItem it;
HttpConnection con;
InputStream in;
OutputStream out;
String url=null;
Command c1,c2;
Thread th;
public void startApp() {
di=Display.getDisplay(this);
f=new Form ("sapxep");
tf1=new TextField("t1","",20,TextField.NUMERIC);
f.append(tf1);
it=new StringItem ("ket qua:","");
f.append(it);
c1=new Command ("sxep",Command.OK,1);
c2=new Command ("exit",Command.EXIT,2);
f.addCommand(c1);
f.addCommand(c2);
f.setCommandListener(this);
di.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction (Command c,Displayable d){
if (c==c2) {this.notifyDestroyed ();}
if (c==c1){
th=new Thread (this);
th.start();
}
}
public void run(){
try{
String t2;
int k;
t2=tf1.getString();
+t2;
con = (HttpConnection)Connector.open(url);
con.setRequestMethod (HttpConnection.GET);
in=con.openInputStream();
ByteArrayOutputStream data = new ByteArrayOutputStream();
int ch;
while((ch=in.read())!=-1)
{data.write(ch);}
byte b[]=data.toByteArray();
String s=new String(b);
int m=Integer.parseInt(s);
it.setText(String.valueOf(m));
}catch(Exception e){}
}}
//sever
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class sxep1 extends HttpServlet {
protected void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
String t3=request.getParameter("t1");
String xau= String.valueOf(t3);
char t;
char []a=xau.toCharArray();
for(int i=0;i<xau.length();i++)
{for(int j=0;j<=i;j++)
{if(a[i]<a[j]){t=a[i];
a[i]=a[j];
a[j]=t;}}
}
out.print(a);
}
}
9.Chuyển từ hoa sang thường
client
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class chuyendoixau extends MIDlet implements Runnable,CommandListener{
Display di;
Form f;
TextField tf;
StringItem it;
Command c1,c2;
Thread th;
OutputStream out;
InputStream in;
HttpConnection con;
String url;
public void startApp() {
di=Display.getDisplay(this);
f=new Form("chuyen doi chuoi ky tu");
tf=new TextField("chuoi ky tu:","",20,TextField.NUMERIC);
it=new StringItem("chuoi sau chuyen thanh chu hoa:","");
c1=new Command("EXIT",Command.EXIT,1);
c2=new Command("OK",Command.OK,1);
f.append(tf);
f.append(it);
f.addCommand(c1);
f.addCommand(c2);
f.setCommandListener(this);
di.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d){
if(c==c1)
notifyDestroyed();
else
if(c==c2)
th=new Thread();
th.start();
}
public void run(){
try{
String x;
x=tf.getString();
url="http://localhost:8080/chuyendoixaukytu/chuyendoi?chuoi="+x;
con=(HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.GET);
ByteArrayOutputStream data=new ByteArrayOutputStream();
in=con.openInputStream();
int ch;
while((ch=in.read())!=-1)
data.write(ch);
byte b[]=data.toByteArray();
String st=new String(b);
it.setText(st+tf);
}catch(Exception e){}
}
}
sevlet
import java.io.*;
import javax.servlet.http.*;
public class Servlet_chuyendoi extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException{
String t1;
PrintWriter out = res.getWriter();
t1=req.getParameter("chuoi:");
if(t1.equals(":"))
t1=t1.substring(2,t1.length());
String t2=t1.toLowerCase(); // từ hoa sang thuờng
out.print(t2);
}
}
Bạn đang đọc truyện trên: AzTruyen.Top