package com.trail;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class FullScreenCaptureExample {
public static void main(String[] args) {
try {
Robot robot = new Robot();
String format = "jpg";
String fileName = "PartialScreenshot." + format;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle captureRect = new Rectangle(0, 0, screenSize.width / 2, screenSize.height / 2);
BufferedImage screenFullImage = robot.createScreenCapture(captureRect);
ImageIO.write(screenFullImage, format, new File(fileName));
System.out.println("A partial screenshot saved!");
} catch (AWTException | IOException ex) {
System.err.println(ex);
}
}
}
Tuesday, 7 June 2016
How take Screenshot in java Program
Saturday, 7 May 2016
How to invoke seter &geter Method of a java bean Using Java Reflection..!!
//Code......
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
public class InvokeSetterGetter {
public static void main(String[] args) {
/* Create object of Actor. */
Actor objActor = new Actor();
InvokeSetterGetter objInvokeSetterGetter =
new InvokeSetterGetter();
/* Call invokeSetter method */
objInvokeSetterGetter.invokeSetter(objActor, "Name", "Benedict Cumberbatch");
/* Call invokeGetter method */
objInvokeSetterGetter.invokeGetter(objActor, "Name");
}
private void invokeSetter(Object obj,
String variableName,
Object variableValue){
/* variableValue is Object because value can
be an Object, Integer, String, etc... */
try {
/**
* Get object of PropertyDescriptor
using variable name and class
* Note: To use PropertyDescriptor on any
field/variable, the field must have both `Setter` and `Getter` method.
*/
PropertyDescriptor objPropertyDescriptor =
new PropertyDescriptor(variableName,
obj.getClass());
/* Set field/variable value
using getWriteMethod() */
objPropertyDescriptor.getWriteMethod().invoke(obj,
variableValue);
}
catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | IntrospectionException e) {
/* Java 8: Multiple exception
in one catch. Use Different catch block for lower version. */
e.printStackTrace();
}
}
private void invokeGetter(Object obj, String variableName){
try {
/**
* Get object of PropertyDescriptor
using variable name and class
* Note: To use PropertyDescriptor
on any field/variable,
the field must have both `Setter` and `Getter` method.
*/
PropertyDescriptor objPropertyDescriptor =
new PropertyDescriptor(variableName, obj.getClass());
/**
* Get field/variable value using getReadMethod()
* variableValue is Object
because value can be an Object, Integer, String, etc...
*/
Object variableValue=objPropertyDescriptor.getReadMethod().invoke(obj);
/* Print value of variable */
System.out.println(variableValue);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | IntrospectionException e) {
/* Java 8: Multiple exception in
one catch. Use Different catch block for lower version. */
e.printStackTrace();
}
}
}
Friday, 22 April 2016
Convert Java (JDBC) ResultSet to JSON Using RStoJSON API in Java
This API is develop by me.It convert ResultSet to JSON String..By invoking a static Method present in Converter CLASS.(download RStoJSON.jar from here)
ResultSet rs=ps.executeQuery();
String jsonString=com.learners.converter.Converter.rsTojson(rs);
Use Code As
String jsonString=com.learners.converter.Converter.rsTojson(rs);
Use Code As
Set jar file in lib Folder
It will give Out put As
(its a web service output on postman)
Thursday, 21 April 2016
How to make ResultSet Object to JSON String in Java
package com.learners.converter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection;
/**
* @author jyotioeuvretc.com
*
*/
public class Converter {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://192.168.0.29/scylla","root","root");
PreparedStatement ps=con.prepareStatement("SELECT * FROM view_promocode_doctor ");
ResultSet rs=ps.executeQuery();
ResultSetMetaData rsm=rs.getMetaData();
System.out.println("col="+rsm.getColumnCount()+"table="+rsm.getTableName(1));
ArrayList<StringBuilder> collist=new ArrayList<StringBuilder>();
while(rs.next()){
StringBuilder sb=new StringBuilder();
sb.append("{");
for(int i=1;i<rsm.getColumnCount()+1;i++){
//System.out.println(rsm.getColumnName(i)+":"+rs.getString(i)+",");
if(i==rsm.getColumnCount())
{
sb.append("\""+rsm.getColumnName(i)+"\":\""+rs.getString(i)+"\"");
}
else
{
sb.append("\""+rsm.getColumnName(i)+"\":\""+rs.getString(i)+"\",");
}
}
sb.append("}");
collist.add(sb);
}
//OutPut
System.out.println(collist.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
It give Output As....
Tuesday, 19 April 2016
How to Use media Query in CSS to change the style according to screen width ?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
background-color:lightgreen;
}
@media only screen and (max-width:600px){
body{
background-color:black;
}
}
@media only screen and (max-width: 500px) {
body {
background-color:lightblue;
}
}
</style>
</head>
<body>
<p>Resize the browser window. When the width of this document is less than 500 pixels,
the background-color is "lightblue", otherwise it is "lightgreen".</p>
</body>
</html>
It will work as....
Resize the browser window. When the width of this document is
less than 500 pixels, the background-color is "lightblue",
otherwise it is "lightgreen".
how to filter input element in html 5 ?
Only audio.....<input accept="audio/*;capture=microphone" type="file" /> It will work as__
Friday, 15 April 2016
how to share your website in Facebook by javascript ?
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!-- facebook login -->
<script>
//Load the Facebook JS SDK
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "https://connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
/* (function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
*/
// Init the SDK upon load
window.fbAsyncInit = function () {
FB.init({
appId: '1459247121050170',//0
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
version: 'v2.5' // old v2.4
});
// Specify the extended permissions needed to view user data
// The user will be asked to grant these permissions to the app (so only pick those that are needed)
//public_profile,email
var permissions = [
'public_profile',
'email',
].join(',');
var fields = [
'id',
'name',
'first_name',
'middle_name',
'last_name',
'gender',
'locale',
'languages',
'link',
'third_party_id',
'installed',
'timezone',
'updated_time',
'verified',
'age_range',
'bio',
'birthday',
'cover',
'currency',
'devices',
'education',
'email',
'hometown',
'interested_in',
'location',
'political',
'payment_pricepoints',
'favorite_athletes',
'favorite_teams',
'picture',
'quotes',
'relationship_status',
'religion',
'significant_other',
'video_upload_limits',
'website',
'work'
].join(',');
function showDetails() {
FB.api('/me', {fields: fields}, function (details) {
alert(JSON.stringify(details)); // display all the details
var res = jQuery.parseJSON(JSON.stringify(details));
/* alert(res.payment_pricepoints.mobile.length);
for(var i=0;i<res.payment_pricepoints.mobile.length;i++){
alert(res.payment_pricepoints.mobile[i].local_currency);
} */
var email = res.email;
var firstName = res.first_name;
var lastName = res.last_name;
var gender = res.gender;
var profielPictureURL = res.picture.data.url;
//alert(profielPictureURL);
profielPictureURL = profielPictureURL.replace(/&/g, "@");
//alert(profielPictureURL);
var data = "email=" + email + "&firstName=" + firstName + "&lastName=" + lastName + "&gender=" + gender + "&profielPictureURL=" + profielPictureURL + "&operation=social-media-signin&siginThrough=facebook";
alert(data);
/* $.ajax({
type: "POST",
url: "LoginServlet",
data: data,
success: function (response) {
if (response === "0") {
alert("Invalid Login");
} else {
location.href = "";
}
},
error: function (errorMsg) {
alert("Error Occurred.");
}
}); */
});
}
$('#facebook').click(function () {
//initiate OAuth Login
FB.login(function (response) {
// if login was successful, execute the following code
if (response.authResponse) {
showDetails();
sharefbimage();
}
}, {scope: "public_profile,email"});
});
};
//todayscode......................
function sharefbimage() {
FB.init({ appId: '1459247121050170', status: true, cookie: true });
FB.ui(
{
method: 'share',
name: 'Facebook Dialogs',
href: $(location).attr('href'),
link: 'www.plateofcode.com',
picture: 'https://www.blogger.com/img/blogger-logo-small.png',
caption: ' Book',
description: 'description'
},
function (response) {
alert(JSON.stringify(response));
if (response && response.post_id) {
alert('success');
} else {
alert('error');
}
}
);
}
//
</script>
<!-- end facebook login -->
</head>
<body>
<button id="facebook" style="background-color: #0967DA;color:white;border: thin;">facebook</button>
</body>
</html>
It will work as....
Subscribe to:
Posts (Atom)
