Advertisement
Guest User

Untitled

a guest
May 27th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. package Edlinger;
  2. import javax.swing.*;
  3. import javax.swing.text.Document;
  4.  
  5. import java.awt.*;
  6. import Edlinger.Controller;
  7. /**
  8. * View Klasse mit JPanel
  9. * @author Florian Edlinger
  10. * @version 2018-05-26
  11. */
  12. public class ViewPanel extends JPanel{
  13. private Controller control;
  14. private JTextField[] felder;
  15. private JButton check,neu,loesung;
  16. private JLabel text;
  17. private JPanel d;
  18. private Kreis kreis;
  19. /**
  20. * Konstruktor
  21. */
  22. public ViewPanel(Controller control) {
  23. this.setLayout(new BorderLayout());
  24. JPanel a = new JPanel(new GridLayout(1,5));
  25. felder = new JTextField[5];
  26. for(int i = 0; i<felder.length;i++) {
  27. felder[i] = new JTextField();
  28. }
  29. for(int i = 0; i<felder.length;i++) {
  30. a.add(felder[i]);
  31. }
  32. this.add(a,BorderLayout.PAGE_START);
  33. JPanel b = new JPanel();
  34. BoxLayout h = new BoxLayout(b, BoxLayout.PAGE_AXIS);
  35. b.setLayout(h);
  36. check = new JButton("Check");
  37. check.setAlignmentX(CENTER_ALIGNMENT);
  38. neu = new JButton("Neu");
  39. neu.setAlignmentX(CENTER_ALIGNMENT);
  40. loesung = new JButton("Lösung");
  41. loesung.setAlignmentX(CENTER_ALIGNMENT);
  42. b.add(check);
  43. b.add(neu);
  44. b.add(loesung);
  45. this.add(b,BorderLayout.LINE_END);
  46.  
  47. text.setText("Versuche es 5 Zahlen von 0-9 zu erraten");
  48. this.add(text,BorderLayout.PAGE_END);
  49.  
  50. kreis = new Kreis(0);
  51. this.add(kreis, BorderLayout.CENTER);
  52. // this.d = new JPanel();
  53. // this.add(d, BorderLayout.CENTER);
  54. //
  55. neu.addActionListener(control);
  56. check.addActionListener(control);
  57. loesung.addActionListener(control);
  58.  
  59. neu.setActionCommand("Neu");
  60. check.setActionCommand("Check");
  61. loesung.setActionCommand("Lösung");
  62.  
  63. for(int i =0;i<felder.length;i++) {
  64. felder[i].addActionListener(control);
  65. felder[i].setActionCommand("Feld"+i);
  66. }
  67. // Document[] doku = new Document[5];
  68. // for(int i = 0;i<felder.length;i++) {
  69. // doku[i] = felder[i].getDocument();
  70. // doku[i].addDocumentListener(control);
  71. // }
  72.  
  73. }
  74. /**
  75. * @return the d
  76. */
  77. public JPanel getD() {
  78. return d;
  79. }
  80. /**
  81. * @param d the d to set
  82. */
  83. public void setD(JPanel d) {
  84. this.d = d;
  85. }
  86. /**
  87. * @return the control
  88. */
  89. public Controller getControl() {
  90. return control;
  91. }
  92. /**
  93. * @param control the control to set
  94. */
  95. public void setControl(Controller control) {
  96. this.control = control;
  97. }
  98. /**
  99. * @return the felder
  100. */
  101. public JTextField[] getFelder() {
  102. return felder;
  103. }
  104. /**
  105. * @param felder the felder to set
  106. */
  107. public void setFelder(JTextField[] felder) {
  108. this.felder = felder;
  109. }
  110. /**
  111. * @return the check
  112. */
  113. public JButton getCheck() {
  114. return check;
  115. }
  116. /**
  117. * @param check the check to set
  118. */
  119. public void setCheck(JButton check) {
  120. this.check = check;
  121. }
  122. public int[] getTextfelder() {
  123. int[] b = new int[5];
  124. try {
  125. for(int i = 0;i<this.felder.length;i++) {
  126. b[i] = Integer.parseInt(felder[i].getText());
  127. }
  128. }catch(NumberFormatException n) {
  129. System.out.println("Nur Zahlen");
  130. return new int[] {-1,-1,-1,-1,-1,};
  131. }
  132. return b;
  133. }
  134. public void reset() {
  135. text.setText("Versuche es 5 Zahlen von 0-9 zu erraten");
  136. for(int i = 0;i<felder.length;i++) {
  137. felder[i].setText("");
  138. }
  139. }
  140. /**
  141. * @return the neu
  142. */
  143. public JButton getNeu() {
  144. return neu;
  145. }
  146. /**
  147. * @param neu the neu to set
  148. */
  149. public void setNeu(JButton neu) {
  150. this.neu = neu;
  151. }
  152. /**
  153. * @return the loesung
  154. */
  155. public JButton getLoesung() {
  156. return loesung;
  157. }
  158. /**
  159. * @param loesung the loesung to set
  160. */
  161. public void setLoesung(JButton loesung) {
  162. this.loesung = loesung;
  163. }
  164. /**
  165. * @return the text
  166. */
  167. public JLabel getText() {
  168. return text;
  169. }
  170. /**
  171. * @param text the text to set
  172. */
  173. public void setLabelText(String text) {
  174. this.text.setText(text);
  175. }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement