Posted By


DSTG_Kwan on 01/09/13

Tagged


Statistics


Viewed 785 times
Favorited by 0 user(s)

DSTG_Projekt_WebKalkulator_


/ Published in: Java
Save to your folder(s)

Web aplikacija generira slučajne registracijske oznake za grad Zagreb u odabranom formatu. Ispisuje se i broj mogućih različitih registracijskih tablica za taj format.


Copy this code and paste it in your HTML
  1. /////////////////////////////////// Klasa Kalkulator.java ///////
  2.  
  3. /*******************************************************************************
  4.  * Copyright 2011 Google Inc. All Rights Reserved.
  5.  *
  6.  * All rights reserved. This program and the accompanying materials
  7.  * are made available under the terms of the Eclipse Public License v1.0
  8.  * which accompanies this distribution, and is available at
  9.  * http://www.eclipse.org/legal/epl-v10.html
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  *******************************************************************************/
  17. package hr.foi.dstg.client;
  18.  
  19. import com.google.gwt.core.client.EntryPoint;
  20. import com.google.gwt.user.client.ui.RootPanel;
  21.  
  22. /**
  23.  * Entry point classes define <code>onModuleLoad()</code>.
  24.  */
  25. public class Kalkulator implements EntryPoint {
  26.  
  27. public void onModuleLoad() {
  28. RootPanel rootPanel = RootPanel.get();
  29.  
  30. Calc calc = new Calc();
  31. rootPanel.add(calc, 10, 10);
  32. calc.setSize("344px", "223px");
  33.  
  34.  
  35. }
  36. }
  37.  
  38.  
  39. /////////////////////////////////// Klasa Calc.java ///////
  40.  
  41. package hr.foi.dstg.client;
  42.  
  43. import java.util.Random;
  44.  
  45. import com.google.gwt.user.client.ui.Composite;
  46. import com.google.gwt.user.client.ui.VerticalPanel;
  47. import com.google.gwt.user.client.ui.Label;
  48. import com.google.gwt.user.client.ui.FlexTable;
  49. import com.google.gwt.user.client.ui.RadioButton;
  50. import com.google.gwt.user.client.ui.Button;
  51. import com.google.gwt.user.client.ui.NumberLabel;
  52. import com.google.gwt.event.dom.client.ClickHandler;
  53. import com.google.gwt.event.dom.client.ClickEvent;
  54. import com.google.gwt.user.client.ui.HasHorizontalAlignment;
  55.  
  56. public class Calc extends Composite {
  57.  
  58. RadioButton rdbtnOdabirFormata1 = new RadioButton("new name", "Grad - 3 brojke - 2 slova");
  59. RadioButton rdbtnOdabirFormata2 = new RadioButton("new name", "Grad - 4 brojke - 2 slova");
  60. RadioButton rdbtnOdabirFormata3 = new RadioButton("new name", "Grad - 3 brojke - 1 slovo");
  61. RadioButton rdbtnOdabirFormata4 = new RadioButton("new name", "Grad - 4 brojke - 1 slovo");
  62.  
  63. NumberLabel<Integer> lblIspisBrojaPermutacija = new NumberLabel<Integer>();
  64. Label lblIspisregistracije = new Label("");
  65.  
  66. public static String generateString(Random rng, String characters, int length)
  67. {
  68. char[] text = new char[length];
  69. for (int i = 0; i < length; i++)
  70. {
  71. text[i] = characters.charAt(rng.nextInt(characters.length()));
  72. }
  73. return new String(text);
  74. }
  75.  
  76. public Calc() {
  77.  
  78. VerticalPanel verticalPanel = new VerticalPanel();
  79. verticalPanel.setBorderWidth(0);
  80. initWidget(verticalPanel);
  81.  
  82. Label lblNaslov = new Label(" Odaberite format registracijske oznake: ");
  83. lblNaslov.setStyleName("gwt-DialogBox");
  84. verticalPanel.add(lblNaslov);
  85. lblNaslov.setWidth("449px");
  86.  
  87. FlexTable flexTable = new FlexTable();
  88. flexTable.setBorderWidth(0);
  89. verticalPanel.add(flexTable);
  90.  
  91. rdbtnOdabirFormata1.setValue(true);
  92. flexTable.setWidget(0, 0, rdbtnOdabirFormata1);
  93. flexTable.setWidget(1, 0, rdbtnOdabirFormata2);
  94. flexTable.setWidget(2, 0, rdbtnOdabirFormata3);
  95. flexTable.setWidget(3, 0, rdbtnOdabirFormata4);
  96.  
  97. Button btnIzracunaj = new Button("Izra\u010Dunaj!");
  98. verticalPanel.add(btnIzracunaj);
  99.  
  100. FlexTable flexTable_1 = new FlexTable();
  101. flexTable_1.setBorderWidth(0);
  102. verticalPanel.add(flexTable_1);
  103. flexTable_1.setWidth("338px");
  104.  
  105. Label lblBrojPermutacija = new Label("Broj permutacija:");
  106. flexTable_1.setWidget(0, 0, lblBrojPermutacija);
  107.  
  108. flexTable_1.setWidget(0, 1, lblIspisBrojaPermutacija);
  109.  
  110. Label lblSluajnoGeneriranaRegistracija = new Label("Slu\u010Dajno generirana registracija: ");
  111. flexTable_1.setWidget(1, 0, lblSluajnoGeneriranaRegistracija);
  112.  
  113.  
  114. flexTable_1.setWidget(1, 1, lblIspisregistracije);
  115.  
  116. Label lblBrojSvihMoguih = new Label("Broj svih mogu\u0107ih registracija: ");
  117. flexTable_1.setWidget(2, 0, lblBrojSvihMoguih);
  118.  
  119. NumberLabel<Integer> lblIspisUkupanBroj = new NumberLabel<Integer>();
  120. flexTable_1.setWidget(2, 1, lblIspisUkupanBroj);
  121. flexTable_1.getCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_LEFT);
  122. flexTable_1.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
  123. flexTable_1.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT);
  124. flexTable_1.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_LEFT);
  125. lblIspisUkupanBroj.setValue(5009400);
  126.  
  127. btnIzracunaj.addClickHandler(new ClickHandler() {
  128. public void onClick(ClickEvent event) {
  129.  
  130. int pom = 0;
  131. Random generator = new Random(System.currentTimeMillis());
  132. int broj = 0;
  133. String slova = new String();
  134.  
  135. if (rdbtnOdabirFormata1.getValue()) {
  136. pom = 9*10*10*22*22;
  137. lblIspisBrojaPermutacija.setValue(pom);
  138. broj = generator.nextInt(900) + 100;
  139. slova = generateString(generator, "ABCDEFGHIJKLMNOPRSTUVZ", 2);
  140. lblIspisregistracije.setText("ZG - " + String.valueOf(broj) + " - " + slova);
  141. }
  142.  
  143. else if (rdbtnOdabirFormata2.getValue()) {
  144. pom = 9*10*10*10*22*22;
  145. lblIspisBrojaPermutacija.setValue(pom);
  146. broj = generator.nextInt(900) * generator.nextInt(10) + 1100;
  147. slova = generateString(generator, "ABCDEFGHIJKLMNOPRSTUVZ", 2);
  148. lblIspisregistracije.setText("ZG - " + String.valueOf(broj) + " - " + slova);
  149. }
  150.  
  151. else if (rdbtnOdabirFormata3.getValue()) {
  152. pom = 9*10*10*22;
  153. lblIspisBrojaPermutacija.setValue(pom);
  154. broj = generator.nextInt(900) + 100;
  155. slova = generateString(generator, "ABCDEFGHIJKLMNOPRSTUVZ", 1);
  156. lblIspisregistracije.setText("ZG - " + String.valueOf(broj) + " - " + slova);
  157. }
  158.  
  159. else if (rdbtnOdabirFormata4.getValue()) {
  160. pom = 9*10*10*10*22;
  161. lblIspisBrojaPermutacija.setValue(pom);
  162. broj = generator.nextInt(900) * generator.nextInt(10) + 1100;
  163. slova = generateString(generator, "ABCDEFGHIJKLMNOPRSTUVZ", 1);
  164. lblIspisregistracije.setText("ZG - " + String.valueOf(broj) + " - " + slova);
  165. } ;
  166.  
  167. }
  168. });
  169. }
  170.  
  171. }

URL: http://free.hostingjava.it/-ikovic/Kalkulator.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.