Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Moving from SymAction in Java.awt to something in JavaFX

 
Jim Anderson
Greenhorn
Posts: 15
Eclipse IDE Java Notepad
  • Mark post as helpful
  • send pies
  • 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){
......}
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but does JavaFX provide substitution for java.awt.Action class?

It seems that not.
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • 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 Java Notepad
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic