Advertisement
Guest User

Klick COunter

a guest
Apr 11th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. package de.filoofox.main;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6.  
  7. public class Main extends JFrame {
  8.  
  9. private JTextField txtfieldClicktext = new JTextField();
  10. private JLabel how_to_close = new JLabel();
  11. private JLabel how_to_close2 = new JLabel();
  12. private JLabel button_will_disappear = new JLabel();
  13. private JLabel clickstatus = new JLabel();
  14. private JLabel InsgesamtText = new JLabel();
  15. private JLabel showmenuText = new JLabel();
  16. private JLabel showclicksleft = new JLabel();
  17. private JLabel uebrigeclicks = new JLabel();
  18. private JLabel geklickt = new JLabel();
  19. private JLabel schongeklickt = new JLabel();
  20. private JButton Reset = new JButton();
  21. private JButton Rename = new JButton();
  22. private JButton closewindow = new JButton();
  23. private JButton b_howtoclose = new JButton();
  24. private JButton CLICK = new JButton();
  25. private JButton geklicktswitch = new JButton();
  26. private JToggleButton Insgesamt = new JToggleButton();
  27. private JToggleButton showmenu = new JToggleButton();
  28. private JToggleButton uebrig = new JToggleButton();
  29.  
  30. boolean geklicktbool;
  31. boolean uebrigshown;
  32. boolean menu;
  33. boolean clickgesamt;
  34. int CloseOffset = 250;
  35. int ButtonMenuOffset = 30;
  36. int clicks;
  37. int clicks_left;
  38.  
  39. public Main() {
  40. super();
  41. geklicktbool = true;
  42. uebrigshown = true;
  43. menu = true;
  44. clickgesamt = true;
  45. setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  46.  
  47. int frameWidth = 1081;
  48. int frameHeight = 737;
  49. setSize(frameWidth, frameHeight);
  50. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  51. int x = (d.width - getSize().width) / 2;
  52. int y = (d.height - getSize().height) / 2;
  53. setLocation(x, y);
  54. setTitle("Viel Spaß");
  55. setResizable(true);
  56. Container cp = getContentPane();
  57. cp.setLayout(null);
  58. clicks = 0;
  59. clicks_left = 100000;
  60. menu = true;
  61.  
  62.  
  63. //text
  64. how_to_close.setText("Um dieses Fenster zu schließen, musst du den TaskManager öffnen!");
  65. how_to_close2.setText("Dies ist dazu da, dass du nicht ausversehen das Fenster schließt!");
  66. button_will_disappear.setText("Wenn du diesen Knopf drückst wird diese info und der knopf entfernt!");
  67. showmenuText.setText("Show-Menu:");
  68. CLICK.setText("Click!");
  69. InsgesamtText.setText("Insgesamt:");
  70. showclicksleft.setText("Übrig:");
  71. uebrigeclicks.setText("Du musst noch " + clicks_left + " mal Klicken!");
  72. clickstatus.setText(clicks + " || " + clicks_left);
  73. geklickt.setText("Geklickt:");
  74. schongeklickt.setText("Du hast schon " + clicks + " mal geklickt!");
  75. clickstatus.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 40));
  76. InsgesamtText.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 12));
  77. showmenuText.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 18));
  78. button_will_disappear.setFont(new Font("@Adobe Gothic Std B", Font.PLAIN, 10));
  79. CLICK.setFont(new Font("@Adobe Gothic Std B", Font.BOLD + Font.ITALIC, 60));
  80. InsgesamtText.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 20));
  81. showclicksleft.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 20));
  82. uebrigeclicks.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 30));
  83. geklickt.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 20));
  84. schongeklickt.setFont(new Font("@Adobe Gothic Std B", Font.BOLD, 40));
  85. how_to_close.setBounds(385 +CloseOffset, -135, 700, 300);
  86. how_to_close2.setBounds(402 +CloseOffset, -120, 700, 300);
  87. clickstatus.setBounds(420, 614, 414, 79);
  88. button_will_disappear.setBounds(390 +CloseOffset,-70,700,300);
  89. InsgesamtText.setBounds(1, 46, 110, 39);
  90. showmenuText.setBounds(1, -2, 110, 39);
  91. showclicksleft.setBounds(1, 94, 110, 39);
  92. uebrigeclicks.setBounds(290, 536, 7000, 79);
  93. geklickt.setBounds(1, 140, 110, 39);
  94. schongeklickt.setBounds(270, 456, 700, 79);
  95.  
  96. cp.add(schongeklickt);
  97. cp.add(how_to_close);
  98. cp.add(how_to_close2);
  99. cp.add(button_will_disappear);
  100. cp.add(CLICK);
  101. cp.add(clickstatus);
  102. cp.add(showmenuText);
  103. cp.add(InsgesamtText);
  104. cp.add(showclicksleft);
  105. cp.add(uebrigeclicks);
  106. cp.add(geklickt);
  107.  
  108. //ende text
  109.  
  110. //textfields
  111. txtfieldClicktext.setText("Ändere den Text von dem Click-Button!");
  112. txtfieldClicktext.setBounds(2, 650, 220, 20);
  113. cp.add(txtfieldClicktext);
  114. //ende textfields
  115.  
  116. //buttons
  117. b_howtoclose.setText("VERSTANDEN!");
  118. Rename.setText("Rename");
  119. Reset.setText("Reset");
  120. Insgesamt.setText("ON");
  121. showmenu.setText("ON");
  122. uebrig.setText("ON");
  123. geklicktswitch.setText("ON");
  124. b_howtoclose.setBounds(490 +CloseOffset,40,120,30);
  125. closewindow.setBounds(1034,0,30,30);
  126. Rename.setBounds(3, 671, 105, 25);
  127. Reset.setBounds(116, 671, 105, 25);
  128. CLICK.setBounds(326 , 211, 411, 209);
  129. uebrig.setBounds(111+ButtonMenuOffset, 100, 55, 33);
  130. Insgesamt.setBounds(111 +ButtonMenuOffset, 50, 57, 33);
  131. showmenu.setBounds(110 +ButtonMenuOffset, 2, 55, 33);
  132. geklicktswitch.setBounds(111+ButtonMenuOffset, 150, 55, 33);
  133. cp.add(b_howtoclose);
  134. cp.add(Rename);
  135. cp.add(Reset);
  136. cp.add(CLICK);
  137. cp.add(Insgesamt);
  138. cp.add(showmenu);
  139. cp.add(uebrig);
  140. cp.add(geklicktswitch);
  141.  
  142.  
  143. b_howtoclose.addActionListener(new ActionListener() {
  144. @Override
  145. public void actionPerformed(ActionEvent e) {
  146. how_to_close.setBounds(0,0,0,0);
  147. how_to_close2.setBounds(0,0,0,0);
  148. button_will_disappear.setBounds(0,0,0,0);
  149. b_howtoclose.setBounds(0,0,0,0);
  150. cp.add(closewindow);
  151. }
  152. });
  153. //ende how to close button
  154.  
  155. //Close button
  156. closewindow.addActionListener(new ActionListener() {
  157. @Override
  158. public void actionPerformed(ActionEvent e) {
  159. System.exit(0);
  160. }
  161. });
  162. //ende Close button
  163.  
  164. //rename ClickButton
  165. Rename.addActionListener(new ActionListener() {
  166. @Override
  167. public void actionPerformed(ActionEvent e) {
  168. CLICK.setText(txtfieldClicktext.getText());
  169. }
  170. });
  171. // ende rename ClickButton
  172.  
  173. //ResetName
  174. Reset.addActionListener(new ActionListener() {
  175. @Override
  176. public void actionPerformed(ActionEvent e) {
  177. CLICK.setText("Click! ");
  178. }
  179. });
  180.  
  181. //ende ResetName
  182.  
  183. //Click
  184. CLICK.addActionListener(new ActionListener() {
  185. @Override
  186. public void actionPerformed(ActionEvent e) {
  187. clicks_left = clicks_left - 1;
  188. clicks = clicks +1;
  189. clickstatus.setText(clicks + " || " + clicks_left);
  190. uebrigeclicks.setText("Du musst noch " + clicks_left + " mal Klicken!");
  191. schongeklickt.setText("Du hast schon " + clicks + " mal geklickt!");
  192. }
  193. });
  194. //ende Click
  195.  
  196. //toggle Insgesamt
  197. Insgesamt.addActionListener(new ActionListener() {
  198. @Override
  199. public void actionPerformed(ActionEvent e) {
  200. if (clickgesamt == true) {
  201. clickgesamt = false;
  202. Insgesamt.setText("OFF");
  203. Insgesamt.setForeground(Color.RED);
  204. clickstatus.setBounds(0,0,0,0);
  205. } else if (clickgesamt == false) {
  206. clickgesamt = true;
  207. Insgesamt.setText("ON");
  208. Insgesamt.setForeground(Color.GREEN);
  209. clickstatus.setBounds(320, 614, 414, 79);
  210. }
  211. }});
  212. //ende toggle Insgesamt
  213.  
  214. //show menu
  215. showmenu.addActionListener(new ActionListener() {
  216. @Override
  217. public void actionPerformed(ActionEvent e) {
  218. if (menu == true) {
  219. menu = false;
  220. showmenu.setText("OFF");
  221. showmenu.setForeground(Color.RED);
  222. } else if (clickgesamt == false) {
  223. menu = true;
  224. showmenu.setText("ON");
  225. showmenu.setForeground(Color.GREEN);
  226. }
  227. }
  228. });
  229. //ende show menu
  230.  
  231. //übrig
  232.  
  233. uebrig.addActionListener(new ActionListener() {
  234. @Override
  235. public void actionPerformed(ActionEvent e) {
  236. if (uebrigshown == true) {
  237. uebrigshown = false;
  238. uebrig.setText("OFF");
  239. uebrig.setForeground(Color.RED);
  240. uebrigeclicks.setBounds(0,0,0,0);
  241. } else if (uebrigshown == false) {
  242. uebrigshown = true;
  243. uebrig.setText("ON");
  244. uebrig.setForeground(Color.GREEN);
  245.  
  246. }
  247. }
  248. });
  249.  
  250. //ende übrig
  251.  
  252. //geklickt
  253.  
  254. geklicktswitch.addActionListener(new ActionListener() {
  255. @Override
  256. public void actionPerformed(ActionEvent e) {
  257. if (geklicktbool == true) {
  258. geklicktbool = false;
  259. geklicktswitch.setText("OFF");
  260. geklicktswitch.setForeground(Color.RED);
  261. schongeklickt.setBounds(0,0,0,0);
  262. } else if (geklicktbool == false) {
  263. geklicktbool = true;
  264. geklicktswitch.setText("ON");
  265. geklicktswitch.setForeground(Color.GREEN);
  266. schongeklickt.setBounds(270, 456, 700, 79);
  267.  
  268. }
  269. }
  270. });
  271.  
  272. //ende geklickt
  273.  
  274.  
  275. setVisible(true);
  276. } // end of public rvd
  277.  
  278. // Anfang Methoden
  279.  
  280. public static void main(String[] args) {
  281. new Main();
  282. } // end of main
  283.  
  284.  
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement