javafx Anonymous Application class -


i'm used swing , exploring javafx. in swing i'd create class extends jpanel , able test class couple of lines of code in class created jframe.

so in javafx thought extend scene or group, , able create anonymous application class in main fails with:

exception in thread "main" java.lang.runtimeexception: error: class test.test not subclass of javafx.application.application @ javafx.application.application.launch(application.java:211) @ test.test.main(test.java:59)

i don't want subclass application want follow pattern lots of scenes/groups , there can 1 application object.

when didn't work, thought write simple class extends application , based on args provided, use reflection create scene doesn't work either since there no default constructor scene... group has default constuctor, maybe need subclass instead of scene?

there must way this... has been java 101 way test , individual class. has ever done this? thoughts or ideas on how accomplish i'm trying here?

java version "1.7.0_21"
java(tm) se runtime environment (build 1.7.0_21-b11)
java hotspot(tm) 64-bit server vm (build 23.21-b01, mixed mode)

here code:

package test;  import javafx.application.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.scene.input.*; import javafx.scene.effect.*;  public class test extends javafx.scene.scene {    public test( javafx.scene.group group, int width, int height )    {       super( group, width, height );       gridpane grid = new gridpane();       grid.setvgap( 4 );       grid.sethgap( 10 );       grid.setpadding( new insets( 5, 5, 5, 5 ) );        final button button = new button ("ok");       final label notification = new label ();       final textfield subject = new textfield("");            final textarea text = new textarea ("");        final combobox prioritycombobox = new combobox();              prioritycombobox.getitems().addall( "highest", "high", "normal", "low", "lowest" );       prioritycombobox.setvalue("normal");         grid.add(new label("priority: "), 0, 0);       grid.add(prioritycombobox, 1, 0);       grid.add(new label("subject: "), 0, 1);       grid.add(subject, 1, 1, 3, 1);        grid.add(text, 0, 2, 4, 1);        grid.add(button, 0, 3);        group.getchildren().add( grid );    }     public static void main(string [] args)    {       application app = new application()       {          public void start(stage stage)          {             stage.settitle( "test" );             scene scene = new test( new group(), 450, 250);             stage.setscene( scene );             stage.show();          }        };       app.launch( args );    } } 

please note launch static method not know calling on anonymous application-instance created!

the best idea have make code this:

public static void main(string [] args) {    application.launch( myapp.class, args ); }  public static class myapp extends application {   public void start(stage stage)   {           stage.settitle( "test" );           scene scene = new test( new group(), 450, 250);           stage.setscene( scene );           stage.show();    }  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -