Platform Independent Shutdown Button web component using JavaFX 2.0


Due to this web component you can able to shutdown all type of Operating System .Your can place this component in any of your Web page.By clicking it will shut down your system.In this program you can easily come to know to apply JavaFx CSS Styles to button.


Source code
// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shutdownsys;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
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;

/**
 *
 * @author allinalljava.blogspot.com */
public class Shutdownsys extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Shut Down");
        Button btn = new Button();
        btn.setText("Shut Down");
               String style_root =" -fx-background-color:   linear-gradient(#ffd65b, #e68400),linear-gradient(#ffef84, #f2ba44), linear-gradient(#ffea6a, #efaa22),linear-gradient(#ffe657 0%, #f8c202 50%, #eea10b 100%), linear-gradient(from 0% 0% to 15% 50%, rgba(255,255,255,0.9), rgba(255,255,255,0));-fx-background-radius: 30;    -fx-background-insets: 0,1,2,3,0;    -fx-text-fill: #654b00;    -fx-font-weight: bold;    -fx-font-size: 14px;    -fx-padding: 10 20 10 20;";
      btn.setStyle(style_root);
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                try {
                    System.out.println("Shut Down");
                    shutdown();
                } catch (RuntimeException ex) {
                    Logger.getLogger(Shutdownsys.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Shutdownsys.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 100, 100));
        primaryStage.show();
    }
    public static void shutdown() throws RuntimeException, IOException {
    String shutdownCommand=null;
    String operatingSystem = System.getProperty("os.name");

  if (operatingSystem.startsWith("Win")) {
  shutdownCommand = "shutdown.exe -s -t 0";
} else if (operatingSystem.startsWith("Linux") || operatingSystem.startsWith("Mac")) {
  shutdownCommand = "shutdown -h now";
} else {
  System.err.println("Shutdown unsupported operating system ...");
    //closeApp();
}


    Runtime.getRuntime().exec(shutdownCommand);
    System.exit(0);
}
}
 

Output Screen
raja P Web Developer

Java Fx Web Component Developement using Xml


In this post you get a good solution to create a web component for your website using Java Fx 2.0.Main benefit of Java Fx 2.0 is Java.Here in this application i choose xml file in order to provide a portable web component .For deploy use Netbeans7.1 by which you can easily develop JNLP file. You can provide your input in the form of xml data..Following is sample program for creating Pie Chart component for your website.As Java FX is rich client side application it can be easily run in all browser.
Sourcecode

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chartsamples;

import java.io.File;
import java.util.List;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.chart.*;
import javafx.scene.Group;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
 *
 * @author sabari
 */
public class Chartsamples extends Application {
 @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setTitle("Best Technology");
        stage.setWidth(500);
        stage.setHeight(500); 
        ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
        NodeList listOfPersons = getListOfNode();
            int totalPersons = listOfPersons.getLength();
          

            for(int s=0; s<listOfPersons.getLength() ; s++){


                Node firstPersonNode = listOfPersons.item(s);
                if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){


                    Element firstPersonElement = (Element)firstPersonNode;

                    //-------
                    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                    Element firstNameElement = (Element)firstNameList.item(0);

                    NodeList textFNList = firstNameElement.getChildNodes();
                    System.out.println("First Name : " + 
                           ((Node)textFNList.item(0)).getNodeValue().trim());
                    String fName=((Node)textFNList.item(0)).getNodeValue().trim().toString();

                    //-------
                    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                    Element lastNameElement = (Element)lastNameList.item(0);

                    NodeList textLNList = lastNameElement.getChildNodes();
                    System.out.println("Last Name : " + 
                           ((Node)textLNList.item(0)).getNodeValue().trim());

                    //----
                    NodeList ageList = firstPersonElement.getElementsByTagName("stat");
                    Element ageElement = (Element)ageList.item(0);

                    NodeList textAgeList = ageElement.getChildNodes();
                    System.out.println("Age : " + 
                           ((Node)textAgeList.item(0)).getNodeValue().trim());

                    //------
                   pieChartData.add(    new PieChart.Data(
                           
                           ((Node)textFNList.item(0)).getNodeValue().trim().toString()+
                           ((Node)textLNList.item(0)).getNodeValue().trim().toString(),
                           Double.parseDouble(((Node)textAgeList.item(0)).getNodeValue().trim().toString())));

                }//end of if clause


            }//end of for loop with s var
              pieChartData.add(    new PieChart.Data("Java", 70));
              pieChartData.add(    new PieChart.Data(".Net", 30));
              pieChartData.add(    new PieChart.Data("Php", 20));
              pieChartData.add(    new PieChart.Data("Ajax", 40));
              pieChartData.add(    new PieChart.Data("JavaScript", 20));
              
          
        final PieChart chart = new PieChart(pieChartData);
        chart.setTitle("Best Technology");

        ((Group) scene.getRoot()).getChildren().add(chart);
        stage.setScene(scene);
        stage.show();
    }
 
 public NodeList getListOfNode()
 {   NodeList listOfPersons=null;
  try {

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            System.out.println ("the path is"+ReadAndPrintXMLFile.class.getResource("book.xml").toString());          
            Document doc = docBuilder.parse (ReadAndPrintXMLFile.class.getResource("book.xml").toString()); 
            doc.getDocumentElement ().normalize ();
            System.out.println ("Root element of the doc is " + 
               doc.getDocumentElement().getNodeName());
               NodeList chidnode=doc.getDocumentElement().getChildNodes();
               System.out.println ("Root element of the doc is " + 
               doc.getDocumentElement().getChildNodes());
               listOfPersons = doc.getElementsByTagName("person");
        

        }catch (SAXParseException err) {
        System.out.println ("** Parsing error" + ", line " 
             + err.getLineNumber () + ", uri " + err.getSystemId ());
        System.out.println(" " + err.getMessage ());

        }catch (SAXException e) {
        Exception x = e.getException ();
        ((x == null) ? e : x).printStackTrace ();

        }catch (Throwable t) {
        t.printStackTrace ();
        }
        //System.exit (0);

    return   listOfPersons;

 }
    public static void main(String[] args) {
        launch(args);
    }
}


Xml File
// Comment
eg
<book>
<person>
  <first>Java</first>
  <last>Technology</last>
  <stat>60</stat>
</person>
<person>
   <first>Dot Net</first>
  <last>Technology</last>
  <stat>30</stat>
</person>
<person>
  <first>Php</first>
  <last>Web</last>
  <stat>20</stat>
</person>
<person>
  <first>HTML</first>
 <last>Web</last>
  <stat>20</stat>
</person>
<person>
  <first>Java Script</first>
<last>Web</last>
  <stat>30</stat>
</person>
<person>
  <first>Ajax</first>
 <last>Web</last>
  <stat>40</stat>
</person>
</book> 


Output Window Screen
raja P Web Developer

Microsoft (So.cl) social network


 Microsoft plunged its So.cl social networking service to worldwide , where users can share and comment on exciting search results with their friends.
Users discern people who are showing interest in the assonant topics,proctor their companions' feeds and take part in "video parties" during which members watch online videos together, commenting on them via chat function.
Its more flexible to create an account with so.cl by integrating with your Facebook account . Members can also create their own "collages of content" using the firm's Bing search engine technology and external links, which they can share with others. 
Its possible to share various information related to technology,shopping ,articles ,games,etc .For each favorite topics there resides a template.You can easily access and share it with your Facebook friend.

Link for social network is www.so.cl.
raja P Web Developer

Best Free Laptop configuration of Tamil nadu government


Tamil Nadu Government free laptop is great Opportunity for student to learn in better way.Government providing laptop with better configuration .Outlook of laptop is also smart.All the students will rush to get Laptop.In the same way if the government promote the student to study visually then only
this scheme will get a fruitful outcome.

                  Laptop configuration

