Multi Threading Java
contoh thread di java, ...\\
lanjut sob...
/*
* Author : Fandy Adam
* Email : fandy_alfa@yahoo.com
* Email : casperadam91@gmail.com
* Blog : fandy-alfa.blogspot.com
* IDE : netbeans 7.1.x
* NOTEBOOK ACER ASPIRE 4738
*/
package app.imageprocessing.thread;
import java.awt.image.BufferedImage;
/**
*
* @author Fandy
*/
public class MyThread implements Runnable{
private BufferedImage image;
private int x;
private app.imageprocessing.thread.ImagePanel panel;
public MyThread(BufferedImage image, int x, app.imageprocessing.thread.ImagePanel panel) {
this.image = image;
this.x = x;
this.panel = panel;
}
public void run() {
int y=0;
while (y < image.getHeight()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) { }
panel.setYellow(x, y);
y++;
}
}
}
lanjut sob...
/*
* Author : Fandy Adam
* Email : fandy_alfa@yahoo.com
* Email : casperadam91@gmail.com
* Blog : fandy-alfa.blogspot.com
* IDE : netbeans 7.1.x
* NOTEBOOK ACER ASPIRE 4738
*/
package app.imageprocessing.thread;
import java.awt.image.BufferedImage;
/**
*
* @author Fandy
*/
public class MyThread implements Runnable{
private BufferedImage image;
private int x;
private app.imageprocessing.thread.ImagePanel panel;
public MyThread(BufferedImage image, int x, app.imageprocessing.thread.ImagePanel panel) {
this.image = image;
this.x = x;
this.panel = panel;
}
public void run() {
int y=0;
while (y < image.getHeight()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) { }
panel.setYellow(x, y);
y++;
}
}
}
List File dan Folder dari Komputer
Labels:
kumpulan program java,
tutorial
iseng wae....
buat program untuk mengambil list folder dan file dari komputer kita....
jadi sy buat dengan menggunakan java.io
so, langsung aja ke 'tkp ...'
public class ListFiles {
public static void main(String[] args) {
java.io.File listroot = new java.io.File("d:/");
java.io.File[] files = listroot.listFiles();
System.out.println("Print root files from c:");
for (java.io.File file : files) {
System.out.println(file.getPath());
}
}
}
buat program untuk mengambil list folder dan file dari komputer kita....
jadi sy buat dengan menggunakan java.io
so, langsung aja ke 'tkp ...'
public class ListFiles {
public static void main(String[] args) {
java.io.File listroot = new java.io.File("d:/");
java.io.File[] files = listroot.listFiles();
System.out.println("Print root files from c:");
for (java.io.File file : files) {
System.out.println(file.getPath());
}
}
}
konversi bilanagan
Labels:
kumpulan program java,
tutorial
setelah sekian lama tdak posting akhirnya punya kesemapatan untuk posting, tp kali ini sy akan memposting program java sederhana, ... he3x
program ini bertujuan untuk mengkonversikan bilangan dari desimal ke biner, desimal ke oktal, desimal ke hexadesimal; dengan menggunakan input dari keyboard
import java.io.*;
import java.util.*;
public class konversi_bilangan {
private String input="";
private int des=0;
private int value;
private int [] bin = new int[100];
private int [] oktal = new int[100];
private String [] hex = {"1","2","3","4","5","6","7","8","9","A","B",
"C","D","E","F"} ;
public static void main (String[] args) throws IOException {
BufferedReader stdin =
new BufferedReader (new InputStreamReader(System.in));
Scanner buffer = new Scanner(System.in);
System.out.println("PROGRAM KONVERSI BILANGAN");
System.out.println("=========================\n");
System.out.println("1. DESIMAL KE BINER");
System.out.println("2. DESIMAL KE OKTAL");
System.out.println("3. DESIMAL KE HEXADESIMAL");
System.out.print("Masukkan pilihan : ");
int pilih = buffer.nextInt();
switch (pilih) {
case 1 : value = 2; break;
case 2 : value = 8; break;
case 3 : value = 16; break;
default : System.out.println("pilihan tidak ada"); return;
}
System.out.print(value+"Masukkan input : ");
input = stdin.readLine();
des = Integer.parseInt(input);
System.out.print("\nHASIL KONVERSI : ");
int j=0;
for (int i=des; i>0; i=i/value) {
bin[j]=i%value;
j++;
}
j=j-1;
while (j>=0) {
if(bin[j]<10)
System.out.print(bin[j]);
else if(bin[j]==10)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==11)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==12)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==13)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==14)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==15)
System.out.print(hex[bin[j]-1]);
j--;
}
}
}
program ini bertujuan untuk mengkonversikan bilangan dari desimal ke biner, desimal ke oktal, desimal ke hexadesimal; dengan menggunakan input dari keyboard
import java.io.*;
import java.util.*;
public class konversi_bilangan {
private String input="";
private int des=0;
private int value;
private int [] bin = new int[100];
private int [] oktal = new int[100];
private String [] hex = {"1","2","3","4","5","6","7","8","9","A","B",
"C","D","E","F"} ;
public static void main (String[] args) throws IOException {
BufferedReader stdin =
new BufferedReader (new InputStreamReader(System.in));
Scanner buffer = new Scanner(System.in);
System.out.println("PROGRAM KONVERSI BILANGAN");
System.out.println("=========================\n");
System.out.println("1. DESIMAL KE BINER");
System.out.println("2. DESIMAL KE OKTAL");
System.out.println("3. DESIMAL KE HEXADESIMAL");
System.out.print("Masukkan pilihan : ");
int pilih = buffer.nextInt();
switch (pilih) {
case 1 : value = 2; break;
case 2 : value = 8; break;
case 3 : value = 16; break;
default : System.out.println("pilihan tidak ada"); return;
}
System.out.print(value+"Masukkan input : ");
input = stdin.readLine();
des = Integer.parseInt(input);
System.out.print("\nHASIL KONVERSI : ");
int j=0;
for (int i=des; i>0; i=i/value) {
bin[j]=i%value;
j++;
}
j=j-1;
while (j>=0) {
if(bin[j]<10)
System.out.print(bin[j]);
else if(bin[j]==10)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==11)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==12)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==13)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==14)
System.out.print(hex[bin[j]-1]);
else if(bin[j]==15)
System.out.print(hex[bin[j]-1]);
j--;
}
}
}
Subscribe to:
Posts (Atom)





