aspose file tools*
The moose likes JavaFX and the fly likes Moving from SymAction in Java.awt to something in JavaFX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Moving from SymAction in Java.awt to something in JavaFX" Watch "Moving from SymAction in Java.awt to something in JavaFX" New topic
Author

Moving from SymAction in Java.awt to something in JavaFX

Jim Anderson
Greenhorn

Joined: Apr 19, 2013
Posts: 15

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){
......}
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1083
    
  10

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


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Yes, but does JavaFX provide substitution for java.awt.Action class?

It seems that not.


True person is moral, false is right!
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 144
    
    9
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

Joined: Apr 19, 2013
Posts: 15

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Moving from SymAction in Java.awt to something in JavaFX