Processor                   : Intel Pentium dual-core processor
Operating System      : Windows 7 & Linux BOSS 4.0
size                            : 14-inch display
Weight                       : 2.7 kg
Physical Memory      : 2 GB Ram
HDD                          : 320 GB (Excluded in DVD writer, Web camera, Modem)
Price                          : Rs.15,000
Warranty                     : one-year

Download all Model Tamil Nadu Government free laptop Mother Board Drivers From this Links.
raja P Web Developer

Simple Chart Application using JavaFx 2.0


Following Example show how to create a  pie chart using JavaFx2.0.While you go through the program your can get a idea way that it works.
Source Code
// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chartsamples;

/**
 *
 * @author sabari
 */
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.chart.*;
import javafx.scene.Group;
 
public class simplepiechart extends Application {
 
    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setTitle("Large Cities");
        stage.setWidth(500);
        stage.setHeight(500);
 
        ObservableList pieChartData =
                FXCollections.observableArrayList(
                new PieChart.Data("Chennai", 40),
                new PieChart.Data("Madurai", 20),
                new PieChart.Data("Delhi", 50),
                new PieChart.Data("Goa", 20),
                new PieChart.Data("Hyderabad", 30),
                new PieChart.Data("Bangalore", 35),
                new PieChart.Data("Mumbai", 60));
        final PieChart chart = new PieChart(pieChartData);
        chart.setTitle("Large Cities");

        ((Group) scene.getRoot()).getChildren().add(chart);
        stage.setScene(scene);
        stage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
}



Output Screen
raja P Web Developer

Best topics to focus for Java fresher Interview


Most common interview question for java is based on the following topics.If you are strong in these topics then you can surely get placed in Good company with better incentives.
  • Overloading and Overriding
  • Threads
  • Garbage Collection
  • Class 
  • Objects
  • Access Specifiers
  • Datatypes, Variables, and Arrays, Operators, Control Statements
  • Packages , Interfaces
  • Exception handling
  • Networking
  •  String handling
  •  Collections FrameWork
  • JDBC programming
  • Object-Oriented concepts 
  • Servlet
  • Jsp
Based on above all topics just try to know the basic of each with best examples.All these concept is applied in all java web frameworks.There are so many websites available to study programs with example just go through it .For example www.roseindia.net,www.java2s.com. Where you can see lot of java programs.Keep the basic of java in finger tips.For studying all these topic it may take only one weak as part of your work.
   Try to learn differences between c ,c++,java.jsp,servlet. All the best for you Jobs.If you work you can get it.
raja P Web Developer

Table View in Java Fx2.0 using Collection



In this example, person class is a pojo(Plain Old Java Object).In order to load a mutiple data in table view component i have used the collection in javaFx
// Comment
 ObservableList people = FXCollections.observableArrayList();
This is method by which we can get collection of data in to Array List.Then obtained list is loaded in the table view component of JavaFx2.0
person.java
// Comment
package javafxapplication2;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

/**
 *
 * @author sabari
 */
public class person {

    private String firstName;
private ObservableList employees = FXCollections.observableArrayList();

    person() {
      
    }

    public ObservableList getEmployees() {
        return employees;
    }

    public void setEmployees(ObservableList employees) {
        this.employees = employees;
    }
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    private String lastName;

    public person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }



}

Main.java
// Comment
package javafxapplication2;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

import javafx.stage.Stage;

public class Main extends Application {

    public void start(Stage stage) {
       
        stage.setTitle("Hello Table");

        Group root = new Group();
        Scene scene = new Scene(root);
        stage.setScene(scene);

       root.getChildren().add(getTableView());
        stage.show();
    }

    public TableView getTableView() {
        
     ObservableList people = FXCollections.observableArrayList();
        
 people.add(new person("Associate", "Javafx"));
 people.add(new person("Developer", "Hibernate"));
 people.add(new person("Best performer", "Java"));
 people.add(new person("Best Programmer", "Sabari Raja"));

        TableView tableView = new TableView();
   
        tableView.setItems(people);

        TableColumn firstNameCol = new TableColumn("First");
     
firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
        TableColumn lastNameCol = new TableColumn("Last");
    
        lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
      

        tableView.getColumns().addAll(firstNameCol, lastNameCol);

        return tableView;
    }

