Example #1
0
  public boolean ertad() {
    int t = -10000;
    try {
      t = Integer.parseInt(tf.getText());
    } catch (Exception e) {
      return false;
    }

    if (t <= 100 && t >= -100) {
      root.setState(t);
      root.getvalue(); // notifyme();
      return true;
    }
    return false;
  }
Example #2
0
  public ObserverPattern(CompositeParent r) {
    root = r;
    window = new JFrame();
    width = 400;
    height = 400;

    if (root != null) {
      window = new JFrame(root.toString());
    } else {
      window = new JFrame();
    }

    // controllwin =  new JFrame("Controll");
    // controllwin.setLayout(new FlowLayout());
    JButton b = new JButton("Értéket ad");
    tf = new JTextField();

    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // controlwindow.removeAll();
            if (!ertad()) {
              tf.setText("Nem megfelelo parameter!!");
            }
          }
        });

    /*controllwin.add(tf);
    controllwin.add(b);
    controllwin.setVisible(true);*/

    window.setLayout(new FlowLayout());
    window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    window.setSize(width, height);
    window.setVisible(true);
  }