The Artima Developer Community
Sponsored Link

Java Answers Forum
Can anyone help explain/comment on this code ?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
A i

Posts: 1
Nickname: ai0461400
Registered: Jan, 2009

Can anyone help explain/comment on this code ? Posted: Jan 10, 2009 5:24 AM
Reply to this message Reply
Advertisement
package socket;

import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.*;

public class Battleship extends MIDlet implements CommandListener {
private static final String SERVER = "Server";
private static final String CLIENT = "Client";
private static final String[] names = { SERVER, CLIENT };
private static Display display;
//form that contains items, in this case contains choicegrups
private Form f;
//group of selectable elements within a form
private ChoiceGroup cg;
private boolean isPaused;
private Server server;
private Client client;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command startCommand = new Command("Start", Command.ITEM, 1);

public Battleship() {
display = Display.getDisplay(this);
f = new Form("Battleship");
cg = new ChoiceGroup("Please select peer", Choice.EXCLUSIVE, names,
null);
// add the choice group to the form
f.append(cg);
f.addCommand(exitCommand);
f.addCommand(startCommand);
f.setCommandListener(this);
display.setCurrent(f);
}

public boolean isPaused() {
return isPaused;
}

public void startApp() {
isPaused = false;
}

public void pauseApp() {
isPaused = true;
}

public void destroyApp(boolean unconditional) {
if (server != null) {
server.stop();
}
if (client != null) {
client.stop();
}
}

public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();
} else if (c == startCommand) {
String name = cg.getString(cg.getSelectedIndex());
if (name.equals(SERVER)) {
server = new Server(this);
server.start();
} else {
client = new Client(this);
client.start();
}
}
}
}

Topic: Generics Help Previous Topic   Next Topic Topic: not assigning a reference bad coding standard

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use