    public static void main(String[] args) {
      Application.launch(args);
    }


}




Output 

raja P Web Developer

Text Reflection Effect in Java Fx2.0


In this Example you can easily come to know that how to apply a background color to your Java Fx 2.0 application.Here i have used various text effect to show the possible text reflection in javaFx 2.0.

// Comment
package javatextreflection;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Reflection;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 *
 * @author allinalljava.blogspot.com
 */
public class Javatextreflection extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        
primaryStage.setTitle("Reflection Example");
Group root = new Group();
Scene scene = new Scene(root,300, 300, Color.BLACK);


Text text1 = new Text(10, 50, "Welcome to JavaFX2.0");
Font monoFont = Font.font("Monospaced", 30);
text1.setFont(monoFont);
text1.setFill(Color.AQUA);
root.getChildren().add(text1);
Text text2 = new Text(100, 150, "Reflection");
Font monoF = Font.font("Monospaced", 22);
text2.setFont(monoF);
text2.setFill(Color.ANTIQUEWHITE);
root.getChildren().add(text2);
Reflection reflECT = new Reflection();
reflECT.setFraction(0.8f);
text1.setEffect(reflECT);
text2.setEffect(reflECT);
primaryStage.setScene(scene);
primaryStage.show();
    }
}





Output

raja P Web Developer

ImageView Reflection in Java Fx 2.0


This is the sample program for running image view in JavaFx2.0.Reflection effect has been applied to the image that have been loaded.We have load the image in to the Image view component of the JavaFx 2.0 and then we have load it in the scene that we have to display.
// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ImageReflection;

import java.awt.Color;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.Reflection;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @author allinalljava.blogspot.com
 */
public class ImageReflection extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
          primaryStage.setTitle("Hello World!");
          StackPane root = new StackPane();
          Image img = new Image(ImageReflection.class.getResource("image1.jpg").toString());
          ImageView sample = new ImageView(img);
          final Reflection reflection = new Reflection();
          reflection.setFraction(0.5);
          sample.setEffect(reflection);
          root.getChildren().add(sample);      
          primaryStage.setScene(new Scene(root,800, 600,javafx.scene.paint.Color.BLACK));
          primaryStage.show();
    }
}


Output
raja P Web Developer

Java Fx 2.0 Simple Media Player


In Java Fx 2.0 is fully a UI based Application in which we can easily create all types of desktop and web based component .Here i have explained a sample media player program which  it can play all type of you tube files.for running this application you need netbeans 7.1. with javafx 2.0
// Comment

package SimpleMediaPlayer;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 *
 * @author allinalljava.blogspot.com
 */
public class SimpleMediaPlayer extends Application {

    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
  
    public void start(Stage stage) {
     //At First Step You have to create a Scence For Showing the Screen.
     Scene scene = new Scene(new Group(), 540, 209,Color.BLUEVIOLET);
     stage.setScene(scene);

     // Name and display the Stage.
     stage.setTitle("Welcome to Java Fx 2.0 Media Player Example");
     stage.show();
     // Create the media source. which is possible to get the file from the Embeddedjar itself
  
     Media media = new Media(SimpleMediaPlayer.class.getResource("You Belong To Me - JX.flv").toString());

     // Create the player for playing media.
     MediaPlayer mediaPlayer = new MediaPlayer(media);
     //set player property to autoplay
     mediaPlayer.setAutoPlay(true);

     // Create the view and add it to the Scene.
     MediaView mediaView = new MediaView(mediaPlayer);
     ((Group) scene.getRoot()).getChildren().add(mediaView);
 }
}
raja P Web Developer

Related Posts Plugin for WordPress, Blogger...