Sabtu, 16 Juli 2011

program CountUp Dengan Java


Berikut ini merupakan source code program CountUp dengan java, kalo biasanya CountDown. kalo ini countUp ..coba di run sendiri aja deh hasilnya kayak apa ...


import javax.swing.*;
import java.awt.*;
class CountDownGUI extends JFrame{
    JLabel label;
    CountDownGUI(String title){
        super(title);
        label=new JLabel("Start count!");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().add(new Panel(), BorderLayout.WEST); 
        getContentPane().add(label);
        setSize(300,300);
        setVisible(true);
        
    } 
void startCount(){
    try {
        for (int i=0; i<5000; i++){
            Thread.sleep(1000);
            label.setText(i+"");
            
        }
    Thread.sleep(1000);
    label.setText("Count down complete.");
    Thread.sleep(1000);
    }
    catch(InterruptedException ie){
    }
    label.setText(Thread.currentThread().toString());
}
public static void main(String args[]){
    CountDownGUI cdg=new CountDownGUI("Count down GUI");
    cdg.startCount();
    }
} 

Selengkapnya...

Program Operasi Matriks dengan Java

teman-teman udah lama gak posting jadi kengen sama blog ini(kayak pacar aja)
kali ini sy ingin posting program java operasi matriks, dimana pada program ini kita bisa melakukan perkalian 2 buah matriks dan Transpose ke-2 buah matriks tersebut. langsung aja ini source code programnya :

import javax.swing.*;

class operasimatrik {
public static void main(String[] args) {
System.out.println("********** Matriks **********\n");
int baris = Integer.parseInt(JOptionPane.showInputDialog(null,"Masukkan Jumlah Baris : ",2));
int kolom = Integer.parseInt(JOptionPane.showInputDialog(null,"Masukkan Jumlah Kolom : ",2));
int A[][]=new int [baris][kolom];
int B[][]=new int [baris][kolom];
int C[][]=new int [baris][kolom];
int D[][]=new int [baris][kolom];

do{
int pil=Integer.parseInt(JOptionPane.showInputDialog("PROGRAM MATRIK \n\n1. Inputan Matrik \n2. Perkalian Matrik A x B \n3. Perkalian Matrik B x A\n4. Transpose Matrik A \n5. Tranpose Matrik B \n6. Exit"));

switch(pil){ 
case 1:
//Matrik A
System.out.println("Matriks A");
for (int i=0;i<baris;i++){
  System.out.print(" | ");
  for (int j=0;j<kolom;j++){
    A[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"Masukkan Matriks A ["+(i+1)+","+(j+1)+"]"));
    System.out.print(" "+A[i][j]+" ");
    }
  System.out.println(" | ");
}
//Matrik B
System.out.println("\nMatriks B");
for (int i=0;i<baris;i++){
  System.out.print(" | ");
  for (int j=0;j<kolom;j++){
    B[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"Masukkan Matriks B ["+(i+1)+","+(j+1)+"]"));
    System.out.print(" "+B[i][j]+" ");
    }
  System.out.println(" | ");
}
continue;

case 2:
//Perkalian antar matrik
System.out.println("\nMatriks Perkalian");
for (int i=0;i<baris;i++){
  System.out.print(" | ");
  for (int j=0;j<kolom;j++){
    for (int k=0;k<baris;k++){
      C[i][j] = C[i][j]+(A[i][k]*B[k][j]) ;
    }
    System.out.print(" "+C[i][j]+" ");
  }
  System.out.println(" | ");
}
continue;

case 3:
//Perkalian antar matrik
System.out.println("\nMatriks Perkalian");
for (int i=0;i<baris;i++){
  System.out.print(" | ");
  for (int j=0;j<kolom;j++){
    for (int k=0;k<baris;k++){
      D[i][j] = D[i][j]+(B[i][k]*A[k][j]);
    }
    System.out.print(" "+D[i][j]+" ");
  }
  System.out.println(" | ");
}
continue;


case 4:
//Tranpose Matrik A
System.out.println("\nMatriks A Transpose");
for (int i=0;i<baris;i++){
  System.out.print(" | ");
  for (int j=0;j<kolom;j++){
    System.out.print(" "+A[j][i]+" ");
    }
  System.out.println(" | ");
}
continue;
case 5:
//Tranpose Matrik B
System.out.println("\nMatriks B Transpose");
for (int i=0;i<baris;i++){
  System.out.print(" | ");
  for (int j=0;j<kolom;j++){
    System.out.print(" "+B[j][i]+" ");
    }
  System.out.println(" | ");
}
continue;

case 6:System.exit(0);

default: JOptionPane.showMessageDialog(null,"Salah masukkan PILIHAN", "deFauLt", JOptionPane.INFORMATION_MESSAGE);
continue;
}

}while(JOptionPane.showConfirmDialog(null,"Mau hitung ulang lagi?")==JOptionPane.YES_OPTION);
System.exit(0);
}
}

gimana? keren khan?
Selengkapnya...

konversi StringBuffer ke String

class StringBufferClass{
    public static void main(String args[]){
        StringBuffer sb1= new StringBuffer("MATA KULIAH ");
        StringBuffer sb2= new StringBuffer();
        StringBuffer sb3= new StringBuffer();
        sb2.append("JAVA PROGRAMMING");

        System.out.println("sb1  = "+sb1);
        System.out.println("sb2  = "+sb2);
        System.out.println();
        System.out.println("sb3 = sb1 digabung dengan sb2");
        sb3.append(sb1);
        sb3.append(sb2);
        System.out.println("sb3  = "+sb3);

        System.out.println();
        System.out.println("Sisipkan String CORE pada sb3");
        sb3.insert(12,"CORE ");
        System.out.println("sb3  = "+sb3);
        System.out.println("Panjang = "+sb3.length());


        System.out.println();
        System.out.println("Hapus String dari StringBuffer");
        sb3.delete(12,17);
        System.out.println("sb3  = "+sb3);
        System.out.println("Panjang = "+sb3.length());

        System.out.println();
        System.out.println("Hapus Karakter dari StringBuffer");
        sb3.deleteCharAt(12);
        System.out.println("sb3  = "+sb3);
        System.out.println("Panjang = "+sb3.length());

        System.out.println();
        System.out.println("Koversi StringBuffer ke String");
        String Str = sb3.toString();
        System.out.println("Str  = "+Str);
        System.out.println("Panjang = "+Str.length());






    }
}

sekian, silahkan beri masukkan ,salam informatika

Selengkapnya...

 

© free template by Blogspot tutorial

" Blog Pelajar yang selalu ingin belajar "