Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Edlinger;
- import javax.swing.*;
- import javax.swing.text.Document;
- import java.awt.*;
- import Edlinger.Controller;
- /**
- * View Klasse mit JPanel
- * @author Florian Edlinger
- * @version 2018-05-26
- */
- public class ViewPanel extends JPanel{
- private Controller control;
- private JTextField[] felder;
- private JButton check,neu,loesung;
- private JLabel text;
- private JPanel d;
- private Kreis kreis;
- /**
- * Konstruktor
- */
- public ViewPanel(Controller control) {
- this.setLayout(new BorderLayout());
- JPanel a = new JPanel(new GridLayout(1,5));
- felder = new JTextField[5];
- for(int i = 0; i<felder.length;i++) {
- felder[i] = new JTextField();
- }
- for(int i = 0; i<felder.length;i++) {
- a.add(felder[i]);
- }
- this.add(a,BorderLayout.PAGE_START);
- JPanel b = new JPanel();
- BoxLayout h = new BoxLayout(b, BoxLayout.PAGE_AXIS);
- b.setLayout(h);
- check = new JButton("Check");
- check.setAlignmentX(CENTER_ALIGNMENT);
- neu = new JButton("Neu");
- neu.setAlignmentX(CENTER_ALIGNMENT);
- loesung = new JButton("Lösung");
- loesung.setAlignmentX(CENTER_ALIGNMENT);
- b.add(check);
- b.add(neu);
- b.add(loesung);
- this.add(b,BorderLayout.LINE_END);
- text.setText("Versuche es 5 Zahlen von 0-9 zu erraten");
- this.add(text,BorderLayout.PAGE_END);
- kreis = new Kreis(0);
- this.add(kreis, BorderLayout.CENTER);
- // this.d = new JPanel();
- // this.add(d, BorderLayout.CENTER);
- //
- neu.addActionListener(control);
- check.addActionListener(control);
- loesung.addActionListener(control);
- neu.setActionCommand("Neu");
- check.setActionCommand("Check");
- loesung.setActionCommand("Lösung");
- for(int i =0;i<felder.length;i++) {
- felder[i].addActionListener(control);
- felder[i].setActionCommand("Feld"+i);
- }
- // Document[] doku = new Document[5];
- // for(int i = 0;i<felder.length;i++) {
- // doku[i] = felder[i].getDocument();
- // doku[i].addDocumentListener(control);
- // }
- }
- /**
- * @return the d
- */
- public JPanel getD() {
- return d;
- }
- /**
- * @param d the d to set
- */
- public void setD(JPanel d) {
- this.d = d;
- }
- /**
- * @return the control
- */
- public Controller getControl() {
- return control;
- }
- /**
- * @param control the control to set
- */
- public void setControl(Controller control) {
- this.control = control;
- }
- /**
- * @return the felder
- */
- public JTextField[] getFelder() {
- return felder;
- }
- /**
- * @param felder the felder to set
- */
- public void setFelder(JTextField[] felder) {
- this.felder = felder;
- }
- /**
- * @return the check
- */
- public JButton getCheck() {
- return check;
- }
- /**
- * @param check the check to set
- */
- public void setCheck(JButton check) {
- this.check = check;
- }
- public int[] getTextfelder() {
- int[] b = new int[5];
- try {
- for(int i = 0;i<this.felder.length;i++) {
- b[i] = Integer.parseInt(felder[i].getText());
- }
- }catch(NumberFormatException n) {
- System.out.println("Nur Zahlen");
- return new int[] {-1,-1,-1,-1,-1,};
- }
- return b;
- }
- public void reset() {
- text.setText("Versuche es 5 Zahlen von 0-9 zu erraten");
- for(int i = 0;i<felder.length;i++) {
- felder[i].setText("");
- }
- }
- /**
- * @return the neu
- */
- public JButton getNeu() {
- return neu;
- }
- /**
- * @param neu the neu to set
- */
- public void setNeu(JButton neu) {
- this.neu = neu;
- }
- /**
- * @return the loesung
- */
- public JButton getLoesung() {
- return loesung;
- }
- /**
- * @param loesung the loesung to set
- */
- public void setLoesung(JButton loesung) {
- this.loesung = loesung;
- }
- /**
- * @return the text
- */
- public JLabel getText() {
- return text;
- }
- /**
- * @param text the text to set
- */
- public void setLabelText(String text) {
- this.text.setText(text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement