Pemrograman Java


————–
Script ini hanya jalan di Internet Explorer
————–

<html>
<head>
</head>
<body bgcolor=”black”>

<body>
<!– file “ani_heart.gif” bisa kamu ganti sendiri terserah –>
<script language=”JavaScript1.2″>

<!– Begin
var no = 12; // number of hearts
var speed = 10; // smaller number moves the hearts faster
var heart = “ani_heart.gif”;
var flag;
var ns4up = (document.layers) ? 1 : 0; // browser sniffer
var ie4up = (document.all) ? 1 : 0;

var dx, xp, yp; // coordinate and position variables
var am, stx, sty; // amplitude and step variables
var i, doc_width = 800, doc_height = 600;
if (ns4up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
} else if (ie4up) {
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx = new Array();
xp = new Array();
yp = new Array();
amx = new Array();
amy = new Array();
stx = new Array();
sty = new Array();
flag = new Array();
for (i = 0; i < no; ++ i) {
dx[i] = 0; // set coordinate variables
xp[i] = Math.random()*(doc_width-30)+10; // set position variables
yp[i] = Math.random()*doc_height;
amy[i] = 12+ Math.random()*20; // set amplitude variables
amx[i] = 10+ Math.random()*40;
stx[i] = 0.02 + Math.random()/10; // set step variables
sty[i] = 0.7 + Math.random(); // set step variables
flag[i] = (Math.random()>0.5)?1:0;
if (ns4up) { // set layers
if (i == 0) {
document.write(“<layer name=\”dot”+ i +”\” left=\”15\” “);
document.write(“top=\”15\” visibility=\”show\”><img src=\””);
document.write(heart+ “\” border=\”0\”></layer>”);
} else {
document.write(“<layer name=\”dot”+ i +”\” left=\”15\” “);
document.write(“top=\”15\” visibility=\”show\”><img src=\””);
document.write(heart+ “\” border=\”0\”></layer>”);
}
} else
if (ie4up) {
if (i == 0) {
document.write(“<div id=\”dot”+ i +”\” style=\”POSITION: “);
document.write(“absolute; Z-INDEX: “+ i +”; VISIBILITY: “);
document.write(“visible; TOP: 15px; LEFT: 15px;\”><img src=\””);
document.write(heart+ “\” border=\”0\”></div>”);
} else {
document.write(“<div id=\”dot”+ i +”\” style=\”POSITION: “);
document.write(“absolute; Z-INDEX: “+ i +”; VISIBILITY: “);
document.write(“visible; TOP: 15px; LEFT: 15px;\”><img src=\””);
document.write(heart+ “\” border=\”0\”></div>”);
}
}
}

function snowNS() { // Netscape main animation function
for (i = 0; i < no; ++ i) { // iterate for every dot
if (yp[i] > doc_height-50) {
xp[i] = 10+ Math.random()*(doc_width-amx[i]-30);
yp[i] = 0;
flag[i]=(Math.random()<0.5)?1:0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
if (flag[i])
dx[i] += stx[i];
else
dx[i] -= stx[i];
if (Math.abs(dx[i]) > Math.PI) {
yp[i]+=Math.abs(amy[i]*dx[i]);
xp[i]+=amx[i]*dx[i];
dx[i]=0;
flag[i]=!flag[i];
}
document.layers[“dot”+i].top = yp[i] + amy[i]*(Math.abs(Math.sin(dx[i])+dx[i]));
document.layers[“dot”+i].left = xp[i] + amx[i]*dx[i];

}
setTimeout(“snowNS()”, speed);
}

function snowIE() { // IE main animation function
for (i = 0; i < no; ++ i) { // iterate for every dot
if (yp[i] > doc_height-50) {
xp[i] = 10+ Math.random()*(doc_width-amx[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
flag[i]=(Math.random()<0.5)?1:0;
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
if (flag[i])
dx[i] += stx[i];
else
dx[i] -= stx[i];
if (Math.abs(dx[i]) > Math.PI) {
yp[i]+=Math.abs(amy[i]*dx[i]);
xp[i]+=amx[i]*dx[i];
dx[i]=0;
flag[i]=!flag[i];
}

document.all[“dot”+i].style.pixelTop = yp[i] + amy[i]*(Math.abs(Math.sin(dx[i])+dx[i]));
document.all[“dot”+i].style.pixelLeft = xp[i] + amx[i]*dx[i];
}
setTimeout(“snowIE()”, speed);
}

if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}
// End –>
</script>
</center>
</body>
</html>

Sumber dari situs Ilmu Website dalam kategori javascript dengan judul Hujan Cinta

Iklan


Script ini hanya jalan di Internet Explorer

<html>
<head>
</head>
<body bgcolor=”#000000″>
<STYLE type=text/css>#supertext {
LEFT: 0px; VISIBILITY: hidden; POSITION: absolute; TOP: 0px
}
</STYLE>

<SCRIPT language=JavaScript1.2>

//Configure the below three variables

//1) Set message to display (HTML accepted)
var thecontent='<h2><font face=”Courier New” font size=”5″ color=”#00FF00″>ilmuwebsite.com – Webmaster Resource</font></h2>’
//2) Set delay after which message should be hidden, in miliseconds (” makes it incessantly visible on the screen)
var hidetimer=”;
//3) Set speed of animation (1-50), where larger is faster
var BallSpeed = 20;

///NO NEED TO EDIT BELOW THIS LINE///////////

var contentWidth;
var contentHeight;
var maxBallSpeed = 50;

var xMax;
var yMax;
var xPos = 0;
var yPos = 0;
var xDir = ‘right’;
var yDir = ‘down’;
var superballRunning = true;
var tempBallSpeed;
var currentBallSrc;
var newXDir;
var newYDir;

function initializeBall() {
if (document.all) {
xMax = document.body.clientWidth
yMax = document.body.clientHeight
document.all(“supertext”).style.visibility = “visible”;
contentWidth=supertext.offsetWidth
contentHeight=supertext.offsetHeight
}
else if (document.layers) {
xMax = window.innerWidth;
yMax = window.innerHeight;
contentWidth=document.supertext.document.width
contentHeight=document.supertext.document.height
document.layers[“supertext”].visibility = “show”;
}
setTimeout(‘moveBall()’,400);
if (hidetimer!=”)
setTimeout(“hidetext()”,hidetimer)
}

function moveBall() {
if (superballRunning == true) {
calculatePosition();
if (document.all) {
document.all(“supertext”).style.left = xPos + document.body.scrollLeft;
document.all(“supertext”).style.top = yPos + document.body.scrollTop;
}
else if (document.layers) {
document.layers[“supertext”].left = xPos + pageXOffset;
document.layers[“supertext”].top = yPos + pageYOffset;
}
animatetext=setTimeout(‘moveBall()’,20);
}
}

function calculatePosition() {
if (xDir == “right”) {
if (xPos > (xMax – contentWidth – BallSpeed)) {
xDir = “left”;
}
}
else if (xDir == “left”) {
if (xPos < (0 + BallSpeed)) {
xDir = “right”;
}
}
if (yDir == “down”) {
if (yPos > (yMax – contentHeight – BallSpeed)) {
yDir = “up”;
}
}
else if (yDir == “up”) {
if (yPos < (0 + BallSpeed)) {
yDir = “down”;
}
}
if (xDir == “right”) {
xPos = xPos + BallSpeed;
}
else if (xDir == “left”) {
xPos = xPos – BallSpeed;
}
else {
xPos = xPos;
}
if (yDir == “down”) {
yPos = yPos + BallSpeed;
}
else if (yDir == “up”) {
yPos = yPos – BallSpeed;
}
else {
yPos = yPos;
}
}

function hidetext(){
if (document.all)
supertext.style.visibility=”hidden”
else if (document.layers)
document.supertext.visibility=”hide”
clearTimeout(animatetext)
}

if (document.all||document.layers){
document.write(‘<span id=”supertext”><nobr>’+thecontent+'</nobr></span>’)
window.onload = initializeBall;
window.onresize = new Function(“window.location.reload()”);
}

</SCRIPT>

(lebih…)

Dalam membuat program, ada kalanya kita ingin agar data yang diinput tidak salah. Teknik Validasi yang anda terapkan pun, misalnya validasi nama tidak boleh angka terkadang tidak maksimal. Kalau misalnya kita salah mengetik nama “Ivan” dengan “Ivam”, pasti nama akan lansung tersimpan bukan? Bukan hanya itu, biasanya seorang user tidak sengaja menekan tombol “enter”. Padahal belum selesai mengetik. Ada cara untuk mengatasi hal diatas, yakni dengan membuat pertanyaan konfirmasi. Pertanyaan konfirmasi berfungsi untuk menampilkan pertanyaan “ok” dan “cancel”. Ini untuk memastikan apakah data yang diinput sudah benar dengan melakukan pengecekan ulang.

Pertanyaan konfirmasi sepeti diatas dapat dibuat dengan javascript.

Buat file dengan nama pertanyaan.js lalu ketikkan script berikut :

pertanyaan.js

function pertanyaan()
{
if(confirm(‘Anda yakin yang ingin anda posting ini sudah benar?’))
{
return true;
}
else
{
return false;
}
}

index.html

<html>
<body>
<script language=”javascript” src=”pertanyaan.js”></script>
<a href=# onclick=”return pertanyaan ()”>Tes membuat pertanyaan…..</a>
</body>
</html>

Sedikit Penjelasan kode diatas :

Pada pertanyaan.js, dibuatkan perintah confirm untuk menampilkan kotak pesan ok dan cancel. Karena menggunakan function, kita gunakan return TRUE jika benar dan return FALSE jika salah. Lalu pada bagian yang ingin dimunculkan pertanyaan, tambahkan perintah onclick. Maksudnya ketika diklik,event apa yang terjadi.

Yah, sekian dulu lah penjelasan dari saya. Silahkan download sourcenya Disini