0

So Im trying to make a code generator for something and i am using java swing and a combo box. So I want it for when you pick one of the choices it changes the variable. When I use an if else statement it only does it once. TL;DR How do i make like a when statement so when effect = "Sphere" it will set e to "Sphere" but in the dropdown if I select Helix it will change e to "Helix" etc.

EricZeBaws 2
  • 11
  • 1
  • 2
  • This is what event-driven programming is all about -- you listen to changes in state, here the state of the JComboBox selection, perhaps with an ActionListener. Otherwise your question is kind of vague and broad and could use improvement including relevant [mcve] code. – Hovercraft Full Of Eels Jul 10 '17 at 23:46
  • You can also listen for changes to a variable/field/property by using some JavaBeans classes (e.g., PropertyChangeListener, PropertyChangeEvent and PropertyChangeSupport) to make the field a "bound" property, and in fact Swing components already have the machinery for this wired into them. But again it would be difficult to give you a more precise answer without more information. – Hovercraft Full Of Eels Jul 10 '17 at 23:47
  • Ah ok thx also thanks to whoever posted the og post – EricZeBaws 2 Jul 11 '17 at 00:31
  • the person who linked the post that was already answered – EricZeBaws 2 Jul 11 '17 at 00:43
  • Ah, that was me. Also, you can find links to the Swing tutorials and to other Swing resources here: [Swing Info](http://stackoverflow.com/tags/swing/info) – Hovercraft Full Of Eels Jul 11 '17 at 00:48

0 Answers0