Date Calculation in JavaFX2.0


From following code you can easily get idea how to calculate date in JavaFX. JavaFX is fully based on java you can easily implement any java concept in your business logic.Here is sample code how to use all type of date calculation in javaFX.
// Comment

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

import java.awt.Label;
import java.util.Calendar;
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 saibaba
 */
public class DateCalculation extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Date Calculation");
       Button btn = new Button();
       
       
        btn.setText("Calculate Date ");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                 Calendar cal = Calendar.getInstance();
             System.out.println("Today : " + cal.getTime());
  
         // Subtract 30 days from the calendar
         cal.add(Calendar.DATE, -30);
         System.out.println("30 days ago: " + cal.getTime());
  
         // Add 10 months to the calendar
         cal.add(Calendar.MONTH, 10);
         System.out.println("10 months later: " + cal.getTime());
  
         // Subtract 1 year from the calendar
         cal.add(Calendar.YEAR, -1);
         System.out.println("1 year ago: " + cal.getTime());
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}
Output
Today : Sun Jun 17 17:44:00 IST 2012
30 days ago: Fri May 18 17:44:00 IST 2012
10 months later: Mon Mar 18 17:44:00 IST 2013
1 year ago: Sun Mar 18 17:44:00 IST 2012


Unknown Web Developer

To create Image Panel in Swing


In this article you can get idea how to use a image panel in Swing Application.By using this code you can make your swing application much transparent image view.

// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
 
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
 *
 * @author allinalljava.blogspot.com
 */
public class ImagePanel  extends JPanel{
     
 
  private Image img;
 
  public ImagePanel(String img) {
    this(new ImageIcon(img).getImage());
  }
 
  public ImagePanel(Image img) {
    this.img = img;
    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
    setPreferredSize(size);
    setMinimumSize(size);
    setMaximumSize(size);
    setSize(size);
    setLayout(null);
  }
 
  public void paintComponent(Graphics g) {
    g.drawImage(img, 0, 0, null);
  
}

}



In the above code you can easily create a Image panel.But In order to implement the application You can following code.By means of that You can enjoy Better Output Look and Feel in application.
// Comment

JPanel mainpanel = new ImagePanel(new ImageIcon(this.getClass().getResource("/images/12.jpg")).getImage());

Following Program describes sample implementation of Image Panel in Swing
// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

/**
 *
 * @author j
 */

    import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
 
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
public class NewClass {
 
  public static void main(String[] args) {
    ImagePanel panel = new ImagePanel(new ImageIcon("C:\\12.jpg").getImage());
 
    JFrame frame = new JFrame();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
  }
}
 
OutPut Window

Unknown Web Developer

Reverse String in Java


From Following  Program you can get the good knowledge in String Processing.Here i am Converting text in two way.Whole text that given as in put is reversed or by reversing each word by eliminating space.For running this program you need "org.apache.commons.lang.StringUtils" Library.
// Comment

import org.apache.commons.lang.xwork.StringUtils;

public class ReverseString {

    
     public static void main(String[] args)
     {
        
         String sampletext = "Java is Great Language";
          
        
         String reversed = StringUtils.reverse(sampletext);
          
         
         String delimitedReverse = StringUtils.reverseDelimited(sampletext, ' ');
                  
         
         System.out.println("Normal: " + sampletext);
         System.out.println("Reversed: " + reversed);
         System.out.println("Delimited Reverse: " + delimitedReverse);
     }

 
}


Output
Normal: Java is a Great Language
Reversed: egaugnaL taerG a si avaJ
Delimited Reverse: Language Great a is Java
Unknown Web Developer

TamilNadu Government Free Laptop Brand ,Configration And avilable Region



Free  tamilnadu government Laptop Brands

Lenovo 300,000 laptops
Acer and HCL  200,000 laptops
Wipro 50,000 laptops
RP Infosystems  75,000 laptops

This is the Biggest order of Tamilnadu Government in India, the free laptop scheme is part of Tamil Nadu chief minister J Jayalalithaa’s pre-poll promise to voters, The government sector is emerging as one of the largest spenders on information technology owing to a thrust of late on e-governance. The Laptop are avilable for students. In the same approach if the education system of tamilnadu is computerized then it would be the best State to provide a better education for the students.



Tamil Nadu Free Laptop Now Avail in Following Areas.


Virudhunagar,
Trinelveli,
Aruppukotai,
Sivakasi,
Kovil Patti,
Madurai
Thuthukoody,
Chennai.
Trichy.
Soon in your village also.

In all the above Region the tamilnadu government laptop is distributed for village students and Colleges of Arts and Science. If possible you can get Better laptop at Cheap Price.



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)


Warranty                     : one-year

Laptop comes with the Logo of tamilnadu government. And the chip is also trusted. Some of laps comes with Linux OS. All the Laptop is provided a serial number due that students Can get out of their technical issues Faced in laptop
Unknown Web Developer

AffinityClick - Generate revenue from your content!


Unknown Web Developer

Free Laptops Register Here


After a long research on web i found the sites that offering free Laptops.You no need to do any thing for getting free laptop.Laptops are provided by Laptop manufacture for testing their products.Thing that you have to do is just register in the site for getting your laptop.After getting Your laptop you have to send your Feed Back about how your laptop works and any draw backs related details to the manufacture.

            There lot of websites is providing laptop for free. To register for free laptop just place your Order Here
Unknown Web Developer

Open/Close DVD Tray using JAVA FX 2


In the following example you can easily create a Open/Close DVD tray software.I have show the way how to implement the program in javafx 2.0

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

import java.awt.Desktop;
import java.io.File;
import java.io.PrintWriter;
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 saibaba
 * allinalljava.blogspot.com
 * Sabari
 */
public class JavaFXApplication1 extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Open /Close CD Tray");
        Button btn = new Button();
        btn.setText("Open CD");
        btn.setOnAction(new EventHandler() {

            @Override
            public void handle(ActionEvent event) {
              opencd();
             
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
    
    
   public void opencd()
   {
   try
  {
  
   String a="Set oWMP = CreateObject(\"WMPlayer.OCX\")"+"\n"
    +"Set colCDROMs = oWMP.cdromCollection"+"\n"
    +"For d = 0 to colCDROMs.Count - 1"+"\n"
    +"colCDROMs.Item(d).Eject"+"\n"
    +"Next"+"\n"
    +"set owmp = nothing"+"\n"
    +"set colCDROMs = nothing"+"\n"
    +"wscript.Quit(0)";
 
   
   //Create a vbscript file called OpenCdTray.vbs
   File myCdTrayOpener=new File("OpenCdTray.vbs");
   
   //Create a PrintWriter object that will use to write into created file
   PrintWriter pw=new PrintWriter(myCdTrayOpener);
   
   //Write all string in (a) into created file
   pw.print(a);
   
   //Flush all resource in PrintWriter to make sure
   //there are no data left in this stream.
   pw.flush();
   
   //Close PrintWriter and releases any 
   //system resources associated with it
   pw.close();
   
  
   //It will open using default application that will use 
 
   Desktop.getDesktop().open(myCdTrayOpener);
   
   //Delete created vbs file before terminate application
   myCdTrayOpener.deleteOnExit();
  }
  catch(Exception exception)
  {
   exception.printStackTrace();
  }
   
   }
}


Output Windows Screen 

Unknown Web Developer

Open your System Directory From Java


While running the following program you can easily open directory that you like from Java Code.
// Comment
package com.sabari;

import java.io.IOException;

public class opendirectory {
 public static void main(String[] args) throws IOException {
  String cmd = "cmd.exe /c start ";
  String file = "c:\\";
  Runtime.getRuntime().exec(cmd + file);
 }

}



Output Screen 

Unknown Web Developer

Intract with your Email Application Using Java code.


In this following example you get idea how to interact with the email application from your java code.
// Comment
package com.sabari;

import java.io.IOException;

public class simpleemailer {
 public static void main(String[] args) throws IOException {
  String editorpath = "cmd.exe /c start ";
  String mailid = "mailto:[email protected]";
  Runtime.getRuntime().exec(editorpath + mailid);
 }

}

Output Window


Unknown Web Developer

Dynamically Resize Your Frames


In Java Frames are not dynamically Re-sized by default .In order to perform this function Just add the following code your code.

// Comment
Toolkit.getDefaultToolkit().setDynamicLayout(true);

Using this code Frame are auto re sized according to the client window.
Unknown Web Developer

Using Robot in Java


java.awt.Robot is a best robot class which is mainly used to create a simulation software.Due to this robot class you can automatically enable mouse and keyboard event from java code itself.Following program helps us to invoke some basic stuff to get a picture about how to implement robot in java.
// Comment
package com.sabari;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class simplerobot {
 

 public static void main(String[] args) {
 try {

 Robot robot = new Robot();
 
 robot.delay(1000);
 robot.keyPress(KeyEvent.VK_J);
 robot.keyPress(KeyEvent.VK_A);
 robot.keyPress(KeyEvent.VK_V);
 robot.keyPress(KeyEvent.VK_A);
 robot.keyPress(KeyEvent.VK_SPACE);
 robot.keyPress(KeyEvent.VK_2);


 } catch (AWTException e) {
 e.printStackTrace();
 }
 }
 } 



Output Window 

In order to run the program first you have to open notepad or word pad .Then you can easily Study the implementation workflow process of Robot.
Unknown Web Developer

Java Program Basic


From Following program you can easily understand basics of defining the java program step by step.




// Comment
package com.sabari;

import java.util.Scanner;

public class simple {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  String name;
  Scanner in = new Scanner(System.in);
  System.out.println("Enter Your name");
  name = in.nextLine();
  System.out.println("Enter Your Age");
  int  age = in.nextInt();
  System.out.println("Your Name:"+name);
  System.out.println("Your Age:"+age);

 }

}




Out Put
Enter Your name
 sabari
Enter Your Age
29
Your Name: sabari
Your Age:29
// Comment
class simple {

Here class is a keyword mainly use to create a new class."simple" is the name of the class.
// Comment
public static void main(String[] args) {

Public - public is an access specifier, due to this the programmer can easily  control the visibility of class members. When a class member is affirmed as public, then that member can be accessed by code outside the class in which it is declared.

static allows main( ) to be elite to instantiate a particular instance of the class. main( ) is called by the Java interpreter before any objects are created.

 void merely says the compiler  ,main( ) does not return a value
main( ) is called when a Java application initiates.
It is imperative to realize that the Java compiler will compile classes that do not contain a main( ) method.



Java interpreter  has no approach to run these classes .if you mention Main as a replacement for main, the compiler retain compile your program. Java interpreter will testimony an error because it cant find the main( ) method.

String args[ ] array of instances of the class  String.

  args obtains command-line arguments here when the program    is     executed.Arrays are collections of similar objects.
A complex program may have several number of classes,but one main class is need to initiate an application.
While creating applets—Java programs are  usually embedded in Web browsers so we no need to use  main( ) at all, because Web browser uses a various ways of starting the execution of applets.

System is a predefined class affords various access to the system

out  is the output stream which is usually get in connected with that of console.
Output is consummate by the built-in println( ) method.
print( )  mainly exhibit the string .This string is not go behind a newline. next output is generated, it will start on the same line.
Unknown Web Developer

Related Posts Plugin for WordPress, Blogger...