Advertisement
Guest User

Untitled

a guest
Jun 18th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.61 KB | None | 0 0
  1. package de[PRIVAT].main;
  2.  
  3. import java.awt.Font;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.ArrayList;
  7. import java.util.InputMismatchException;
  8.  
  9. import javax.swing.ImageIcon;
  10. import javax.swing.JButton;
  11. import javax.swing.JCheckBox;
  12. import javax.swing.JFrame;
  13. import javax.swing.JLabel;
  14. import javax.swing.JOptionPane;
  15. import javax.swing.JPanel;
  16. import javax.swing.JTextField;
  17. import javax.swing.text.AttributeSet;
  18. import javax.swing.text.BadLocationException;
  19. import javax.swing.text.Document;
  20. import javax.swing.text.PlainDocument;
  21.  
  22. @SuppressWarnings("serial")
  23. public class Punkterechner extends JFrame {
  24.  
  25.  
  26.  
  27.  
  28. Font font = new Font("Verdana", Font.BOLD, 15);
  29.  
  30.  
  31.  
  32.  
  33.  
  34. ArrayList<String> liste1 = new ArrayList<String>();
  35.  
  36.  
  37.  
  38.  
  39. static JLabel text1;
  40. static JLabel anzahl1;
  41. static JLabel klasse1;
  42.  
  43. static JLabel text2;
  44. static JLabel anzahl2;
  45. static JLabel klasse2;
  46.  
  47. JPanel panel2 = new JPanel();
  48. JPanel panel3 = new JPanel();
  49.  
  50. ImageIcon img = new ImageIcon("GCG.jpg");
  51.  
  52. JPanel panel = new JPanel();
  53. static JTextField A0;
  54. static JTextField A2;
  55. static JTextField A3;
  56. static JTextField A4;
  57. JCheckBox box1 = new JCheckBox("Klimmzüge");
  58. JCheckBox box2 = new JCheckBox("Standweitsprung");
  59. JCheckBox box3 = new JCheckBox("Beugestütz");
  60. JButton button = new JButton("Auswählen");
  61. static JButton berechnen1 = new JButton("Berechnen");
  62. JButton berechnen2 = new JButton("Berechnen");
  63. JButton berechnen3 = new JButton("Berechnen");
  64.  
  65.  
  66.  
  67. public static void main(String[] args) {
  68.  
  69. Punkterechner pr = new Punkterechner();
  70.  
  71. pr.b1click();
  72. pr.Punkterechner();
  73.  
  74.  
  75.  
  76. JOptionPane.showMessageDialog(null, "[DATENSCHUTZ ENTFERNT]");
  77.  
  78. }
  79.  
  80.  
  81.  
  82. private Document createNumericDocumentWithMaxLength(final int maxLength) {
  83.  
  84.  
  85.  
  86. Document doc = new PlainDocument(){
  87. @Override
  88. public void insertString(int offs, String str, AttributeSet a)
  89. throws BadLocationException {
  90. if(getLength() + str.length() > maxLength)
  91. return;
  92. if(!str.matches("^[\\d]*$"))
  93. return;
  94.  
  95.  
  96. super.insertString(offs, str, a);
  97.  
  98. }
  99. };
  100. return doc;
  101.  
  102. }
  103.  
  104. private Document createNumericDocumentWithMaxLength1(final int maxLength) {
  105.  
  106.  
  107.  
  108. Document doc = new PlainDocument(){
  109. @Override
  110. public void insertString(int offs, String str, AttributeSet a)
  111. throws BadLocationException {
  112. if(getLength() + str.length() > maxLength)
  113. return;
  114. if(!str.matches("^[\\d]*$"))
  115. if(!str.matches("[5-12]+"))
  116. return;
  117.  
  118.  
  119. super.insertString(offs, str, a);
  120.  
  121. }
  122. };
  123. return doc;
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130. public void Punkterechner() {
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. panel.setLayout(null);
  138.  
  139. JFrame f = new JFrame();
  140. f.setIconImage(img.getImage());
  141. f.setVisible(true);
  142. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  143. f.setLocationRelativeTo(null);
  144. f.setTitle("Punkterechner");
  145. f.setBounds(100, 300, 500, 500);
  146.  
  147. text1 = new JLabel("Bitte wählen Sie die Disziplin aus!");
  148. text1.setVisible(true);
  149. text1.setBounds(135, 30, 300, 50);
  150. text1.setFont(new Font("Calabria", Font.BOLD, 16));
  151.  
  152.  
  153.  
  154. button.setBounds(195, 350, 100, 35);
  155.  
  156. box1.setVisible(true);
  157. box1.setBounds(195, 110, 150, 35);
  158.  
  159. box2.setVisible(true);
  160. box2.setBounds(195, 190, 150, 35);
  161.  
  162. box3.setVisible(true);
  163. box3.setBounds(195, 270, 150, 35);
  164.  
  165. button.addActionListener(new ActionListener() {
  166.  
  167. @Override
  168. public void actionPerformed(ActionEvent ae) {
  169.  
  170. if(box1.isSelected()) {
  171. panel2.setLayout(null);
  172. f.setVisible(false);
  173. JFrame f5 = new JFrame();
  174. f5.setVisible(true);
  175. f5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  176. f5.setLocationRelativeTo(null);
  177. f5.setTitle("Klimmzug");
  178. f5.setBounds(100, 300, 500, 500);
  179.  
  180. anzahl1 = new JLabel("Anzahl: ");
  181. anzahl1.setFont(font);
  182.  
  183. anzahl1.setBounds(140, 123, 75, 15);
  184. anzahl1.setVisible(true);
  185.  
  186. JTextField A0 = new JTextField(5);
  187. A0.setBounds(210, 120, 32, 25);
  188. A0.setDocument(createNumericDocumentWithMaxLength(3));
  189.  
  190.  
  191. JTextField A2 = new JTextField();
  192. A2.setDocument(createNumericDocumentWithMaxLength1(2));
  193. A2.setBounds(210, 180, 32, 25);
  194.  
  195. klasse1 = new JLabel("Alter: ");
  196. klasse1.setFont(font);
  197.  
  198. klasse1.setBounds(140, 183, 75, 15);
  199. klasse1.setVisible(true);
  200.  
  201. JLabel t2 = new JLabel("Anzahl:");
  202. //Erg�nzen//
  203.  
  204. JLabel t3 = new JLabel("Alter:");
  205. //Erg�nzen//
  206.  
  207.  
  208. berechnen1.setBounds(160, 280, 115, 35);
  209.  
  210.  
  211.  
  212.  
  213. panel2.add(A0);
  214. panel2.add(A2);
  215. panel2.add(anzahl1);
  216. panel2.add(klasse1);
  217. panel2.add(berechnen1);
  218. f5.add(panel2);
  219.  
  220.  
  221. }else {
  222. if(box2.isSelected()) {
  223. panel2.setLayout(null);
  224. f.setVisible(false);
  225. JFrame f2 = new JFrame();
  226. f2.setVisible(true);
  227. f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  228. f2.setLocationRelativeTo(null);
  229. f2.setTitle("Standweitsprung");
  230. f2.setBounds(100, 300, 500, 500);
  231.  
  232. anzahl2 = new JLabel("Anzahl: ");
  233. anzahl2.setFont(font);
  234.  
  235. anzahl2.setBounds(140, 123, 75, 15);
  236. anzahl2.setVisible(true);
  237.  
  238. JTextField A3 = new JTextField(5);
  239. A3.setBounds(210, 120, 32, 25);
  240. A3.setDocument(createNumericDocumentWithMaxLength(3));
  241.  
  242.  
  243. JTextField A4 = new JTextField();
  244. A4.setDocument(createNumericDocumentWithMaxLength1(2));
  245. A4.setBounds(210, 180, 32, 25);
  246.  
  247. klasse2 = new JLabel("Alter: ");
  248. klasse2.setFont(font);
  249.  
  250. klasse2.setBounds(140, 183, 75, 15);
  251. klasse2.setVisible(true);
  252.  
  253. JLabel t2 = new JLabel("Anzahl:");
  254. //Erg�nzen//
  255.  
  256. JLabel t3 = new JLabel("Klasse:");
  257. //Erg�nzen//
  258.  
  259.  
  260. berechnen2.setBounds(160, 280, 115, 35);
  261. panel3.add(A3);
  262. panel3.add(A4);
  263. panel3.add(anzahl2);
  264. panel3.add(klasse2);
  265. panel3.add(berechnen2);
  266.  
  267. }else {
  268. if(box3.isSelected()) {
  269. f.setVisible(false);
  270. JFrame f4 = new JFrame();
  271. f4.setVisible(true);
  272. f4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  273. f4.setLocationRelativeTo(null);
  274. f4.setTitle("Beugestütz");
  275. f4.setBounds(100, 300, 500, 500);
  276.  
  277. JLabel t2 = new JLabel("Anzahl:");
  278. t2.setBounds(12, 50, 100, 300);
  279. t2.setVisible(true);
  280. JLabel t3 = new JLabel("Alter:");
  281. //Erg�nzen//
  282.  
  283. panel.add(t2);
  284.  
  285. }
  286.  
  287. }
  288. }
  289.  
  290.  
  291.  
  292. }
  293.  
  294.  
  295. });
  296.  
  297. box1.addActionListener(new ActionListener() {
  298.  
  299. @Override
  300. public void actionPerformed(ActionEvent ac) {
  301. // TODO Auto-generated method stub
  302.  
  303. if(box1.isSelected() == true) {
  304. box2.setSelected(false);
  305. box3.setSelected(false);
  306.  
  307. }
  308.  
  309.  
  310. }
  311.  
  312.  
  313.  
  314. });
  315. box2.addActionListener(new ActionListener() {
  316.  
  317. @Override
  318. public void actionPerformed(ActionEvent ac) {
  319. // TODO Auto-generated method stub
  320.  
  321. if(box2.isSelected() == true) {
  322. box1.setSelected(false);
  323. box3.setSelected(false);
  324.  
  325. }
  326.  
  327.  
  328.  
  329. }
  330.  
  331.  
  332.  
  333. });
  334. box3.addActionListener(new ActionListener() {
  335.  
  336. @Override
  337. public void actionPerformed(ActionEvent ac) {
  338. // TODO Auto-generated method stub
  339.  
  340. if(box3.isSelected() == true) {
  341. box1.setSelected(false);
  342. box2.setSelected(false);
  343. }
  344.  
  345.  
  346.  
  347. }
  348.  
  349.  
  350.  
  351. });
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361. panel.add(button);
  362. panel.add(box1);
  363. panel.add(box2);
  364. panel.add(box3);
  365. panel.add(text1);
  366. f.add(panel);
  367.  
  368. }
  369.  
  370. public void b1click() {
  371. berechnen1.addActionListener(new ActionListener() {
  372.  
  373.  
  374.  
  375. @Override
  376. public void actionPerformed(ActionEvent a) {
  377. // TODO Auto-generated method stub
  378.  
  379. int parse = Integer.parseInt(A0.getText());
  380.  
  381.  
  382. if(parse >= 14) {
  383. JOptionPane.showMessageDialog(null, "It works!");
  384.  
  385. } else {
  386. JOptionPane.showMessageDialog(null, "Bitte benutzen Sie den Punkterechner für unter 14 Jährige!");
  387. }
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396. }
  397.  
  398. });
  399.  
  400.  
  401. }
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement