All pastes #481510 Raw Edit

Something

public text v1 · immutable
·published 2007-05-10 21:21 UTC
rendered paste body

import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;

public class birdieBluejack extends MIDlet
                 implements CommandListener {

	public TextBox textBox= null;
    private Display display;
    private ImageItem imageItem;
    public static final Command exitCommand = new Command( "Exit", Command.EXIT, 1 ); 
    public static final Command agreeCommand = new Command("Agree", Command.OK, 1);
    public static final Command bluejackCommand = new Command("Bluejack'em!", Command.OK, 1);
	public static final Command stopBluejackCommand = new Command("Stop", Command.STOP, 1);

    private Form mainForm; //För input av kontaktens namn
    private ChoiceGroup options;
	private TextField contactName; 
	private bluejack bbluejack;
    
    public MIDPLogger log;
       
    public birdieBluejack(){
   try {
     log = new MIDPLogger(MIDPLogger.DEBUG,true,false);
     //levels are MIDPLogger.DEBUG, MIDPLogger.INFO, MIDPLogger.WARNING, MIDPLogger.ERROR, MIDPLogger.EXPRESS or MIDPLogger.NONE
    }
    catch (Exception e) { 
     System.out.println("Exception creating MIDPLogger");
     e.printStackTrace();
    }
			textBox=new TextBox("Birdie Bluejacking", "This application will bluejack enabled OBEX and visable bluetooth devices with in range. This application was developed to help the entrence crew at the demoparty Birdie(.org) in Sweden to make the visitors to show there ticket to the party when going out (to probly get stoned and drunk) and in to the party.\n\nThe code is developed by Lezgin \"LeRrA\" Bakircioglu, lerra@birdie.org.\n\nBy using this application you agree to NOT hold me responsible to whatever BECIDE all the laughter. Now move along by pressing agree button.", 598, TextField.UNEDITABLE);
			log.write("Agreement showed",MIDPLogger.DEBUG);
		}

    public void commandAction( Command c, Displayable d){
         
         if( c == exitCommand ){

            exitMIDlet();
        }
        if( c == agreeCommand ){
			log.write("Agree buttom created, will create midlet now",MIDPLogger.DEBUG);
            preInitMIDlet();
        }
      if( c == bluejackCommand ){

            initMIDlet();
        }        
        if( c == stopBluejackCommand ){
			bbluejack.stopRun();   
			bbluejack=null;     
        }


    }

    protected void destroyApp( boolean unconditional ) throws MIDletStateChangeException {
    	log.close();
        exitMIDlet();
    }

    public void exitMIDlet(){
        notifyDestroyed();
    }

    public Display getDisplay(){ return display; }

	private void preInitMIDlet()
	{
/*		try{
		    Class.forName("javax.bluetooth.LocalDevice");
		}
		catch(Exception ex){
    		System.out.println("You don't have support for the BT API in your MIDlet.");
    		exitMIDlet();
		}
*/		log.write("Creating the forms",MIDPLogger.DEBUG);
        mainForm = new Form("Text Field");
        log.write("Will create the contact",MIDPLogger.DEBUG);
		contactName=new TextField("Bluejack message", "VISA BANDEN!", 15, TextField.ANY);
        mainForm.append(contactName);
		//option part
        String[] optionStrings= { "Count total bluejackt devices?" };
        options = new ChoiceGroup("Options", Choice.MULTIPLE, optionStrings, null);
        log.write("Showing the forms and adding buttons",MIDPLogger.DEBUG);
        mainForm.append(options);		
		mainForm.addCommand(exitCommand);
		mainForm.addCommand(bluejackCommand);	
		mainForm.setCommandListener(this);	
        //display = Display.getDisplay( this );
        display.setCurrent(mainForm);
		log.write("Showd the form",MIDPLogger.DEBUG);
	}

    protected void initMIDlet(){
		display = Display.getDisplay( this );
		//contactName.getString();
		//options.isSelected(0) e om den ska visa;
		log.write("creating the bluejacking object",MIDPLogger.DEBUG);
        bbluejack = new bluejack(contactName.getString(),options.isSelected(0),log);
//        bbluejack.addCommand(exitCommand);
//		bbluejack.addCommand(stopBluejackCommand);
//        bbluejack.setCommandListener (this);
        //getDisplay().setCurrent(this);
        
        while(true)
        {
        try { //to makesure the var's is initlized in the object we are collecting from
        		Thread.sleep(5000);
        	} catch (Exception e) {}
        
        String s=printScreen();
		
		//Form form;
    	//form = new Form("ScanUpdate");    
    	mainForm.deleteAll();
		StringItem realUpdate= new StringItem ("scan",s);
		mainForm.append(realUpdate);		
		mainForm.addCommand(exitCommand);
		mainForm.addCommand(stopBluejackCommand);
		mainForm.setCommandListener(this);
		//display = Display.getDisplay( this );
    	//display.setCurrent(form);        
        
//textBox=new TextBox("Birdie Bluejacking", s, 598, TextField.UNEDITABLE);        
//display = Display.getDisplay( this );
//textBox.addCommad(stopBluejackCommand);
//textBox.setCommandListener (this);
//display.setCurrent(textBox);
        }
        	
    }
    
	public String printScreen()
	{
		int[] status=bbluejack.getStatus();
		String s;
		if(status[0]==1)
			s="Scanning for devices";
		else
			s="Not scanning for devices";
			
			
		if(status[1]==1)
			s=s+" but scanning for services in the found devices";
		else
			s=s+" and not scanning for services";
		
		s=s+ " (found total "+status[2]+"devices)";
		System.out.println(s);
		return s;
    	
	}
    protected void pauseApp(){

    }

    protected void startApp() throws MIDletStateChangeException {
        if( display == null )
        { 
        	textBox.addCommand(exitCommand);
        	textBox.addCommand(agreeCommand);
     		textBox.setCommandListener(this);
            display = Display.getDisplay( this );
            display.setCurrent(textBox);
        }
    }
}