| |||||||||||||||||||||||||||||||||||||||||||||||||||
Think,Learn,Share
Tuesday, November 24, 2015
Friday, October 31, 2014
Currency Convertor
public partial class Form1 : Form
{
String curr1 = "";
String curr2 = "";
public Form1()
{
InitializeComponent();
}
private void cmbCurrencywnt_SelectedIndexChanged(object sender, EventArgs e)
{
curr2 = cmbCurrencywnt.SelectedText.ToString();
}
private void cmbCurrencyhv_SelectedIndexChanged(object sender, EventArgs e)
{
curr1 = cmbCurrencyhv.SelectedText.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
//ServiceReference1.CurrencyConvertorSoapClient objWS = new ServiceReference1.CurrencyConvertorSoapClient();
ServiceReference1.CurrencyConvertorSoapClient objWS = new ServiceReference1.CurrencyConvertorSoapClient("CurrencyConvertorSoap");
curr1 = cmbCurrencyhv.SelectedItem.ToString();
curr2 = cmbCurrencywnt.SelectedItem.ToString();
double usdToinr = objWS.ConversionRate((ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), curr1), (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), curr2));
//double usdToinr1 = objWS.ConversionRate((ServiceReference1.Currency)System.Enum.Parse(curr1), curr2);
double totalAmount = usdToinr * Double.Parse(txtCurrencyhv.Text);
txtCurrencywnt.Text = totalAmount.ToString();
//MessageBox.Show(totalAmount.ToString(), "Total Indian Rupees");
}
}
Web service link:
http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
Regular expressions
Email
String email= textField.getText();
//method implementation
private boolean validMail(String email) {
Pattern emailPattern = Pattern.compile(".+@.+\\.[a-z]+");
Matcher emailMatcher = emailPattern.matcher(email);
return emailMatcher.matches();
}
//method calling
if(validMail(email))
JOptionPane.showMessageDialog(rootPane, "email is right");
else
JOptionPane.showMessageDialog(rootPane, "wrong email");
Password
String pw =textField_1.getText();
//method implementation
private boolean validPassword(String pw){
Pattern passwPattern = Pattern.compile("[A-Za-z0-9]{0,6}");
Matcher passwMatcher = passwPattern.matcher(pw);
return passwMatcher.matches();
}
String email= textField.getText();
//method implementation
private boolean validMail(String email) {
Pattern emailPattern = Pattern.compile(".+@.+\\.[a-z]+");
Matcher emailMatcher = emailPattern.matcher(email);
return emailMatcher.matches();
}
//method calling
if(validMail(email))
JOptionPane.showMessageDialog(rootPane, "email is right");
else
JOptionPane.showMessageDialog(rootPane, "wrong email");
Password
String pw =textField_1.getText();
//method implementation
private boolean validPassword(String pw){
Pattern passwPattern = Pattern.compile("[A-Za-z0-9]{0,6}");
Matcher passwMatcher = passwPattern.matcher(pw);
return passwMatcher.matches();
}
Additional Reference
http://madhuraead.blogspot.com/2014/10/c-currency-converter.htmlmalsha
http://hasangiead.blogspot.com/2014/10/currency-convertor-web-service-client.html
http://itsmalsblog.blogspot.com/2014/10/ejb.html
http://daprogrammer.blogspot.com/2014/10/mongo-db-application-with-crud-op.html
http://muthu-karunarathna.blogspot.com/
http://myeadblog.blogspot.com/
EJB
https://netbeans.org/kb/docs/javaee/javaee-entapp-ejb.html
http://www.service-repository.com/
Webservices
http://daprogrammer.blogspot.com/2014/10/find-country-from-uri.html
Encrypt/Decrypt
http://daprogrammer.blogspot.com/2014/10/encrypt-and-decrypt-text-using-alphabet.html
http://hasangiead.blogspot.com/2014/10/currency-convertor-web-service-client.html
http://itsmalsblog.blogspot.com/2014/10/ejb.html
http://daprogrammer.blogspot.com/2014/10/mongo-db-application-with-crud-op.html
http://muthu-karunarathna.blogspot.com/
http://myeadblog.blogspot.com/
EJB
https://netbeans.org/kb/docs/javaee/javaee-entapp-ejb.html
http://www.service-repository.com/
Webservices
http://daprogrammer.blogspot.com/2014/10/find-country-from-uri.html
Encrypt/Decrypt
http://daprogrammer.blogspot.com/2014/10/encrypt-and-decrypt-text-using-alphabet.html
Tuesday, October 14, 2014
Web Service
Web
Service
Server side
Calculator.java
package web;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
@WebService(serviceName =
"Calculator")
@Stateless()
public class Calculator {
/**
* REMOVE
THE DEFAULT OPERATION, DRAG AND DROP NEWLY CREATED OPERATIONS
*/
@WebMethod(operationName = "add")
public int add(@WebParam(name = "a") int a, @WebParam(name =
"b") int b) {
//TODO write your implementation code here:
return a+b;
}
@WebMethod(operationName = "multi")
public int multi(@WebParam(name = "a") int a, @WebParam(name =
"b") int b) {
//TODO write your implementation code here:
return a*b;
}
}
Client Side
Crate a console client application.
Right click > other > web service
client > add the project
(Before that deploy the web service app)
Pass the values in sever side main method
package calculatorclient;
public class CalculatorClient {
public static void main(String[] args) {
int x = add(10, 5);
System.out.println(x);
}
private static int add(int a, int b) {
web.Calculator_Service service = new web.Calculator_Service();
web.Calculator port = service.getCalculatorPort();
return port.add(a, b);
}
}
//if you use c# application
//Add the wsdl url to sevice reference
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CalculatorWS.CalculatorClient calc = new
CalculatorWS.CalculatorClient();
int x = calc.add(1, 2);
MessageBox.Show(Convert.ToString(x));
}
}
}
WebApplication1
//Server side same
@WebService(serviceName =
"Converter")
@Stateless()
public class Converter {
double celcious = 0.0;
double faran =0.0;
@WebMethod(operationName = "CelciouseToFaranheight")
public double CelciouseToFaranheight(@WebParam(name = "value")
double value) {
//TODO write your implementation code here:
faran =celcious * 1.8 + 32.0;
return faran;
}
}
//Client side
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
double celcious
=Integer.parseInt(jTextField1.getText());
Converter c =new Converter();
double faran
=c.CelciouseToFaranheight(celcious);
jTextField2.setText(String.valueOf(faran));
}
Subscribe to:
Posts (Atom)