Loading...
Logo
Processing Forum
Filip Zymek's Profile
1 Posts
2 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hello all :)

    I am trying to run my program (simple Cellular automata) under Eclipse environment using Processing 2.x.

    Everything works fine, but i cannot capture any keyXXX event or mouseXXX event after staring my app. The same code plced in Processing pde editor runs corractly and captures and handles key events properly.

    Has anyone of you spotted simmilar problem?

    Here my code for starint PApplet sketch:

    1. public class Main {

    2. private static final String DEFAULT_SIZE = "20";

    3. public static void main(String[] args) {
    4. if (args.length != 1) {
    5. PApplet.main(new String[] { CellularAutomataEngine.class.getName(),
    6. DEFAULT_SIZE, "--present" });
    7. } else {
    8. try {
    9. int size = Integer.parseInt(args[0]);
    10. if (size < 10 || size > 20) {
    11. throw new NumberFormatException();
    12. }
    13. } catch (NumberFormatException e) {
    14. System.err
    15. .println("argument should be integer in range[10, 20]");
    16. return;
    17. }
    18. PApplet.main(CellularAutomataEngine.class.getName(), new String[] {
    19. args[0], "--present" });
    20. }
    21. }
    22. }
    And heres part of my Applet code with keyReleased method:

    1. public class CellularAutomataEngine extends PApplet {

    2. private static final long serialVersionUID = 1L;
    3. private CellSpace world = null;

    4. public CellularAutomataEngine() {
    5. }

    6. @Override
    7. public void setup() {
    8. super.setup();
    9. size(300, 300);
    10. frameRate(10.0f);
    11. System.out.println("Setup args: " + Arrays.toString(args));
    12. System.out.println("Setup args[0]: " + args[0]);
    13. world = new CellSpace(this, Integer.parseInt(args[0]));
    14. world.randomize();
    15. }

    16. @Override
    17. public void draw() {
    18. super.draw();
    19. update(0);
    20. draw(0);
    21. }

    22.         @Override
    23. public void keyPressed() {
    24. super.keyPressed();
    25. System.out.println("KeyPressed: '" + key + "'");
    26. }

    27. @Override
    28. public void keyReleased(KeyEvent event) {
    29. super.keyReleased(event);
    30. System.out.println("KeyReleasedEvent: '" + event + "'");
    31. }

    32.         @Override
    33. public void keyReleased() {
    34. super.keyReleased();
    35. System.out.println("KeyReleased: '" + key + "'");
    36. if (key == ' ' || key == 'r') {
    37. reset();
    38. }
    39. }
    40.  /* rest o code */
    41. }
    The problem is that none of those keyXXX methods are triggered when keyboard is pressed ;(