Tuesday, April 30, 2013

Get current method name using Thread.currentThread().getStackTrace()

To get the stack trace elements in StackTraceElement[] form, call Thread.currentThread().getStackTrace(). The second element, [1], is the your method call getStackTrace(); [0] is getStackTrace(). Then call its getMethodName() method to get the name of your method.

Example to print the stack trace elements, and the name of the current method.

Get current method name
Get current method name


package javafxapplication1;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFXApplication1 extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                method_01();
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
    
    private void method_01(){
        method_02();
    }
    
    private void method_02(){
        
        StackTraceElement[] stackTraceElementArray = 
                Thread.currentThread().getStackTrace();
        
        for(int i = stackTraceElementArray.length-1; i >= 0; i--){
            System.out.println(i + ":" + stackTraceElementArray[i].getMethodName());
        }
        
        String me = Thread.currentThread().getStackTrace()[1].getMethodName();
        System.out.println("It's: " + me);
    }
}


Sunday, April 28, 2013

Introduction to Java Development with OpenCV



OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code.

As of OpenCV 2.4.4, OpenCV supports desktop Java development using nearly the same interface as for Android development. The guide, Introduction to Java Development, will help you to create your first Java (or Scala) application using OpenCV, use Eclipse, Apache Ant or the Simple Build Tool (SBT) to build the application.


Tuesday, April 23, 2013

JavaFX Scene Builder Tutorial updated wth Using Scene Builder with NetBeans, Eclipse and IntelliJ

JavaFX Scene Builder (Scene Builder) enables you to quickly design JavaFX application user interfaces by dragging a UI component from a library of UI components and dropping it into a content view area. The FXML code for the UI layout that you create in the tool is automatically generated in the background. To learn more about Scene Builder's features, see to JavaFX Scene Builder User Guide.

Scene Builder can be used as a standalone design tool, but it can also be used in conjunction with Java IDEs, so that you can use the IDE to write, build, and run the controller source code that you use with your application's user interface.

The tutorial of Using JavaFX Scene Builder with Java IDEs in JavaFX Documentation updated with information about how to configure the NetBeans, Eclipse, or IntelliJ IDEs to use with Scene Builder.