pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Java pastebin - collaborative debugging tool View Help


Posted by RR on Fri 19 Sep 18:27
report abuse | View followups from jahadubrapebernos and Anonymous | download | new post

  1. // Källkoden för Tricket.Jar
  2.  
  3. //------------------------------------------------------CustomHeader.Java------------------------------------------------------\\
  4. package example.sms;
  5.  
  6. import javax.microedition.lcdui.*;
  7.  
  8. public class CustomHeader extends CustomItem
  9. {
  10.  
  11.     public CustomHeader(int i, String s, String s1)
  12.     {
  13.         super(null);
  14.         height = 70;
  15.         smsCentralNumber = s;
  16.         date = s1;
  17.         width = i;
  18.         setLayout(2576);
  19.     }
  20.  
  21.     protected int getMinContentHeight()
  22.     {
  23.         return height;
  24.     }
  25.  
  26.     protected int getMinContentWidth()
  27.     {
  28.         return width;
  29.     }
  30.  
  31.     protected int getPrefContentHeight(int i)
  32.     {
  33.         return getMinContentHeight();
  34.     }
  35.  
  36.     protected int getPrefContentWidth(int i)
  37.     {
  38.         return getMinContentWidth();
  39.     }
  40.  
  41.     protected void paint(Graphics g, int i, int j)
  42.     {
  43.         for(int k = 0; k < j; k++)
  44.         {
  45.             g.setColor(255 - k, 255 - k, 255 - k);
  46.             g.drawLine(0, k, i, k);
  47.         }
  48.  
  49.         g.setColor(80, 80, 80);
  50.         g.setFont(Font.getFont(0, 0, 16));
  51.         g.drawString(smsCentralNumber, 2, 7, 20);
  52.         g.setFont(Font.getFont(0, 0, 0));
  53.         g.drawString(date, 2, 40, 20);
  54.     }
  55.  
  56.     int width;
  57.     int height;
  58.     String smsCentralNumber;
  59.     String date;
  60. }
  61.  
  62. //------------------------------------------------------CustomHeaderTransparent.Java------------------------------------------------------\\
  63. package example.sms;
  64.  
  65. import javax.microedition.lcdui.*;
  66.  
  67. public class CustomHeaderTransparent extends CustomItem
  68. {
  69.  
  70.     public CustomHeaderTransparent(int i, String s, String s1)
  71.     {
  72.         super(null);
  73.         height = 70;
  74.         smsCentralNumber = s;
  75.         date = s1;
  76.         width = i;
  77.         setLayout(2576);
  78.     }
  79.  
  80.     protected int getMinContentHeight()
  81.     {
  82.         return height;
  83.     }
  84.  
  85.     protected int getMinContentWidth()
  86.     {
  87.         return width;
  88.     }
  89.  
  90.     protected int getPrefContentHeight(int i)
  91.     {
  92.         return getMinContentHeight();
  93.     }
  94.  
  95.     protected int getPrefContentWidth(int i)
  96.     {
  97.         return getMinContentWidth();
  98.     }
  99.  
  100.     protected void paint(Graphics g, int i, int j)
  101.     {
  102.         g.setColor(80, 80, 80);
  103.         g.setFont(Font.getFont(0, 0, 16));
  104.         g.drawString(smsCentralNumber, 2, 7, 20);
  105.         g.setFont(Font.getFont(0, 0, 0));
  106.         g.drawString(date, 2, 40, 20);
  107.     }
  108.  
  109.     int width;
  110.     int height;
  111.     String smsCentralNumber;
  112.     String date;
  113. }
  114.  
  115. //------------------------------------------------------Generator.Java------------------------------------------------------\\
  116. package example.sms;
  117.  
  118. import java.util.Calendar;
  119. import java.util.Random;
  120. import javax.microedition.lcdui.Form;
  121.  
  122. public class Generator
  123. {
  124.  
  125.     public Generator(String s, String s1)
  126.     {
  127.         newLine = "\n";
  128.         minutesValid = 75;
  129.         minutesOffset = 2;
  130.         phoneNumber = s;
  131.         zoneCode = s1;
  132.         calendar = Calendar.getInstance();
  133.         expiryCalendar = Calendar.getInstance();
  134.         expiryCalendar.set(12, expiryCalendar.get(12) + minutesValid);
  135.         random = new Random();
  136.         smsCentralNumber = getSmsCentralNumber();
  137.     }
  138.  
  139.     private String getSmsCentralNumber()
  140.     {
  141.         String s = "72150";
  142.         String s1 = "";
  143.         if(zoneCode.compareTo("A") == 0)
  144.             s1 = "11";
  145.         else
  146.         if(zoneCode.compareTo("AB") == 0)
  147.             s1 = "24";
  148.         else
  149.         if(zoneCode.compareTo("ABC") == 0)
  150.             s1 = "36";
  151.         s = s + s1 + formatInt(calendar.get(12) + minutesOffset);
  152.         return s;
  153.     }
  154.  
  155.     public String getDateFormatted()
  156.     {
  157.         return String.valueOf(calendar.get(1)) + "-" + formatInt(calendar.get(2) + 1) + "-" + formatInt(calendar.get(5));
  158.     }
  159.  
  160.     public String getTimeFormatted()
  161.     {
  162.         return formatInt(calendar.get(11)) + ":" + formatInt(calendar.get(12));
  163.     }
  164.  
  165.     public String getBody(Form form)
  166.     {
  167.         String s = "0";
  168.         String s10 = "";
  169.         String s11 = "";
  170.         Random random1 = new Random();
  171.         int i = random1.nextInt() % 26;
  172.         if(i < 0)
  173.             i = -i;
  174.         String s12 = String.valueOf((char)(97 + i));
  175.         s12 = s12 + generateNumber(6);
  176.         String s13 = generateNumber(9);
  177.         String s14 = s13.substring(0, 1) + generateNumber(8);
  178.         String s15 = generateNumber(9);
  179.         if(zoneCode.compareTo("A") == 0)
  180.         {
  181.             s = "30";
  182.             s11 = "A";
  183.         } else
  184.         if(zoneCode.compareTo("AB") == 0)
  185.         {
  186.             s = "45";
  187.             s11 = "D";
  188.         } else
  189.         if(zoneCode.compareTo("ABC") == 0)
  190.         {
  191.             s = "60";
  192.             s11 = "E";
  193.         }
  194.         String s5 = getDateFormatted();
  195.         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);
  196.         String s2 = phoneNumber.substring(phoneNumber.length() - 3);
  197.         String s6 = formatInt(calendar.get(11)) + formatInt(calendar.get(12));
  198.         String s9 = formatInt(expiryCalendar.get(11)) + ":" + formatInt(expiryCalendar.get(12));
  199.         String s4 = String.valueOf(expiryCalendar.get(1)) + "-" + formatInt(expiryCalendar.get(2) + 1) + "-" + formatInt(expiryCalendar.get(5));
  200.         String s7 = formatInt(expiryCalendar.get(5));
  201.         String s8 = String.valueOf((char)(65 + expiryCalendar.get(2)));
  202.         String s16 = String.valueOf(minutesOffset + 1);
  203.         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;
  204.         return s3;
  205.     }
  206.  
  207.     private String generateNumber(int i)
  208.     {
  209.         String s = "";
  210.         for(int k = 0; k < i; k++)
  211.         {
  212.             int j = random.nextInt() % 10;
  213.             if(j < 0)
  214.                 j = -j;
  215.             s = s + String.valueOf(j);
  216.         }
  217.  
  218.         return s;
  219.     }
  220.  
  221.     private String formatInt(int i)
  222.     {
  223.         String s = String.valueOf(i);
  224.         if(s.length() == 1)
  225.             s = "0" + s;
  226.         return s;
  227.     }
  228.  
  229.     private String phoneNumber;
  230.     private String zoneCode;
  231.     private Calendar calendar;
  232.     private Calendar expiryCalendar;
  233.     private String newLine;
  234.     private int minutesValid;
  235.     private int minutesOffset;
  236.     public String smsCentralNumber;
  237.     private Random random;
  238. }
  239.  
  240. //------------------------------------------------------Preferences.Java------------------------------------------------------\\
  241. package example.sms;
  242.  
  243. import java.util.Enumeration;
  244. import java.util.Hashtable;
  245. import javax.microedition.rms.*;
  246.  
  247. public class Preferences
  248. {
  249.  
  250.     public Preferences(String s)
  251.         throws RecordStoreException
  252.     {
  253.         mRecordStoreName = s;
  254.         mHashtable = new Hashtable();
  255.         load();
  256.     }
  257.  
  258.     public String get(String s)
  259.     {
  260.         return (String)mHashtable.get(s);
  261.     }
  262.  
  263.     public void put(String s, String s1)
  264.     {
  265.         if(s1 == null)
  266.             s1 = "";
  267.         mHashtable.put(s, s1);
  268.     }
  269.  
  270.     private void load()
  271.         throws RecordStoreException
  272.     {
  273.         RecordStore recordstore;
  274.         RecordEnumeration recordenumeration;
  275.         recordstore = null;
  276.         recordenumeration = null;
  277.         recordstore = RecordStore.openRecordStore(mRecordStoreName, true);
  278.         String s1;
  279.         String s2;
  280.         for(recordenumeration = recordstore.enumerateRecords(null, null, false); recordenumeration.hasNextElement(); put(s1, s2))
  281.         {
  282.             byte abyte0[] = recordenumeration.nextRecord();
  283.             String s = new String(abyte0);
  284.             int i = s.indexOf('|');
  285.             s1 = s.substring(0, i);
  286.             s2 = s.substring(i + 1);
  287.         }
  288.  
  289.         if(recordenumeration != null)
  290.             recordenumeration.destroy();
  291.         if(recordstore != null)
  292.             recordstore.closeRecordStore();
  293.         break MISSING_BLOCK_LABEL_132;
  294.         Exception exception;
  295.         exception;
  296.         if(recordenumeration != null)
  297.             recordenumeration.destroy();
  298.         if(recordstore != null)
  299.             recordstore.closeRecordStore();
  300.         throw exception;
  301.     }
  302.  
  303.     public void save()
  304.         throws RecordStoreException
  305.     {
  306.         RecordStore recordstore;
  307.         RecordEnumeration recordenumeration;
  308.         recordstore = null;
  309.         recordenumeration = null;
  310.         recordstore = RecordStore.openRecordStore(mRecordStoreName, true);
  311.         int i;
  312.         for(recordenumeration = recordstore.enumerateRecords(null, null, false); recordenumeration.hasNextElement(); recordstore.deleteRecord(i))
  313.             i = recordenumeration.nextRecordId();
  314.  
  315.         byte abyte0[];
  316.         for(Enumeration enumeration = mHashtable.keys(); enumeration.hasMoreElements(); recordstore.addRecord(abyte0, 0, abyte0.length))
  317.         {
  318.             String s = (String)enumeration.nextElement();
  319.             String s1 = get(s);
  320.             String s2 = s + "|" + s1;
  321.             abyte0 = s2.getBytes();
  322.         }
  323.  
  324.         if(recordenumeration != null)
  325.             recordenumeration.destroy();
  326.         if(recordstore != null)
  327.             recordstore.closeRecordStore();
  328.         break MISSING_BLOCK_LABEL_173;
  329.         Exception exception;
  330.         exception;
  331.         if(recordenumeration != null)
  332.             recordenumeration.destroy();
  333.         if(recordstore != null)
  334.             recordstore.closeRecordStore();
  335.         throw exception;
  336.     }
  337.  
  338.     private String mRecordStoreName;
  339.     private Hashtable mHashtable;
  340. }
  341.  
  342. //------------------------------------------------------Sender.Java------------------------------------------------------\\
  343. package example.sms;
  344.  
  345. import java.io.IOException;
  346. import java.io.PrintStream;
  347. import javax.microedition.io.Connector;
  348. import javax.microedition.lcdui.*;
  349. import javax.wireless.messaging.MessageConnection;
  350. import javax.wireless.messaging.TextMessage;
  351.  
  352. // Referenced classes of package example.sms:
  353. //            Generator, CustomHeader, CustomHeaderTransparent
  354.  
  355. public class Sender
  356.     implements CommandListener, Runnable
  357. {
  358.  
  359.     public Sender(String s, Display display1, Displayable displayable, String s1, String s2)
  360.     {
  361.         backCommand = new Command("Tillbaka", 3, 1);
  362.         cancelCommand = new Command("Avbryt", 3, 1);
  363.         altCommand = new Command("Alternativ", 2, 2);
  364.         replyCommand = new Command("Svara", 4, 3);
  365.         smsPort = s;
  366.         display = display1;
  367.         destinationAddress = null;
  368.         backScreen = displayable;
  369.         phoneNumber = s1;
  370.         zoneCode = s2;
  371.     }
  372.  
  373.     public void display(int i)
  374.     {
  375.         generator = new Generator(phoneNumber, zoneCode);
  376.         if(i == 0)
  377.             form = new Form(generator.smsCentralNumber + "        " + generator.getTimeFormatted() + "        ");
  378.         else
  379.         if(i == 1)
  380.         {
  381.             form = new Form(null);
  382.             customHeader = new CustomHeader(form.getWidth(), generator.smsCentralNumber, generator.getDateFormatted() + " " + generator.getTimeFormatted());
  383.             form.append(customHeader);
  384.         } else
  385.         {
  386.             form = new Form(null);
  387.             customHeaderTransparent = new CustomHeaderTransparent(form.getWidth(), generator.smsCentralNumber, generator.getDateFormatted() + " " + generator.getTimeFormatted());
  388.             form.append(customHeaderTransparent);
  389.         }
  390.         form.append(generator.getBody(form));
  391.         form.addCommand(backCommand);
  392.         form.addCommand(altCommand);
  393.         form.addCommand(replyCommand);
  394.         form.setCommandListener(this);
  395.         display.setCurrent(form);
  396.     }
  397.  
  398.     public void send()
  399.     {
  400.         form = new Form("Tricket [SMS]");
  401.         form.addCommand(cancelCommand);
  402.         form.setCommandListener(this);
  403.         display.setCurrent(form);
  404.         generator = new Generator(phoneNumber, zoneCode);
  405.         body = generator.getBody(form);
  406.         (new Thread(this)).start();
  407.     }
  408.  
  409.     public void commandAction(Command command, Displayable displayable)
  410.     {
  411.         try
  412.         {
  413.             if(command == backCommand || command == cancelCommand)
  414.                 display.setCurrent(backScreen);
  415.         }
  416.         catch(Exception exception)
  417.         {
  418.             exception.printStackTrace();
  419.         }
  420.     }
  421.  
  422.     public void run()
  423.     {
  424.         String s = "sms://" + phoneNumber + ":" + smsPort;
  425.         try
  426.         {
  427.             form.append("Skapar koppling...");
  428.             smsConn = (MessageConnection)Connector.open(s);
  429.             form.append("Skapar meddelande...");
  430.             TextMessage textmessage = (TextMessage)smsConn.newMessage("text");
  431.             textmessage.setAddress(s);
  432.             textmessage.setPayloadText(body);
  433.             form.append("Skickar SMS...");
  434.             smsConn.send(textmessage);
  435.         }
  436.         catch(Throwable throwable)
  437.         {
  438.             System.out.println("Send caught: ");
  439.             throwable.printStackTrace();
  440.         }
  441.         if(smsConn != null)
  442.             try
  443.             {
  444.                 form.append("St\344nger koppling...");
  445.                 smsConn.close();
  446.             }
  447.             catch(IOException ioexception)
  448.             {
  449.                 form.append("Closing connection caught: " + ioexception.toString());
  450.             }
  451.     }
  452.  
  453.     Command backCommand;
  454.     Command cancelCommand;
  455.     Command altCommand;
  456.     Command replyCommand;
  457.     MessageConnection smsConn;
  458.     Display display;
  459.     String smsPort;
  460.     String destinationAddress;
  461.     Displayable backScreen;
  462.     Form form;
  463.     String phoneNumber;
  464.     String zoneCode;
  465.     Generator generator;
  466.     CustomHeader customHeader;
  467.     CustomHeaderTransparent customHeaderTransparent;
  468.     String body;
  469. }
  470.  
  471. //------------------------------------------------------Tricket.Java------------------------------------------------------\\
  472. package example.sms;
  473.  
  474. import javax.microedition.lcdui.*;
  475. import javax.microedition.midlet.MIDlet;
  476. import javax.microedition.rms.RecordStore;
  477. import javax.microedition.rms.RecordStoreException;
  478.  
  479. // Referenced classes of package example.sms:
  480. //            Preferences, Sender
  481.  
  482. public class Tricket extends MIDlet
  483.     implements CommandListener
  484. {
  485.  
  486.     public Tricket()
  487.     {
  488.         exitCommand = new Command("Avsluta", 7, 2);
  489.         okCommand = new Command("OK", 4, 1);
  490.         smsPort = "666";
  491.         kPhoneNumber = "phone";
  492.         kZoneCode = "zone";
  493.         kMode = "mode";
  494.         try
  495.         {
  496.             mPreferences = new Preferences("preferences");
  497.         }
  498.         catch(Exception exception)
  499.         {
  500.             exception.printStackTrace();
  501.         }
  502.         form = new Form(null);
  503.         try
  504.         {
  505.             image = Image.createImage("/Logo.png");
  506.             imageItem = new ImageItem(null, image, 769, "My Image");
  507.             form.append(imageItem);
  508.         }
  509.         catch(Exception exception1)
  510.         {
  511.             exception1.printStackTrace();
  512.         }
  513.         textFieldPhoneNumber = new TextField("Telefonnummer", mPreferences.get(kPhoneNumber), 50, 3);
  514.         form.append(textFieldPhoneNumber);
  515.         spacer = new Spacer(10, 10);
  516.         form.append(spacer);
  517.         choiceGroupZone = new ChoiceGroup("Zon", 1, new String[] {
  518.             "A", "AB", "ABC"
  519.         }, null);
  520.         zoneCode = String.valueOf(mPreferences.get(kZoneCode));
  521.         if(zoneCode.compareTo("A") == 0)
  522.             choiceGroupZone.setSelectedIndex(0, true);
  523.         else
  524.         if(zoneCode.compareTo("AB") == 0)
  525.             choiceGroupZone.setSelectedIndex(0, true);
  526.         else
  527.         if(zoneCode.compareTo("ABC") == 0)
  528.             choiceGroupZone.setSelectedIndex(2, true);
  529.         else
  530.             choiceGroupZone.setSelectedIndex(0, true);
  531.         form.append(choiceGroupZone);
  532.         spacer = new Spacer(10, 10);
  533.         choiceGroupMode = new ChoiceGroup("Hur?", 1, new String[] {
  534.             "Visa standard", "Visa W890i", "Visa transparent", "Skicka SMS"
  535.         }, null);
  536.         mode = String.valueOf(mPreferences.get(kMode));
  537.         if(mode.compareTo("Visa standard") == 0)
  538.             choiceGroupMode.setSelectedIndex(0, true);
  539.         else
  540.         if(mode.compareTo("Visa W890i") == 0)
  541.             choiceGroupMode.setSelectedIndex(1, true);
  542.         else
  543.         if(mode.compareTo("Visa transparent") == 0)
  544.             choiceGroupMode.setSelectedIndex(2, true);
  545.         else
  546.         if(mode.compareTo("Skicka SMS") == 0)
  547.             choiceGroupMode.setSelectedIndex(3, true);
  548.         else
  549.             choiceGroupMode.setSelectedIndex(0, true);
  550.         form.append(choiceGroupMode);
  551.         spacer = new Spacer(10, 10);
  552.         form.append("Version  0.9 (2008-09-02)");
  553.         form.addCommand(exitCommand);
  554.         form.addCommand(okCommand);
  555.         form.setCommandListener(this);
  556.     }
  557.  
  558.     public void startApp()
  559.     {
  560.         display = Display.getDisplay(this);
  561.         display.setCurrent(form);
  562.     }
  563.  
  564.     public void pauseApp()
  565.     {
  566.     }
  567.  
  568.     public void destroyApp(boolean flag)
  569.     {
  570.         mPreferences.put(kPhoneNumber, textFieldPhoneNumber.getString());
  571.         int i = 0;
  572.         do
  573.         {
  574.             if(i >= choiceGroupZone.size())
  575.                 break;
  576.             if(choiceGroupZone.isSelected(i))
  577.             {
  578.                 zoneCode = choiceGroupZone.getString(i);
  579.                 break;
  580.             }
  581.             i++;
  582.         } while(true);
  583.         i = 0;
  584.         do
  585.         {
  586.             if(i >= choiceGroupMode.size())
  587.                 break;
  588.             if(choiceGroupMode.isSelected(i))
  589.             {
  590.                 mode = choiceGroupMode.getString(i);
  591.                 break;
  592.             }
  593.             i++;
  594.         } while(true);
  595.         form.append(mode);
  596.         mPreferences.put(kZoneCode, zoneCode);
  597.         mPreferences.put(kMode, mode);
  598.         try
  599.         {
  600.             mPreferences.save();
  601.         }
  602.         catch(RecordStoreException recordstoreexception) { }
  603.     }
  604.  
  605.     public void commandAction(Command command, Displayable displayable)
  606.     {
  607.         try
  608.         {
  609.             if(command == exitCommand || command == Alert.DISMISS_COMMAND)
  610.             {
  611.                 destroyApp(false);
  612.                 notifyDestroyed();
  613.             } else
  614.             if(command == okCommand)
  615.                 try
  616.                 {
  617.                     int i = 0;
  618.                     do
  619.                     {
  620.                         if(i >= choiceGroupZone.size())
  621.                             break;
  622.                         if(choiceGroupZone.isSelected(i))
  623.                         {
  624.                             zoneCode = choiceGroupZone.getString(i);
  625.                             break;
  626.                         }
  627.                         i++;
  628.                     } while(true);
  629.                     sender = new Sender(smsPort, display, form, textFieldPhoneNumber.getString(), zoneCode);
  630.                     for(int j = 0; j < choiceGroupMode.size(); j++)
  631.                         if(choiceGroupMode.isSelected(j))
  632.                             mode = choiceGroupMode.getString(j);
  633.  
  634.                     if(mode.compareTo("Visa standard") == 0)
  635.                         sender.display(0);
  636.                     else
  637.                     if(mode.compareTo("Visa W890i") == 0)
  638.                         sender.display(1);
  639.                     else
  640.                     if(mode.compareTo("Visa transparent") == 0)
  641.                         sender.display(2);
  642.                     else
  643.                     if(mode.compareTo("Skicka SMS") == 0)
  644.                         sender.send();
  645.                 }
  646.                 catch(Exception exception)
  647.                 {
  648.                     exception.printStackTrace();
  649.                 }
  650.         }
  651.         catch(Exception exception1)
  652.         {
  653.             exception1.printStackTrace();
  654.         }
  655.     }
  656.  
  657.     private Display display;
  658.     private Form form;
  659.     private Spacer spacer;
  660.     private ImageItem imageItem;
  661.     private TextField textFieldPhoneNumber;
  662.     private ChoiceGroup choiceGroupZone;
  663.     private ChoiceGroup choiceGroupMode;
  664.     private Command exitCommand;
  665.     private Command okCommand;
  666.     private Sender sender;
  667.     private String smsPort;
  668.     private String zoneCode;
  669.     private String mode;
  670.     private Image image;
  671.     String kPhoneNumber;
  672.     String kZoneCode;
  673.     String kMode;
  674.     RecordStore recordStore;
  675.     private Preferences mPreferences;
  676. }

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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post