• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Moving from SymAction in Java.awt to something in JavaFX

 
Greenhorn
Posts: 15
Eclipse IDE Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I convert "Java.awt" code that uses SymAction into JavaFX format?

After I define three Buttons, here's my working "Java.awt" code:

SymAction lSymAction = new SymAction();
IterationButton.addActionListener(lSymAction);
OneIterButton.addActionListener(lSymAction);
SaveImageButton.addActionListener(lSymAction);
}
............

class SymAction implements java.awt.event.ActionListener{
public void actionPerformed(java.awt.event.ActionEvent event){
Object object = event.getSource();
if (object == IterationButton){
IterationButton_ActionPerformed(event);}
if (object == OneIterButton){
OneIterButton_ActionPerformed(event);}
else if (object == SaveImageButton){
SaveImageButton_ActionPerformed(event);}
}
}
................

void OneIterButton_ActionPerformed(java.awt.event.ActionEvent event){
......}

void IterationButton_ActionPerformed(java.awt.event.ActionEvent event){
......}

void SaveImageButton_ActionPerformed(java.awt.event.ActionEvent event){
......}
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim,
JavaFX has a Button control that you can use to build buttons and add listeners to it. Do click on the link to know more.

To know more about building a JavaFX application, you can start here
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but does JavaFX provide substitution for java.awt.Action class?

It seems that not.
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On RT-30749 Overload Button type constructors to allow an ActionEvent to be set on the button a developer offered the following comment in relation to java.awt.Action style functionality in JavaFX.

Whilst a good idea, I would like to hold off on this feature until we think through add an Action API into JavaFX. At that point it may be that ActionEvent shouldn't be passed into the constructor, but Action objects (which include not just the event handler but all the appropriate state (text, tooltip, graphic, selected, etc).


So it would appear that the JavaFX developers have considered adding such functionality to JavaFX, but it is not present for Java 8 (which is the target version for which the above comment was made). The functionality is also not directly present in any 3rd party libraries that I am aware of. If you want to use such functionality in your application, you will need to implement it yourself.
 
Jim Anderson
Greenhorn
Posts: 15
Eclipse IDE Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar: Thanks for your comment. I was aware of the article by Alla Redko. She suggests that the "add Button method" can be used to add a large # of buttons & associated actions. In practice, I find that only two or fewer buttons can be used. If one tries to add (say) five buttons, the buttons look ok, but the associated actions get fouled up. This led to my "SymAction" question. As others have noted, there's no analog of the awt.ActionEvent protocol in javafx.

I think that one should be working with the "ToggleButton" function, letting each "toggle" produce a specific action. Any thoughts?

Jim Anderson
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic