Hi there,
I wonder whether anyone can point me in the right direction...
I need to find out how I can make all my JMenuItem's have a similar sort of action. I want to click on any one of them and get them to all pass their own name as a
string and do other similar stuff detailed in a ActionListener class. For more details, please see below.
I'm just mucking about trying to learn the basics of swing and linking up to databases with
JDBC. I can enter a name of a new column for my database table into a JTextField of my GUI, press a button and I connect up to the database and add a column to it. After that (part of the same actionPerformed method) a method called getColumnHeadings() is called which I shall show below:
SQLCommand is a class that I've made with a few useful methods to interact with my database. The getColumnNameArrayList() method queries the database and eventually returns an ArrayList<String> with the column headings in. As you can see this ArrayList is then used to create / refresh my JMenuItems in my 'fileMenu' JMenu.
This is all well and good, but when I click on one of the JMenuItems in my menu, how do I let my action listener know where in the ArrayList this MenuItems name string is held? Thats all I need I think, I need to click on the MenuItem and get it to pass its own name string to the ActionListener or something (so that I can set which database table column will be added to.
Thanks for reading all the above waffle! Hope you can help.
Cheers
Joe Lemmer