[Bill's Home]
[Old Page]

 Design  | SFC  |  NOS  |  Code |  Diary  | WWW |  Essay |  Cisco | [Home]

 

Quick links

WinSock in Visual Basic
WinSock multiserver
Java (Pocket PC)
DHTML
CSS
Flash/XML
ASP
PHP
JavaScript
Java
Delphi
RSA
WAP
Java Socket Programming
Subnetting
RS-232
Subnetting
Word
Design Tips

Source Code

Pascal
Java
C Programming
Applied PC Interfacing
WinSock client
WinSock server
FTP client
HTTP client
Java client/server
HTTP client
Subnetting in VB
RS-232 in VB
WinSock Multiserver

 

 

 

 

Next page >>

Well. I couldn't resist a few more of these, as it shows the power of Java. If you're interested the code is from the Mastering Java book which is published by Macmillan [Link]. I've tried all these on the Pocket PC and they work extremely well.

 

// Source Mastering Java, Bill Buchanan.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;

public class chap11_03 extends Applet implements
ActionListener,ItemListener
{
String str1,str2;
TextField tfield1 = new TextField(20);
TextField tfield2 = new TextField(20);
TextField tfield3 = new TextField(20);
Button comp = new Button("Compare");
Button quit = new Button("Quit");
Checkbox ccase = new Checkbox("Case");
boolean case_show=false;

public void init()
{
add(new Label("Enter two strings"));
add(tfield1); add(tfield2);
add(new Label("Comparison:"));
add(tfield3);
add(comp); add(quit);
add(ccase);
comp.addActionListener(this);
quit.addActionListener(this);
ccase.addItemListener(this);
}

public void actionPerformed(ActionEvent evt)
{
String str;
str=evt.getActionCommand();
if (str.equals("Compare"))
{
str1=tfield1.getText();
str2=tfield2.getText();
if (case_show)
{
str1=str1.toLowerCase();
str2=str2.toLowerCase();
}
if (str1.equals(str2)) tfield3.setText("Same");
else tfield3.setText("Different");
}
else if (str.equals("Quit")) System.exit(0);
}
public void itemStateChanged(ItemEvent evt)
{
Object obj;
obj=evt.getItem();
if (obj.equals("Case")) case_show=ccase.getState();
}
}


 

// Source Mastering Java, Bill Buchanan.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;

public class chap11_04 extends Applet implements ActionListener
{
String str1,str2;
TextField tfield1 = new TextField(20);
TextField tfield2 = new TextField(2);
TextField tfield3 = new TextField(20);
Button find = new Button("Find");
Button quit = new Button("Quit");

public void init()
{
add(new Label("Enter a string"));
add(tfield1);
add(new Label("Character to find:"));
add(tfield2);
add(new Label("Dialog"));
add(tfield3);
add(find); add(quit);
find.addActionListener(this);
quit.addActionListener(this);
}

public void actionPerformed(ActionEvent evt)
{
int index;
String Msg,str;
str=evt.getActionCommand();
if (str.equals("Find"))
{
str1=tfield1.getText();
str2=tfield2.getText();
index=str1.indexOf(str2);
Msg="Found at " + index;
tfield3.setText(Msg);
}
else if (str.equals("Quit")) System.exit(0);
}
}

 

// Source Mastering Java, Bill Buchanan.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;

public class chap11_06 extends Applet
implements ActionListener
{
TextField tfield1 = new TextField(20);
TextField tfield2 = new TextField(2);
TextField tfield3 = new TextField(2);
TextField tfield4 = new TextField(20);
Button convert = new Button("Convert");
Button quit = new Button("Quit");


public void init()
{
add(new Label("Enter a string"));
add(tfield1);
add(new Label("Character to replace"));
add(tfield2);
add(new Label("with"));
add(tfield3);
add(new Label("Substituted text:"));
add(tfield4);

add(convert); add(quit);
convert.addActionListener(this);
quit.addActionListener(this);
}

public void actionPerformed(ActionEvent evt)
{
int index,curr;
String str1,str2,str3,str4,str;

str=evt.getActionCommand();

if (str.equals("Convert"))
{
str1=tfield1.getText();
str2=tfield2.getText();
str3=tfield3.getText();
str4=str1.replace(str2.charAt(0),
str3.charAt(0));
tfield4.setText(str4);
}
else if (str.equals("Quit"))
System.exit(0);
}
}

 

// Source Mastering Java, Bill Buchanan.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;

public class chap11_07 extends Applet
implements ActionListener
{
TextField tfield1 = new TextField(20);
TextArea tarea = new TextArea(6,20);
Button quit = new Button("Quit");

public void init()
{
add(new Label("Enter a string"));
add(tfield1);
tfield1.addActionListener(this);
add(tarea);
add(quit); quit.addActionListener(this);
}

public void actionPerformed(ActionEvent evt)
{
char c[];
String Msg=null,str;
int i=0;

str=evt.getActionCommand();
if (str.equals("Quit")) System.exit(0);
else
{
str=tfield1.getText();
c=str.toCharArray();
for (i=0;i<str.length();i++)
{
if (Msg!=null) Msg=Msg + " Char=" + c[i] + "\n";
else Msg= " Char=" + c[i] + "\n";
}
tarea.setText(Msg);
}
}
}

Java is a powerful programming language which runs well on any type of device, and is especially usage in mobile devices. Microsoft are busy developing .NET for Windows CE, but it'll take them a while to fully develop it for as many devices as Java currently supports.

 

 
 

Design  | SFC  |  NOS  |  Code |  Diary  | WWW |  Essay |  Cisco | [Home]