if(window.XMLHttpRequest)//non IE
{
req = new XMLHttpRequest();
try
{
req.open("GET",url,true);
req.onreadystatechange=setInTextField;
}
catch(e)
{
alert("cannot connect to server");
}
req.send(null);
}
else if(window.ActiveXObject)//IE
{
try
{
req=new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
catch(e)
{
req=new ActiveXObject("Microsoft.XMLHTTP");
}
if(req)
{
req.open("GET",url,true);
req.onreadystatechange=setInTextField;
req.send(null);
}
}
Search Your Question
Monday, August 10, 2009
Friday, July 24, 2009
Tuesday, July 21, 2009
JavaScript Text Field formatter for input money
function moneyonly(e)
{
var unicode=e.charCode? e.charCode : e.keyCode;
var st = document.getElementById("amount").value;
//alert(unicode)
if (unicode== 8)
{
return true;
//if the key isn't the backspace key (which we should allow)
}
else if(unicode == 46)
{
if(st.toString().indexOf(".",0) != -1)
{
return false;
}
}
else if (unicode<48||unicode>57) //if not a number
{
return false //disable key press
}
else if(st.toString().indexOf(".",0) != -1)
{
if(st.toString().length - st.toString().indexOf(".",0) > 2)
{
return false;
}
}
return true;
}
{
var unicode=e.charCode? e.charCode : e.keyCode;
var st = document.getElementById("amount").value;
//alert(unicode)
if (unicode== 8)
{
return true;
//if the key isn't the backspace key (which we should allow)
}
else if(unicode == 46)
{
if(st.toString().indexOf(".",0) != -1)
{
return false;
}
}
else if (unicode<48||unicode>57) //if not a number
{
return false //disable key press
}
else if(st.toString().indexOf(".",0) != -1)
{
if(st.toString().length - st.toString().indexOf(".",0) > 2)
{
return false;
}
}
return true;
}
Trim function in JavaScript
function trimThis(value1)
{
value1= value1.replace(/^\s+|\s+$/, '');
return value1;
}
{
value1= value1.replace(/^\s+|\s+$/, '');
return value1;
}
Friday, June 5, 2009
Set Image Background in a JPanel
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.swing.*;
public class BackgroundImage {
public static void main(String[] args) throws IOException {
BufferedImage image = javax.imageio.ImageIO.read(new File("C:\\WINDOWS\\Web\\Wallpaper\\Azul.jpg"));
ImageBackgroundPanel imp = new ImageBackgroundPanel(image);
// Set layout and add components to imp as desired.
JFrame f = new JFrame();
JTextField txtField=new JTextField(20);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(imp);
imp.add(txtField);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
class ImageBackgroundPanel extends JPanel {
BufferedImage image;
ImageBackgroundPanel(BufferedImage image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
}
}
import java.awt.image.BufferedImage;
import java.io.*;
import javax.swing.*;
public class BackgroundImage {
public static void main(String[] args) throws IOException {
BufferedImage image = javax.imageio.ImageIO.read(new File("C:\\WINDOWS\\Web\\Wallpaper\\Azul.jpg"));
ImageBackgroundPanel imp = new ImageBackgroundPanel(image);
// Set layout and add components to imp as desired.
JFrame f = new JFrame();
JTextField txtField=new JTextField(20);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(imp);
imp.add(txtField);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
class ImageBackgroundPanel extends JPanel {
BufferedImage image;
ImageBackgroundPanel(BufferedImage image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
}
}
Subscribe to:
Posts (Atom)