mardi 2 juin 2015

Java Programm für Prüfzahl Berechnung eines Persnalausweises bzw. Prüfung auf Richtigkeit

Hallo,
Ich muss aktuell ein Java-Projekt für die schule realisieren und habe nun auch schon den Großteil gemacht leider wirft Java bei meinem Projekt immer einen Fehler aus. Der da wäre :

Code:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:592)
    at java.lang.Integer.parseInt(Integer.java:615)
    at personalausweis.jButton1_ActionPerformed(personalausweis.java:324)
    at personalausweis$1.actionPerformed(personalausweis.java:222)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Ich habe keine Ahnung woran dies liegen könnte bitte um Hilfe
hier der Quelltext:
Java Code:

  1.  
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6. import javax.swing.event.*;
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. public class personalausweis extends JFrame {
  16. // Anfang Attribute
  17. private JLabel jLabel1 = new JLabel();
  18. private JTextField jTextField1 = new JTextField();
  19. private JLabel jLabel2 = new JLabel();
  20. private JTextField jTextField2 = new JTextField();
  21. private JLabel jLabel3 = new JLabel();
  22. private JNumberField jNumberField1 = new JNumberField();
  23. private JNumberField jNumberField2 = new JNumberField();
  24. private JNumberField jNumberField3 = new JNumberField();
  25. private JNumberField jNumberField4 = new JNumberField();
  26. private JNumberField jNumberField5 = new JNumberField();
  27. private JNumberField jNumberField6 = new JNumberField();
  28. private JNumberField jNumberField7 = new JNumberField();
  29. private JNumberField jNumberField8 = new JNumberField();
  30. private JNumberField jNumberField9 = new JNumberField();
  31. private JNumberField jNumberField10 = new JNumberField();
  32. private JTextField jTextField4 = new JTextField();
  33. private JLabel jLabel4 = new JLabel();
  34. private JLabel jLabel5 = new JLabel();
  35. private JNumberField jNumberField11 = new JNumberField();
  36. private JNumberField jNumberField12 = new JNumberField();
  37. private JNumberField jNumberField13 = new JNumberField();
  38. private JNumberField jNumberField14 = new JNumberField();
  39. private JNumberField jNumberField15 = new JNumberField();
  40. private JNumberField jNumberField16 = new JNumberField();
  41. private JNumberField jNumberField17 = new JNumberField();
  42. private JLabel jLabel6 = new JLabel();
  43. private JNumberField jNumberField18 = new JNumberField();
  44. private JNumberField jNumberField19 = new JNumberField();
  45. private JNumberField jNumberField20 = new JNumberField();
  46. private JNumberField jNumberField21 = new JNumberField();
  47. private JNumberField jNumberField22 = new JNumberField();
  48. private JNumberField jNumberField23 = new JNumberField();
  49. private JNumberField jNumberField24 = new JNumberField();
  50. private JLabel jLabel7 = new JLabel();
  51. private JNumberField jNumberField25 = new JNumberField();
  52. private JLabel jLabel8 = new JLabel();
  53. private JButton jButton1 = new JButton();
  54. private JLabel jLabel9 = new JLabel();
  55.  
  56.  
  57.  
  58. String nachname;
  59. String vorname;
  60. int zahl1;
  61. int zahl2;
  62. int zahl3;
  63. int zahl4;
  64. int zahl5;
  65. int zahl6;
  66. int zahl7;
  67. int zahl8;
  68. int zahl9;
  69. int zahl10;
  70. int zahl11;
  71. int zahl12;
  72. int zahl13;
  73. int zahl14;
  74. int zahl15;
  75. int zahl16;
  76. int zahl17;
  77. int zahl18;
  78. int zahl19;
  79. int zahl20;
  80. int zahl21;
  81. int zahl22;
  82. int zahl23;
  83. int zahl24;
  84. int zahl25;
  85.  
  86.  
  87.  
  88.  
  89.  
  90. // Ende Attribute
  91.  
  92. public personalausweis(String title) {
  93. // Frame-Initialisierung
  94. super(title);
  95. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  96. int frameWidth = 800;
  97. int frameHeight = 784;
  98. setSize(frameWidth, frameHeight);
  99. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  100. int x = (d.width - getSize().width) / 2;
  101. int y = (d.height - getSize().height) / 2;
  102. setLocation(x, y);
  103. setResizable(false);
  104. Container cp = getContentPane();
  105. cp.setLayout(null);
  106. // Anfang Komponenten
  107.  
  108. jLabel1.setBounds(74, 88, 30, 25);
  109. jLabel1.setText("<<");
  110. cp.add(jLabel1);
  111. jTextField1.setBounds(96, 88, 94, 25);
  112.  
  113. cp.add(jTextField1);
  114. jLabel2.setBounds(192, 88, 30, 25);
  115. jLabel2.setText("<<");
  116. cp.add(jLabel2);
  117. jTextField2.setBounds(216, 88, 94, 25);
  118. cp.add(jTextField2);
  119. jLabel3.setBounds(312, 88, 94, 25);
  120. jLabel3.setText("<<<<<<<<<<<<<");
  121. cp.add(jLabel3);
  122. jNumberField1.setBounds(48, 120, 19, 25);
  123. jNumberField1.setText("");
  124. cp.add(jNumberField1);
  125. jNumberField2.setBounds(72, 120, 19, 25);
  126. jNumberField2.setText("");
  127. cp.add(jNumberField2);
  128. jNumberField3.setBounds(96, 120, 19, 25);
  129. jNumberField3.setText("");
  130. cp.add(jNumberField3);
  131. jNumberField4.setBounds(120, 120, 19, 25);
  132. jNumberField4.setText("");
  133. cp.add(jNumberField4);
  134. jNumberField5.setBounds(144, 120, 19, 25);
  135. jNumberField5.setText("");
  136. cp.add(jNumberField5);
  137. jNumberField6.setBounds(168, 120, 19, 25);
  138. jNumberField6.setText("");
  139. cp.add(jNumberField6);
  140. jNumberField7.setBounds(192, 120, 19, 25);
  141. jNumberField7.setText("");
  142. cp.add(jNumberField7);
  143. jNumberField8.setBounds(216, 120, 19, 25);
  144. jNumberField8.setText("");
  145. cp.add(jNumberField8);
  146. jNumberField9.setBounds(240, 120, 19, 25);
  147. jNumberField9.setText("");
  148. cp.add(jNumberField9);
  149. jNumberField10.setBounds(264, 120, 19, 25);
  150. jNumberField10.setText("");
  151. cp.add(jNumberField10);
  152. jTextField4.setBounds(288, 120, 30, 25);
  153. cp.add(jTextField4);
  154. jLabel4.setBounds(48, 88, 30, 25);
  155. jLabel4.setText("IDD");
  156. cp.add(jLabel4);
  157. jLabel5.setBounds(320, 120, 14, 25);
  158. jLabel5.setText("<<");
  159. cp.add(jLabel5);
  160. jNumberField11.setBounds(336, 120, 19, 25);
  161. jNumberField11.setText("");
  162. cp.add(jNumberField11);
  163. jNumberField12.setBounds(360, 120, 19, 25);
  164. jNumberField12.setText("");
  165. cp.add(jNumberField12);
  166. jNumberField13.setBounds(384, 120, 19, 25);
  167. jNumberField13.setText("");
  168. cp.add(jNumberField13);
  169. jNumberField14.setBounds(408, 120, 19, 25);
  170. jNumberField14.setText("");
  171. cp.add(jNumberField14);
  172. jNumberField15.setBounds(432, 120, 19, 25);
  173. jNumberField15.setText("");
  174. cp.add(jNumberField15);
  175. jNumberField16.setBounds(456, 120, 19, 25);
  176. jNumberField16.setText("");
  177. cp.add(jNumberField16);
  178. jNumberField17.setBounds(480, 120, 19, 25);
  179. jNumberField17.setText("");
  180. cp.add(jNumberField17);
  181. jLabel6.setBounds(504, 120, 14, 25);
  182. jLabel6.setText("<");
  183. cp.add(jLabel6);
  184. jNumberField18.setBounds(520, 120, 19, 25);
  185. jNumberField18.setText("");
  186. cp.add(jNumberField18);
  187. jNumberField19.setBounds(544, 120, 19, 25);
  188. jNumberField19.setText("");
  189. cp.add(jNumberField19);
  190. jNumberField20.setBounds(568, 120, 19, 25);
  191. jNumberField20.setText("");
  192. cp.add(jNumberField20);
  193. jNumberField21.setBounds(592, 120, 19, 25);
  194. jNumberField21.setText("");
  195. cp.add(jNumberField21);
  196. jNumberField22.setBounds(616, 120, 19, 25);
  197. jNumberField22.setText("");
  198. cp.add(jNumberField22);
  199. jNumberField23.setBounds(640, 120, 19, 25);
  200. jNumberField23.setText("");
  201. cp.add(jNumberField23);
  202. jNumberField24.setBounds(664, 120, 19, 25);
  203. jNumberField24.setText("");
  204. cp.add(jNumberField24);
  205. jLabel7.setBounds(688, 120, 54, 25);
  206. jLabel7.setText("<<<<<<<");
  207. cp.add(jLabel7);
  208. jNumberField25.setBounds(738, 120, 19, 25);
  209. jNumberField25.setText("");
  210. cp.add(jNumberField25);
  211. jLabel8.setBounds(88, 336, 627, 425);
  212. jLabel8.setIcon(new ImageIcon("Perso.PNG"));
  213. jLabel8.setText("Perso.png");
  214. cp.add(jLabel8);
  215.  
  216.  
  217. jButton1.setBounds(328, 200, 171, 65);
  218. jButton1.setText("Personalausweis Prüfen");
  219. jButton1.setMargin(new Insets(2, 2, 2, 2));
  220. jButton1.addActionListener(new ActionListener() {
  221. public void actionPerformed(ActionEvent evt) {
  222. jButton1_ActionPerformed(evt);
  223. }
  224. });
  225. cp.add(jButton1);
  226. jLabel9.setBounds(216, 16, 403, 41);
  227. jLabel9.setText("Geben sie die Prüfziffern ihres Personalasweises ein. (Siehe unten)");
  228. cp.add(jLabel9);
  229. setTitle("IDC - Identification Check");
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. // Ende Komponenten
  237.  
  238. setVisible(true);
  239. }
  240.  
  241. // Anfang Methoden
  242. public void jButton1_ActionPerformed(ActionEvent evt) {
  243.  
  244.  
  245. nachname = jTextField1.getSelectedText();
  246. vorname = jTextField2.getSelectedText();
  247.  
  248. zahl1 = jNumberField1.getInt();
  249. zahl2 = jNumberField2.getInt();
  250. zahl3 = jNumberField3.getInt();
  251. zahl4 = jNumberField4.getInt();
  252. zahl5 = jNumberField5.getInt();
  253. zahl6 = jNumberField6.getInt();
  254. zahl7 = jNumberField7.getInt();
  255. zahl8 = jNumberField8.getInt();
  256. zahl9 = jNumberField9.getInt();
  257. zahl10 = jNumberField10.getInt();
  258. String land = jTextField4.getSelectedText();
  259. zahl11 = jNumberField11.getInt();
  260. zahl12 = jNumberField12.getInt();
  261. zahl13 = jNumberField13.getInt();
  262. zahl14 = jNumberField14.getInt();
  263. zahl15 = jNumberField15.getInt();
  264. zahl16 = jNumberField16.getInt();
  265. zahl17 = jNumberField17.getInt();
  266. zahl18 = jNumberField18.getInt();
  267. zahl19 = jNumberField19.getInt();
  268. zahl20 = jNumberField20.getInt();
  269. zahl21 = jNumberField21.getInt();
  270. zahl22 = jNumberField22.getInt();
  271. zahl23 = jNumberField23.getInt();
  272. zahl24 = jNumberField24.getInt();
  273. zahl25 = jNumberField25.getInt();
  274.  
  275.  
  276. zahl1 = zahl1 * 7;
  277. zahl2 = zahl2 * 3;
  278. zahl3 = zahl3 * 1;
  279. zahl4 = zahl4 * 7;
  280. zahl5 = zahl5 * 3;
  281. zahl6 = zahl6 * 1;
  282. zahl7 = zahl7 * 7;
  283. zahl8 = zahl8 * 3;
  284. zahl9 = zahl9 * 1;
  285. zahl11 = zahl11 * 3;
  286. zahl12 = zahl12 * 1;
  287. zahl13 = zahl13 * 7;
  288. zahl14 = zahl14 * 3;
  289. zahl15 = zahl15 * 1;
  290. zahl16 = zahl16 * 7;
  291. zahl18 = zahl18 * 1;
  292. zahl19 = zahl19 * 7;
  293. zahl20 = zahl20 * 3;
  294. zahl21 = zahl21 * 1;
  295. zahl22 = zahl22 * 7;
  296. zahl23 = zahl23 * 3;
  297.  
  298.  
  299. //zahl1
  300. String s1 = String.valueOf(zahl1);
  301. int index1 = s1.length();
  302. int länge1 = index1-1;
  303. s1 = s1.substring(länge1, index1);
  304. int z1 = Integer.parseInt(s1.toString());
  305.  
  306.  
  307.  
  308. //zahl2
  309. String s2 = String.valueOf(zahl2);
  310. int index2 = s2.length();
  311. int länge2 = index1-1;
  312. s2 = s2.substring(länge2, index2);
  313. int z2 = Integer.parseInt(s2.toString());
  314.  
  315.  
  316. //zahl3
  317. String s3 = String.valueOf(zahl3);
  318. int index3 = s3.length();
  319. int länge3 = index1-1;
  320. s3 = s3.substring(länge3, index3);
  321. int z3 = Integer.parseInt(s3.toString());
  322.  
  323.  
  324.  
  325. //zahl4
  326. String s4 = String.valueOf(zahl4);
  327. int index4 = s4.length();
  328. int länge4 = index1-1;
  329. s4 = s4.substring(länge4, index4);
  330. int z4 = Integer.parseInt(s4.toString());
  331.  
  332. //zahl5
  333. String s5 = String.valueOf(zahl5);
  334. int index5 = s5.length();
  335. int länge5 = index1-1;
  336. s5 = s5.substring(länge5, index5);
  337. int z5 = Integer.parseInt(s5.toString());
  338.  
  339. //zahl6
  340. String s6 = String.valueOf(zahl6);
  341. int index6 = s6.length();
  342. int länge6 = index1-1;
  343. s6 = s6.substring(länge6, index6);
  344. int z6 = Integer.parseInt(s6.toString());
  345.  
  346. //zahl7
  347. String s7 = String.valueOf(zahl7);
  348. int index7 = s7.length();
  349. int länge7 = index1-1;
  350. s7 = s7.substring(länge7, index7);
  351. int z7 = Integer.parseInt(s7.toString());
  352.  
  353. //zahl8
  354. String s8 = String.valueOf(zahl8);
  355. int index8 = s8.length();
  356. int länge8 = index1-1;
  357. s8 = s8.substring(länge8, index8);
  358. int z8 = Integer.parseInt(s8.toString());
  359.  
  360. //zahl9
  361. String s9 = String.valueOf(zahl9);
  362. int index9 = s9.length();
  363. int länge9 = index1-1;
  364. s9 = s9.substring(länge9, index9);
  365. int z9 = Integer.parseInt(s9.toString());
  366.  
  367. //zahl11
  368. String s11 = String.valueOf(zahl11);
  369. int index11 = s11.length();
  370. int länge11 = index1-1;
  371. s11 = s11.substring(länge11, index11);
  372. int z11 = Integer.parseInt(s11.toString());
  373.  
  374. //zahl12
  375. String s12 = String.valueOf(zahl12);
  376. int index12 = s12.length();
  377. int länge12 = index1-1;
  378. s12 = s12.substring(länge12, index12);
  379. int z12 = Integer.parseInt(s12.toString());
  380.  
  381. //zahl13
  382. String s13 = String.valueOf(zahl13);
  383. int index13 = s13.length();
  384. int länge13 = index1-1;
  385. s13 = s13.substring(länge13, index13);
  386. int z13 = Integer.parseInt(s13.toString());
  387.  
  388. //zahl14
  389. String s14 = String.valueOf(zahl14);
  390. int index14 = s14.length();
  391. int länge14 = index1-1;
  392. s14 = s14.substring(länge14, index14);
  393. int z14 = Integer.parseInt(s14.toString());
  394.  
  395. //zahl15
  396. String s15 = String.valueOf(zahl15);
  397. int index15 = s15.length();
  398. int länge15 = index1-1;
  399. s15 = s15.substring(länge15, index15);
  400. int z15 = Integer.parseInt(s15.toString());
  401.  
  402. //zahl16
  403. String s16 = String.valueOf(zahl16);
  404. int index16 = s16.length();
  405. int länge16 = index1-1;
  406. s16 = s16.substring(länge16, index16);
  407. int z16 = Integer.parseInt(s16.toString());
  408.  
  409. //zahl18
  410. String s18 = String.valueOf(zahl18);
  411. int index18 = s18.length();
  412. int länge18 = index1-1;
  413. s18 = s18.substring(länge18, index18);
  414. int z18 = Integer.parseInt(s18.toString());
  415.  
  416. //zahl19
  417. String s19 = String.valueOf(zahl19);
  418. int index19 = s19.length();
  419. int länge19 = index1-1;
  420. s19 = s19.substring(länge19, index19);
  421. int z19 = Integer.parseInt(s19.toString());
  422.  
  423. //zahl20
  424. String s20 = String.valueOf(zahl20);
  425. int index20 = s20.length();
  426. int länge20 = index1-1;
  427. s20 = s20.substring(länge20, index20);
  428. int z20 = Integer.parseInt(s20.toString());
  429.  
  430. //zahl21
  431. String s21 = String.valueOf(zahl21);
  432. int index21 = s21.length();
  433. int länge21 = index1-1;
  434. s21 = s21.substring(länge21, index21);
  435. int z21 = Integer.parseInt(s21.toString());
  436.  
  437. //zahl22
  438. String s22 = String.valueOf(zahl22);
  439. int index22 = s22.length();
  440. int länge22 = index1-1;
  441. s22 = s22.substring(länge22, index22);
  442. int z22 = Integer.parseInt(s22.toString());
  443.  
  444. //zahl23
  445. String s23 = String.valueOf(zahl23);
  446. int index23 = s23.length();
  447. int länge23 = index1-1;
  448. s23 = s23.substring(länge23, index23);
  449. int z23 = Integer.parseInt(s23.toString());
  450.  
  451.  
  452.  
  453. //Prüfziffer1(zahl10)
  454. int pruef1;
  455. pruef1 = z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9;
  456. String p1 = String.valueOf(pruef1);
  457. int indexp1 = p1.length();
  458. int längep1 = index1-1;
  459. p1 = p1.substring(längep1, indexp1);
  460. int pu1 = Integer.parseInt(p1.toString());
  461.  
  462. //Prüfziffer2 (zahl17)
  463. int pruef2;
  464. pruef2 = z11 + z12 + z13 + z14 + z15 + z16;
  465. String p2 = String.valueOf(pruef2);
  466. int indexp2 = p2.length();
  467. int längep2 = index1-1;
  468. p2 = p2.substring(längep2, indexp2);
  469. int pu2 = Integer.parseInt(p2.toString());
  470.  
  471. //Prüfziffer3 (zahl124)
  472. int pruef3;
  473. pruef3 = z18 + z19 + z20 + z21 + z22 + z23;
  474. String p3 = String.valueOf(pruef3);
  475. int indexp3 = p3.length();
  476. int längep3 = index1-1;
  477. p3 = p3.substring(längep3, indexp3);
  478. int pu3 = Integer.parseInt(p3.toString());
  479.  
  480. //Prüfziffer4 (zahl25)
  481. int pruef4;
  482. pruef4 = pruef1 + pruef2 + pruef3 + pu1 * 7 + pu2 * 3 + pu3 * 1;
  483. String p4 = String.valueOf(pruef4);
  484. int indexp4 = p4.length();
  485. int längep4 = index1-1;
  486. p4 = p4.substring(längep4, indexp4);
  487. int pu4 = Integer.parseInt(p4.toString());
  488.  
  489. System.out.println("5");
  490.  
  491. if(zahl10 == pu1 && zahl17 == pu2 && zahl24 == pu3 && zahl25 == pu4){
  492. System.out.println("Right");
  493.  
  494.  
  495. }
  496. else{
  497. System.out.println("false");
  498.  
  499. }
  500.  
  501. }
  502.  
  503.  
  504. // Ende Methoden
  505.  
  506. public static void main(String[] args) {
  507. new personalausweis("IDC - Identification Check");
  508.  
  509.  
  510.  
  511. }
  512. }



Vielen Dank schon einmal ;)


Java Programm für Prüfzahl Berechnung eines Persnalausweises bzw. Prüfung auf Richtigkeit

0 commentaires:

Enregistrer un commentaire