Posted by RR on Fri 19 Sep 18:27
report abuse | View followups from jahadubrapebernos and Anonymous | download | new post
- // Källkoden för Tricket.Jar
- //------------------------------------------------------CustomHeader.Java------------------------------------------------------\\
- package example.sms;
- import javax.microedition.lcdui.*;
- public class CustomHeader extends CustomItem
- {
- {
- super(null);
- height = 70;
- smsCentralNumber = s;
- date = s1;
- width = i;
- setLayout(2576);
- }
- protected int getMinContentHeight()
- {
- return height;
- }
- protected int getMinContentWidth()
- {
- return width;
- }
- protected int getPrefContentHeight(int i)
- {
- return getMinContentHeight();
- }
- protected int getPrefContentWidth(int i)
- {
- return getMinContentWidth();
- }
- {
- for(int k = 0; k < j; k++)
- {
- g.setColor(255 - k, 255 - k, 255 - k);
- g.drawLine(0, k, i, k);
- }
- g.setColor(80, 80, 80);
- g.drawString(smsCentralNumber, 2, 7, 20);
- g.drawString(date, 2, 40, 20);
- }
- int width;
- int height;
- String smsCentralNumber;
- String date;
- }
- //------------------------------------------------------CustomHeaderTransparent.Java------------------------------------------------------\\
- package example.sms;
- import javax.microedition.lcdui.*;
- public class CustomHeaderTransparent extends CustomItem
- {
- {
- super(null);
- height = 70;
- smsCentralNumber = s;
- date = s1;
- width = i;
- setLayout(2576);
- }
- protected int getMinContentHeight()
- {
- return height;
- }
- protected int getMinContentWidth()
- {
- return width;
- }
- protected int getPrefContentHeight(int i)
- {
- return getMinContentHeight();
- }
- protected int getPrefContentWidth(int i)
- {
- return getMinContentWidth();
- }
- {
- g.setColor(80, 80, 80);
- g.drawString(smsCentralNumber, 2, 7, 20);
- g.drawString(date, 2, 40, 20);
- }
- int width;
- int height;
- String smsCentralNumber;
- String date;
- }
- //------------------------------------------------------Generator.Java------------------------------------------------------\\
- package example.sms;
- import java.util.Calendar;
- import java.util.Random;
- import javax.microedition.lcdui.Form;
- public class Generator
- {
- {
- newLine = "\n";
- minutesValid = 75;
- minutesOffset = 2;
- phoneNumber = s;
- zoneCode = s1;
- expiryCalendar.set(12, expiryCalendar.get(12) + minutesValid);
- smsCentralNumber = getSmsCentralNumber();
- }
- {
- String s = "72150";
- String s1 = "";
- if(zoneCode.compareTo("A") == 0)
- s1 = "11";
- else
- if(zoneCode.compareTo("AB") == 0)
- s1 = "24";
- else
- if(zoneCode.compareTo("ABC") == 0)
- s1 = "36";
- s = s + s1 + formatInt(calendar.get(12) + minutesOffset);
- return s;
- }
- {
- return String.valueOf(calendar.get(1)) + "-" + formatInt(calendar.get(2) + 1) + "-" + formatInt(calendar.get(5));
- }
- {
- return formatInt(calendar.get(11)) + ":" + formatInt(calendar.get(12));
- }
- {
- String s = "0";
- String s10 = "";
- String s11 = "";
- int i = random1.nextInt() % 26;
- if(i < 0)
- i = -i;
- s12 = s12 + generateNumber(6);
- if(zoneCode.compareTo("A") == 0)
- {
- s = "30";
- s11 = "A";
- } else
- if(zoneCode.compareTo("AB") == 0)
- {
- s = "45";
- s11 = "D";
- } else
- if(zoneCode.compareTo("ABC") == 0)
- {
- s = "60";
- s11 = "E";
- }
- String s1 = smsCentralNumber.substring(smsCentralNumber.length() - 2, (smsCentralNumber.length() - 2) + 1) + smsCentralNumber.substring(smsCentralNumber.length() - 1, (smsCentralNumber.length() - 1) + 1) + smsCentralNumber.substring(smsCentralNumber.length() - 3, (smsCentralNumber.length() - 3) + 1);
- String s3 = s1 + "/H-" + zoneCode + " " + s9 + newLine + "+'" + s13 + "'+" + newLine + "+'" + s14 + "'+" + newLine + "+'" + s15 + "'+" + newLine + s5 + newLine + "SL Biljett giltig till kl. " + s9 + ". HELT PRIS " + s + " kr (inkl. 6% moms). " + s6 + "P4" + s2 + s8 + s7 + s11 + s16 + s12;
- return s3;
- }
- {
- String s = "";
- for(int k = 0; k < i; k++)
- {
- int j = random.nextInt() % 10;
- if(j < 0)
- j = -j;
- }
- return s;
- }
- {
- if(s.length() == 1)
- s = "0" + s;
- return s;
- }
- private String phoneNumber;
- private String zoneCode;
- private Calendar calendar;
- private Calendar expiryCalendar;
- private String newLine;
- private int minutesValid;
- private int minutesOffset;
- public String smsCentralNumber;
- private Random random;
- }
- //------------------------------------------------------Preferences.Java------------------------------------------------------\\
- package example.sms;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import javax.microedition.rms.*;
- public class Preferences
- {
- throws RecordStoreException
- {
- mRecordStoreName = s;
- load();
- }
- {
- }
- {
- if(s1 == null)
- s1 = "";
- mHashtable.put(s, s1);
- }
- private void load()
- throws RecordStoreException
- {
- RecordStore recordstore;
- RecordEnumeration recordenumeration;
- recordstore = null;
- recordenumeration = null;
- recordstore = RecordStore.openRecordStore(mRecordStoreName, true);
- String s1;
- String s2;
- for(recordenumeration = recordstore.enumerateRecords(null, null, false); recordenumeration.hasNextElement(); put(s1, s2))
- {
- byte abyte0[] = recordenumeration.nextRecord();
- int i = s.indexOf('|');
- s1 = s.substring(0, i);
- s2 = s.substring(i + 1);
- }
- if(recordenumeration != null)
- recordenumeration.destroy();
- if(recordstore != null)
- recordstore.closeRecordStore();
- break MISSING_BLOCK_LABEL_132;
- Exception exception;
- exception;
- if(recordenumeration != null)
- recordenumeration.destroy();
- if(recordstore != null)
- recordstore.closeRecordStore();
- throw exception;
- }
- public void save()
- throws RecordStoreException
- {
- RecordStore recordstore;
- RecordEnumeration recordenumeration;
- recordstore = null;
- recordenumeration = null;
- recordstore = RecordStore.openRecordStore(mRecordStoreName, true);
- int i;
- for(recordenumeration = recordstore.enumerateRecords(null, null, false); recordenumeration.hasNextElement(); recordstore.deleteRecord(i))
- i = recordenumeration.nextRecordId();
- byte abyte0[];
- for(Enumeration enumeration = mHashtable.keys(); enumeration.hasMoreElements(); recordstore.addRecord(abyte0, 0, abyte0.length))
- {
- String s2 = s + "|" + s1;
- abyte0 = s2.getBytes();
- }
- if(recordenumeration != null)
- recordenumeration.destroy();
- if(recordstore != null)
- recordstore.closeRecordStore();
- break MISSING_BLOCK_LABEL_173;
- Exception exception;
- exception;
- if(recordenumeration != null)
- recordenumeration.destroy();
- if(recordstore != null)
- recordstore.closeRecordStore();
- throw exception;
- }
- private String mRecordStoreName;
- private Hashtable mHashtable;
- }
- //------------------------------------------------------Sender.Java------------------------------------------------------\\
- package example.sms;
- import java.io.IOException;
- import java.io.PrintStream;
- import javax.microedition.io.Connector;
- import javax.microedition.lcdui.*;
- import javax.wireless.messaging.MessageConnection;
- import javax.wireless.messaging.TextMessage;
- // Referenced classes of package example.sms:
- // Generator, CustomHeader, CustomHeaderTransparent
- public class Sender
- implements CommandListener, Runnable
- {
- {
- backCommand = new Command("Tillbaka", 3, 1);
- cancelCommand = new Command("Avbryt", 3, 1);
- altCommand = new Command("Alternativ", 2, 2);
- replyCommand = new Command("Svara", 4, 3);
- smsPort = s;
- display = display1;
- destinationAddress = null;
- backScreen = displayable;
- phoneNumber = s1;
- zoneCode = s2;
- }
- public void display(int i)
- {
- generator = new Generator(phoneNumber, zoneCode);
- if(i == 0)
- form = new Form(generator.smsCentralNumber + " " + generator.getTimeFormatted() + " ");
- else
- if(i == 1)
- {
- form = new Form(null);
- customHeader = new CustomHeader(form.getWidth(), generator.smsCentralNumber, generator.getDateFormatted() + " " + generator.getTimeFormatted());
- form.append(customHeader);
- } else
- {
- form = new Form(null);
- customHeaderTransparent = new CustomHeaderTransparent(form.getWidth(), generator.smsCentralNumber, generator.getDateFormatted() + " " + generator.getTimeFormatted());
- form.append(customHeaderTransparent);
- }
- form.append(generator.getBody(form));
- form.addCommand(backCommand);
- form.addCommand(altCommand);
- form.addCommand(replyCommand);
- form.setCommandListener(this);
- display.setCurrent(form);
- }
- public void send()
- {
- form = new Form("Tricket [SMS]");
- form.addCommand(cancelCommand);
- form.setCommandListener(this);
- display.setCurrent(form);
- generator = new Generator(phoneNumber, zoneCode);
- body = generator.getBody(form);
- }
- public void commandAction(Command command, Displayable displayable)
- {
- try
- {
- if(command == backCommand || command == cancelCommand)
- display.setCurrent(backScreen);
- }
- {
- exception.printStackTrace();
- }
- }
- public void run()
- {
- try
- {
- form.append("Skapar koppling...");
- smsConn = (MessageConnection)Connector.open(s);
- form.append("Skapar meddelande...");
- TextMessage textmessage = (TextMessage)smsConn.newMessage("text");
- textmessage.setAddress(s);
- textmessage.setPayloadText(body);
- form.append("Skickar SMS...");
- smsConn.send(textmessage);
- }
- {
- throwable.printStackTrace();
- }
- if(smsConn != null)
- try
- {
- form.append("St\344nger koppling...");
- smsConn.close();
- }
- {
- form.append("Closing connection caught: " + ioexception.toString());
- }
- }
- Command backCommand;
- Command cancelCommand;
- Command altCommand;
- Command replyCommand;
- MessageConnection smsConn;
- Display display;
- String smsPort;
- String destinationAddress;
- Displayable backScreen;
- Form form;
- String phoneNumber;
- String zoneCode;
- Generator generator;
- CustomHeader customHeader;
- CustomHeaderTransparent customHeaderTransparent;
- String body;
- }
- //------------------------------------------------------Tricket.Java------------------------------------------------------\\
- package example.sms;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.rms.RecordStore;
- import javax.microedition.rms.RecordStoreException;
- // Referenced classes of package example.sms:
- // Preferences, Sender
- public class Tricket extends MIDlet
- implements CommandListener
- {
- public Tricket()
- {
- exitCommand = new Command("Avsluta", 7, 2);
- okCommand = new Command("OK", 4, 1);
- smsPort = "666";
- kPhoneNumber = "phone";
- kZoneCode = "zone";
- kMode = "mode";
- try
- {
- mPreferences = new Preferences("preferences");
- }
- {
- exception.printStackTrace();
- }
- form = new Form(null);
- try
- {
- imageItem = new ImageItem(null, image, 769, "My Image");
- form.append(imageItem);
- }
- {
- exception1.printStackTrace();
- }
- form.append(textFieldPhoneNumber);
- spacer = new Spacer(10, 10);
- form.append(spacer);
- "A", "AB", "ABC"
- }, null);
- if(zoneCode.compareTo("A") == 0)
- choiceGroupZone.setSelectedIndex(0, true);
- else
- if(zoneCode.compareTo("AB") == 0)
- choiceGroupZone.setSelectedIndex(0, true);
- else
- if(zoneCode.compareTo("ABC") == 0)
- choiceGroupZone.setSelectedIndex(2, true);
- else
- choiceGroupZone.setSelectedIndex(0, true);
- form.append(choiceGroupZone);
- spacer = new Spacer(10, 10);
- "Visa standard", "Visa W890i", "Visa transparent", "Skicka SMS"
- }, null);
- if(mode.compareTo("Visa standard") == 0)
- choiceGroupMode.setSelectedIndex(0, true);
- else
- if(mode.compareTo("Visa W890i") == 0)
- choiceGroupMode.setSelectedIndex(1, true);
- else
- if(mode.compareTo("Visa transparent") == 0)
- choiceGroupMode.setSelectedIndex(2, true);
- else
- if(mode.compareTo("Skicka SMS") == 0)
- choiceGroupMode.setSelectedIndex(3, true);
- else
- choiceGroupMode.setSelectedIndex(0, true);
- form.append(choiceGroupMode);
- spacer = new Spacer(10, 10);
- form.append("Version 0.9 (2008-09-02)");
- form.addCommand(exitCommand);
- form.addCommand(okCommand);
- form.setCommandListener(this);
- }
- public void startApp()
- {
- display = Display.getDisplay(this);
- display.setCurrent(form);
- }
- public void pauseApp()
- {
- }
- public void destroyApp(boolean flag)
- {
- mPreferences.put(kPhoneNumber, textFieldPhoneNumber.getString());
- int i = 0;
- do
- {
- if(i >= choiceGroupZone.size())
- break;
- if(choiceGroupZone.isSelected(i))
- {
- zoneCode = choiceGroupZone.getString(i);
- break;
- }
- i++;
- } while(true);
- i = 0;
- do
- {
- if(i >= choiceGroupMode.size())
- break;
- if(choiceGroupMode.isSelected(i))
- {
- mode = choiceGroupMode.getString(i);
- break;
- }
- i++;
- } while(true);
- form.append(mode);
- mPreferences.put(kZoneCode, zoneCode);
- mPreferences.put(kMode, mode);
- try
- {
- mPreferences.save();
- }
- catch(RecordStoreException recordstoreexception) { }
- }
- public void commandAction(Command command, Displayable displayable)
- {
- try
- {
- if(command == exitCommand || command == Alert.DISMISS_COMMAND)
- {
- destroyApp(false);
- notifyDestroyed();
- } else
- if(command == okCommand)
- try
- {
- int i = 0;
- do
- {
- if(i >= choiceGroupZone.size())
- break;
- if(choiceGroupZone.isSelected(i))
- {
- zoneCode = choiceGroupZone.getString(i);
- break;
- }
- i++;
- } while(true);
- sender = new Sender(smsPort, display, form, textFieldPhoneNumber.getString(), zoneCode);
- for(int j = 0; j < choiceGroupMode.size(); j++)
- if(choiceGroupMode.isSelected(j))
- mode = choiceGroupMode.getString(j);
- if(mode.compareTo("Visa standard") == 0)
- sender.display(0);
- else
- if(mode.compareTo("Visa W890i") == 0)
- sender.display(1);
- else
- if(mode.compareTo("Visa transparent") == 0)
- sender.display(2);
- else
- if(mode.compareTo("Skicka SMS") == 0)
- sender.send();
- }
- {
- exception.printStackTrace();
- }
- }
- {
- exception1.printStackTrace();
- }
- }
- private Display display;
- private Form form;
- private Spacer spacer;
- private ImageItem imageItem;
- private TextField textFieldPhoneNumber;
- private ChoiceGroup choiceGroupZone;
- private ChoiceGroup choiceGroupMode;
- private Command exitCommand;
- private Command okCommand;
- private Sender sender;
- private String smsPort;
- private String zoneCode;
- private String mode;
- private Image image;
- String kPhoneNumber;
- String kZoneCode;
- String kMode;
- RecordStore recordStore;
- private Preferences mPreferences;
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.