Results 1 to 19 of 19
  1. #1
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Java docs assist please

    I have decided to explore javadocs, java.awt .

    According to javadocs, this method should remove component from my application.


    I tried to write code, based on information, what website provided.

    Java Code:
    package ooo;
    
    import java.awt.Component;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class Begin extends Application {
    	
    	Button Needed, Useless;
    	Scene scene1;
    	Stage window;
    	
    
    	public static void main(String[] args) {
    		  launch(args);
        }
    	public void start(Stage primaryStage) {
    	
    		window = primaryStage;
            primaryStage.setTitle("Moves");
            window.setMaximized(false);
           
            Needed = new Button ("do");
            Needed.setTranslateY(100);
            Needed.setOnAction ( e-> {
            	
            void removeLayoutComponent (Component Useless) {
            	
            }	
            
            });
            
            Useless = new Button ("removes");
     
            StackPane test = new StackPane ();
            test.getChildren ().addAll (Needed, Useless);
            scene1 = new Scene (test, 500,500);
    		
            primaryStage.setScene(scene1);
            window.show();
    	}
    
    }
    31th line marks 'removeLayoutComponent' as a syntax mistake. (void is an invalid type for the variable removeLayoutComponent)
    What I have done wrong?
    Last edited by asdfg; 01-16-2017 at 09:37 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    A method can not be defined inside of another method. Define the new method outside of any existing methods.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    I have deleted removeLayoutComponent from lamba expressions.
    Inserted it in 42th line.

    Java Code:
     void removeLayoutComponent (Component Useless) {
    	             
    	        }
    It still shows same errors. I believe i have made mistake with parameters. Method name somehow also should be diffrend.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    Please copy the full text of the compiler's error message and post it here.
    Also post the source code that is causing the error.

    Inserted it in 42th line.
    Line 42 is inside the start() method.
    Try after line 45 just past the } at the end of the start() method.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Java Code:
    import java.awt.Component;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class Begin extends Application {
    	
    	Button Needed, Useless;
    	Scene scene1;
    	Stage window;
    	
    
    	public static void main(String[] args) {
    		  launch(args);
        }
    	public void start(Stage primaryStage) {
    	
    		 window = primaryStage;
    	        primaryStage.setTitle("Moves");
    	        
    	        Needed = new Button ("do");
    	        Needed.setTranslateY(100);
    	     
    	         
    	        Useless = new Button ("removes");
    	  
    	        StackPane test = new StackPane ();
    	        test.getChildren ().addAll (Needed, Useless);
    	        scene1 = new Scene (test, 500,500);
    	         
    	        void removeLayoutComponent ( Component Useless) {
    	        	
    	        }
    	             
    	        
    	        primaryStage.setScene(scene1);
    	        window.show();
           
    		
    	}
    
    }
    The code i wrote myself.
    'removeLayoutComponent' method is taken from here:



    Console:
    Exception in Application start method
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchAppl icationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchAppl ication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchAppl ication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$lau nchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.Error: Unresolved compilation problems:
    void is an invalid type for the variable removeLayoutComponent
    Syntax error on token "(", ; expected
    Syntax error on token ")", ; expected

    at ooo.Begin.start(Begin.java:36)
    at com.sun.javafx.application.LauncherImpl.lambda$lau nchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$run AndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$nul l$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$run Later$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run( InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Nativ e Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$14 8(WinApplication.java:191)
    ... 1 more
    Exception running application ooo.Begin

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    Did you see this from post#2
    A method can not be defined inside of another method. Define the new method outside of any existing methods.
    Also see post#4
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Yes I saw.

    Java Code:
    import java.awt.Component;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class Begin extends Application {
    	
    	Button Needed, Useless;
    	Scene scene1;
    	Stage window;
    	
    
    	public static void main(String[] args) {
    		  launch(args);
        }
    	public void start(Stage primaryStage) {
    	
    		 window = primaryStage;
    	        primaryStage.setTitle("Moves");
    	        
    	        Needed = new Button ("do");
    	        Needed.setTranslateY(100);
    	       
    	        	
    	       
    	         
    	        Useless = new Button ("removes");
    	  
    	        StackPane test = new StackPane ();
    	        test.getChildren ().addAll (Needed, Useless);
    	        scene1 = new Scene (test, 500,500);
    	         
    	       
    	        Needed.setOnAction ( e-> {
    		    removeLayoutComponent(Useless);	
    	        
    	        });   
    	        
    	        primaryStage.setScene(scene1);
    	        window.show();
           
    		
    	}
    
    	 void removeLayoutComponent ( Button Useless) {
    		 Useless.remove();
    	 }
    }

    I have updated code.
    If I leave 49th line empty = no compilator errors. And If I click 1 of Button, it still do not remove button.
    Thats because method need to be filled- I think.
    Last edited by asdfg; 01-16-2017 at 11:21 PM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    no compilator errors.
    Are you sure?

    Where is the remove() method documented for the Button class?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Quote Originally Posted by Norm View Post
    Are you sure?
    If method looks like this. Then- yes. Program have no errors.
    Java Code:
    void removeLayoutComponent ( Button Useless) {
    		
    	 }
    Where is the remove() method documented for the Button class?
    Nowhere.
    Once program runs, I can click one or other button. Button dont get removed.
    So I tried to fill 'removeLayoutComponent' method.
    Perhaps something diffrend should be written.

  10. #10
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Java Code:
    void removeLayoutComponent ( Button Useless) {
    		Useless.setVisible (false);
    	 }
    This works. Any other alternative?

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    Perhaps something diffrend should be written.
    Yes, You need to find the method to call to remove the component.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    I dont understand whats the point to write 'removeLayoutComponent' method in
    .
    If it works as just regular method.
    I could just wrote 'setvisible" in lambda expression, wihtout even calling method.
    Last edited by asdfg; 01-16-2017 at 11:56 PM.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    Ok, why not do that then.

    I think visibility is different from presence.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Quote Originally Posted by Norm View Post
    Ok, why not do that then.
    I thought it would be somehow diffrend.


    I think visibility is different from presence.
    Java Code:
     Needed.setOnAction ( e-> {
    	        	test.getChildren ().remove ( Useless);
    	        
    	        });
    This code I believe removes button?
    What to write in that method ( to remove, not make invisible) ?

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java docs assist please

    Sorry, I do not understand your question.
    If the code you posted removes the component,
    what do you want do differently?
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Quote Originally Posted by Norm View Post
    Sorry, I do not understand your question.
    If the code you posted removes the component,
    what do you want do differently?
    The code I posted - is lambda expressions.
    I want to see how this methodd should be filled:

    Java Code:
    void removeLayoutComponent ( Button Useless) {
             
         }
    As I didint found info about this in JavaDoc's.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Java docs assist please

    The method remove that you are looking at is on awt.Component. Unlike Swing, JavaFX widgets do not extend Component, so Button does not have access to that method.

    If you are learning JavaFX (and I still suggest avoiding GUI frameworks until you know how to code Java better) then stay away from Swing and AWT. It will only confuse you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    3

    Default Re: Java docs assist please

    Quote Originally Posted by Tolls View Post
    If you are learning JavaFX (and I still suggest avoiding GUI frameworks until you know how to code Java better) then stay away from Swing and AWT. It will only confuse you.
    So I should look to these doc's ? https://docs.oracle.com/javase/8/javafx/api/toc.htm

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Java docs assist please

    What are you trying to achieve?
    The Java Docs are a reference, not a learning tool. They allow you to look up what options are available for a class you are using.
    Don't try and read through them. That won't help.

    The JavaFX section on this page (left hand column) is what you should be looking through to learn how it fits together.
    However, this (as I keep saying) expects you to understand Java and OO development well, both of which you seem to have problems with.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 04-15-2014, 10:14 AM
  2. Kindly Assist Me With A Java Question PLease
    By dana_persad in forum New To Java
    Replies: 11
    Last Post: 11-22-2012, 06:27 AM
  3. Replies: 1
    Last Post: 09-22-2012, 06:16 PM
  4. Help With Generating Java Docs Using Eclipse
    By flyingcurry in forum New To Java
    Replies: 4
    Last Post: 04-08-2011, 05:57 AM
  5. Java Docs for log4j
    By javaplus in forum Advanced Java
    Replies: 0
    Last Post: 12-14-2007, 06:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •