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
JButton
to a "blank"JFrame
every time the mouse is clicked inside theJFrame
. TheJButton
will be placed where the mouse click occurred. TheJButton
text will be a number. EachJButton
will display a different number.