I want to code a little tool that simulates a deterministic, finite automaton (like JFLAP) for myself.
My JFrame is just blank. How can I let the user place buttons on left click? And how do I assign the right values to that button (like which function to call when pressed).
I know I can place a button with
JButton button = new JButton("Press me");
frame.add(button);
But I don't know how I could dynamically code that.
Any help is welcome. Also if you think it's stupid to solve my problem with buttons, I'd like to hear suggestions for improvement.
The following code will add a
JButtonto a "blank"JFrameevery time the mouse is clicked inside theJFrame. TheJButtonwill be placed where the mouse click occurred. TheJButtontext will be a number. EachJButtonwill display a different number.