Tampilkan postingan dengan label SOURCE CODE JAVA. Tampilkan semua postingan
Tampilkan postingan dengan label SOURCE CODE JAVA. Tampilkan semua postingan

Senin, 12 November 2012

Source Code Java: Invers Matriks


package rpl;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author at-yk
 */
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStream;

public class invers_matriks {

    public static void main(String[] ziah) throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int temp;
        System.out.println("======INVERS MATRIKS======");
        System.out.println("ordo matriks 2X2");
        int[][] matriks = new int[2][2];
        System.out.println("masukkan elemen matriksnya");
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                System.out.println("elemen[" + (i + 1) + "," + (j + 1) + "]=");
                matriks[i][j] = Integer.parseInt(input.readLine());
            }
        }
        System.out.println("\n Matriksnya");
        for (int i = 0; i < 2; i++) {
            System.out.println("|");
            for (int j = 0; j < 2; j++) {
                System.out.println(matriks[i][j] + " ");
            }
            System.out.println("|");
        }
        int dtr = (matriks[0][0] * matriks[1][1] - (matriks[1][0] * matriks[0][1]));
        System.out.println("\n Determinannya=" + dtr);
        temp = matriks[0][0];
        matriks[0][0] = matriks[1][1];
        matriks[1][1] = temp;
        matriks[0][1] = matriks[0][1] * -1;
        matriks[1][0] = matriks[1][0] * -1;
        System.out.println("\n matriks Adjoin");
        for (int i = 0; i < 2; i++) {
            System.out.print("|");
            for (int j = 0; j < 2; j++) {
                System.out.print(matriks[i][j] + "");
            }
            System.out.println("|");

        }
        System.out.println("\n Matriks inversnya: ");
        for (int i = 0; i < 2; i++) {
            System.out.print("|");
            for (int j = 0; j < 2; j++) {
                System.out.print(matriks[i][j] + "/" + dtr + "");
            }
            System.out.println("|");
        }

    }
}

Source Code Java : Perkalian Matriks

untuk dot javanya bisa di download disini 


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rpl;

/**
 *
 * @author Acer
 */
import javax.swing.JOptionPane;
public class PERKALIANMATRIKS {
    public static void main(String [] args){
           int barisA=Integer.valueOf(JOptionPane.showInputDialog(null,"masukan jumlah baris Matriks A ->> "," "));
            int kolomA=Integer.valueOf(JOptionPane.showInputDialog(null,"masukan jumlah kolom Matriks A ->> "," "));

            System.out.print("untuk matriks A\n");
            int matrikA[][]=new int[barisA][kolomA];
            for (int i=0; i<barisA; i++ ){
                System.out.print("|");
                    for (int j=0; j<kolomA;j++ ){
                        matrikA[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"nilai matrik A baris ke "+(i+1) + " kolom ke " +(j+1)+" : "," "));
System.out.print(" "+matrikA[i][j]+" ");
                    }
System.out.println("|");
                }
            int barisB=Integer.valueOf(JOptionPane.showInputDialog(null,"masukan jumlah baris Matriks B ->> "," "));
            int kolomB=Integer.valueOf(JOptionPane.showInputDialog(null,"masukan jumlah kolom Matriks B ->> "," "));

            System.out.print("untuk matriks B\n");
            int matrikB[][]=new int[barisB][kolomB];
            for (int i=0; i<barisB; i++ ){
                System.out.print("|");
                    for (int j=0; j<kolomB;j++ ){
                        matrikB[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"nilai matrik B baris ke "+(i+1) + " kolom ke " +(j+1)+" : "," "));
                        System.out.print(" "+matrikB[i][j]+" ");
}
            System.out.println("|");
            }

            //syarat untuk perkalian kolom matrik A harus sama dengan baris matrik B
            if(matrikA[0].length==matrikB.length){
                int matrikhasil[][] = new int[matrikA.length][matrikB.length];
                perkalian(matrikA,matrikB,matrikhasil);
                lihat(matrikhasil);
            }
            else{
                System.out.println("jumlah kolom matrikA tidak sama dengan baris matrikB");
            }
        }
     public static void perkalian(int A[][],int B[][], int C[][]){
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < B[i].length; j++) {
                for (int k = 0; k < A[i].length; k++) {
                    C[i][j]+=A[i][k]*B[k][j];
                }
            }

        }
    }


          public static void lihat(int C[][]){
        System.out.println("Hasil matrik");
        for(int i=0; i<C.length; i++){
            System.out.print("|");
            for(int j=0; j<C[0].length; j++){

                System.out.print(" " + C[i][j] + " ");
            }
            System.out.println("|");
        }
    }
    }



Source Code Java :perkalian Matriks dengan skalar *part 2

postingan kali ini melengkapi yang di bawahnya ya guys.. yg ini langsung download dan langsung drag ke netben atau compilernya.. file . javanya bisa d download disini ^_^

Source Code Java: Perkalian Matriks Dengan Skalar


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Acer
 * import javax.swing.JOptionPane;
 */
import javax.swing.JOptionPane;
public class matriks_skalar {
    public static void main(String[] args){
        int skalar= Integer.valueOf(JOptionPane.showInputDialog("masukan  bilangan skalar:"));
        int barisA= Integer.valueOf(JOptionPane.showInputDialog("masukan baris matrik A :"));
        int kolomA= Integer.valueOf(JOptionPane.showInputDialog("masukan kolom matrik A :"));
        int matrikA[][]= new int[barisA][kolomA];
             System.out.println("bilangan skalar = "+skalar);
             System.out.println("matrikA");
             for(int i=0; i<matrikA.length; i++){
                 System.out.print("|");
                    for(int j=0; j<matrikA[i].length; j++){
                        matrikA[i][j]= Integer.parseInt(JOptionPane.showInputDialog("masukan nilai untuk matrik A :"));
                        System.out.print(" "+matrikA[i][j]+" ");

                    }
            System.out.println("|");
            }
        int hasil[][]= new int[barisA][kolomA];
        perkalianSkalar(skalar,matrikA,hasil);
        show(hasil);
    }
      public static void perkalianSkalar(int skalar,int B[][],int C[][]){
        for(int i=0;i<B.length;i++){
            for(int j=0;j<B[i].length;j++){
                C[i][j]= skalar*B[i][j];
            }
        }
    }
       public static void show(int C[][]){
        System.out.println("Hasil matrik");
        for(int i=0; i<C.length; i++){
            System.out.print("|");
            for(int j=0; j<C[0].length; j++){

                System.out.print(" " + C[i][j] + " ");
            }
            System.out.println("|");
        }
    }
    }



Jumat, 09 November 2012

SOURCE CODE JAVA PENJUMLAHAN MATRIKS

Back to Materi kuliah .. ini source code java penjumlahan matriks.. ekstensinya udah dot java.. bisa di download disini

Rabu, 27 Juni 2012

SOURCE CODE UTS JAVA 12345 54321


output

run:
54321
xx*xx
xx3xx
xx*xx
12345
BUILD SUCCESSFUL (total time: 0 seconds)



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package buroro;

/**
 *
 * @author Masiti
 */
public class belajar {

    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 5; j >= 1; j--) {
                if (i == 1) {
                    System.out.print(j);
                }
                if (i == 2) {
                    if (j == 3) {
                        System.out.print("*");
                    } else {
                        System.out.print("x");
                    }
                }
                if (i == 3) {
                    if (j == 3) {
                        System.out.print("3");

                    } else {
                        System.out.print("x");
                    }

                }
                if (i == 4) {
                    if (j == 3) {
                        System.out.print("*");
                    } else {
                        System.out.print("x");
                    }


                }
                if (i == 5) {
                    for (int k = 1; k <= 5; k++) {
                        System.out.print(k);

                    }
                    break;
                }
            }
            System.out.println(" ");
        }


    }
}

Minggu, 24 Juni 2012

CONTOH SOURCE CODE ARRAY 1

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package array_buroro;

/**
 *
 * @author Masiti
 */
public class ARRAYSEARC {

    public static void main(String[] args) {
        int[] a = {3, 5, 6, 2, 4, 8, 9};
        for (int i = 0; i <= a.length - 1; i++) {
            if ((a[i] % 2) == 0) {
                System.out.println("even");
            } else {
                System.out.println("odd");
            }

        }

    }
}

SOURCE CODE BINTANG 1


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uts;

/**
 *
 * @author Masiti
 */
public class SOAL_3 {
    public static void main(String[] args) {
       
         for(int i=1;i<=5;i++){
            for(int j=1;j<=6-i;j++){
                System.out.print("*");
            }
            for(int k=1;k<=i;k++){
                System.out.print(" ");
            }
            for(int l=1;l<=i;l++){
                System.out.print("*");
            }
           System.out.println("  ");
        }
    }}


outputnya:

run:
***** *
****  **
***   ***
**    ****
*     *****
BUILD SUCCESSFUL (total time: 1 second)




Jumat, 22 Juni 2012

SOURCE CODE QUICK SORT





/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sorting;

/**
 *
 * @author Acer
 */


public class quicksort{
  public static void main(String a[]){
  int i;
  int array[] = {12,9,4,99,120,1,3,10,13};


  System.out.println(" Quick Sort\n\n");
  System.out.println("Values Before the sort:\n");
  for(i = 0; i < array.length; i++)
  System.out.print( array[i]+"  ");
  System.out.println();
  quick_srt(array,0,array.length-1);
  System.out.print("Values after the sort:\n");
  for(i = 0; i <array.length; i++)
  System.out.print(array[i]+"  ");
  System.out.println();
  System.out.println("PAUSE");
  }

  public static void quick_srt(int array[],int low, int n){
  int lo = low;
  int hi = n;
  if (lo >= n) {
  return;
  }
  int mid = array[(lo + hi) / 2];
  while (lo < hi) {
  while (lo<hi && array[lo] < mid) {
  lo++;
  }
  while (lo<hi && array[hi] > mid) {
  hi--;
  }
  if (lo < hi) {
  int T = array[lo];
  array[lo] = array[hi];
  array[hi] = T;
  }
  }
  if (hi < lo) {
  int T = hi;
  hi = lo;
  lo = T;
  }
  quick_srt(array, low, lo);
  quick_srt(array, lo == low ? lo+1 : lo, n);
  }
}

SOURCE CODE FIBONACCI


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uts_buroro;

import javax.swing.JOptionPane;

/**
 *
 * @author Masiti
 */
public class fibonacci {
public static void main(String[]args){
    int n=Integer.parseInt(JOptionPane.showInputDialog("input suku ke-n:"));
    int a=0;
    int b=1;
    for(int i=0;i<n;i++){
        a=a+b;
        b=a-b;
        System.out.print(" "+a);
    }
}
}

SOURCE CODE HEAP SORT


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sorting;

/**
 *
 * @author Acer
 */

    /**
 * For any element, i, in a list of size n, the following is true:
 *    -Parent element index = i/2 (floor(i))
 *    -Left child element index = 2i
 *    -Right child element index = 2i + 1
 */

import java.util.*;
import java.lang.*;


public class heapsort {
    private static int count;
    private static int search;
    public static void main(String a[]) {
        int i;
        int arr[] = {20, 29, 7, 3, 31, 2, 5, 11, 9, 17};
        System.out.println("Unsorted Array\n---------------");
        for (i = 0; i < arr.length; i++) {
            System.out.print(" " + arr[i]);
        }
        for (i = arr.length; i > 1; i--) {
            HeapSort(arr, i - 1);
        }
        System.out.println("\nSorted array\n---------------");
        for (i = 0; i < arr.length; i++) {
            System.out.print(" " + arr[i]);
        }
        System.out.println("\n");
        System.out.println("Data sorted after " + count + " times swapping");
        System.out.println("Data sorted after " + search + " searching");
    }
    public static int HeapSort(int array[], int arr_ubound) {
        int i, j;
        int lChild, rChild, mChild, root, temp;
        root = (arr_ubound - 1) / 2;
        for (j = root; j >= 0; j--) {
            for (i = root; i >= 0; i--) {
                lChild = (2 * i) + 1;
                rChild = (2 * i) + 2;
                if ((lChild <= arr_ubound) && (rChild <= arr_ubound)) {
                    if (array[rChild] >= array[lChild]) {
                        mChild = rChild;
                    } else {
                        mChild = lChild;
                    }
                } else {
                    if (rChild > arr_ubound) {
                        mChild = lChild;
                    } else {
                        mChild = rChild;
                    }
                }
                if (array[i] < array[mChild]) {
                    temp = array[i];
                    array[i] = array[mChild];
                    array[mChild] = temp;
                }
            }
            count++;
        }
        search++;
        temp = array[0];
        array[0] = array[arr_ubound];
        array[arr_ubound] = temp;
        return count;
    }
}

SOURCE CODE SELECTION SORT


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sorting;

/**
 *
 * @author Masiti
 */
public class selection {
    static int kelompok1;

    public static void main(String a[]) {
        int i;
        int array[] = {20, 29, 7, 3, 31, 2, 5, 11, 9, 17};

        //sebelum sorting
        System.out.println("Values BEFORE sorting:");
        for (i = 0; i < array.length; i++) {
            System.out.print(array[i] + "  ");
        }
        System.out.println();

        //pemanggilan method selection_sort
        selection_srt(array, array.length);
        //setelah sorting
        System.out.print("\nValues AFTER sorting:\n");
        for (i = 0; i < array.length; i++) {
            System.out.print(array[i] + "  ");
        }
        System.out.println();
     

        System.out.println("Data sorted after "+kelompok1+" times swapping");
    }

    public static int selection_srt(int a[], int n) {
        int temp = 0, count = 0;

        for (int i = 0; i < n; i++) {
            int min = a[i];
            for (int j =i+ 1; j < n ; j++) {
                if (a[j] < a[i]) {
                    min=a[i];
                    temp = min;
                    a[i] = a[j];
                    a[j] = temp;
                    count++;
                    kelompok1=count;
                }
            }
        }
return count;
    }
}

SOURCE CODE MERGE SORT


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sorting;

/**
 *
 * @author Masiti
 */
public class merge {

    static int swap;
    static int cari;

    public static void main(String[] args) {
        int i;
        int array[] = {20, 29, 7, 3, 31, 2, 5, 11, 9, 17};
        System.out.print("nilai sebelum:\n");
        for (i = 0; i < array.length; i++) {
            System.out.print(array[i] + "  ");
        }
        System.out.println();
        mergeSort_srt(array,array.length);
        System.out.print("setelah sorting:\n");
        for (i = 0; i < array.length; i++) {
            System.out.print(array[i] + "  ");
        }
        System.out.println();
        int temp = 0;
        int n = array.length;
        int count = 0;
        for (int a = 0; a < n; a++) {
            for (int j = 1; j < (n - a); j++) {
                if (array[j - 1] > array[j]) {
                    temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    count++;
                }
            }
        }
        System.out.println();
        System.out.println("Data sorted after " + swap + " times swapping");
        System.out.println("Data sorted after " + cari + " searching");
    }

    public static int mergeSort_srt(int a[], int n) {
        int search = 0;
        int temp = 0, count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < (n - i); j++) {
                if (a[j - 1] > a[j]) {
                    temp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = temp;
                    count++;
                    swap = count;

                }
                else{
                    search++;
                    cari = search;
                }
     
            }

        }

        return count;
    }

    public static void mergeSort_srt(
            int array[], int lo, int n) {
        int low = lo;
        int high = n;
        if (low >= high) {
            return;
        }

        int middle = (low + high) / 2;
        mergeSort_srt(array, low, middle);
        mergeSort_srt(array, middle + 1, high);
        int end_low = middle;
        int start_high = middle + 1;
        while ((lo <= end_low) && (start_high <= high)) {
            if (array[low] < array[start_high]) {
                low++;
            } else {
                int Temp = array[start_high];
                for (int k = start_high - 1; k >= low; k--) {
                    array[k + 1] = array[k];
                }
                array[low] = Temp;
                low++;
                end_low++;
                start_high++;
            }
        }
    }
}

JAVA OUTPUT 12345


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uts_buroro;

/**
 *
 * @author Masiti
 */
public class mm {
public static void main(String[] args){
    for (int i = 1; i >=5; i--) {
        for (int j = 0; j < 10; j++) {

        }
        System.out.print(i);

    }

 
}
}

JAVA OUTPUT 54321


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uts_buroro;

/**
 *
 * @author Masiti
 */
public class mm {
public static void main(String[] args){
    for (int i = 5; i >=1; i--) {
        for (int j = 0; j < 10; j++) {

        }
        System.out.print(i);

    }

 
}
}



Jumat, 15 Juni 2012

PROGRAM COMBO BOX


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author M@siti
// */
//import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.*;
import java.awt.font.*;
//import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class hitung_gizi2 extends JFrame {

    String mak_pokok[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
    JComboBox cb_pokok = new JComboBox(mak_pokok);
    String nabati[] = {"bayam", "Kelor", "sawi"};
    JComboBox cb_nabati = new JComboBox(nabati);
    String hewani[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
    JComboBox cb_hewani = new JComboBox(hewani);
    String sayur[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
    JComboBox cb_sayur = new JComboBox(sayur);
    String buah[] = {"Nasi Putih", "Nasi Kuning", "Nasi Jagung"};
    JComboBox cb_buah = new JComboBox(buah);
    JLabel lbl_judul = new JLabel("HITUNG GIZI");
    JLabel lbl_pokok = new JLabel("Makanan Pokok");
    JLabel lbl_nabati = new JLabel("Lauk Nabati");
    JLabel lbl_hewani = new JLabel("Lauk Hewani");
    JLabel lbl_sayur = new JLabel("Sayur");
    JLabel lbl_Buah = new JLabel("Buah");
    JLabel lbl_gr = new JLabel("gr");
    JLabel lbl_ket = new JLabel("Daftar Makanan Yang Anda Masukkan");
    JTextField txt_grpokok = new JTextField();
    JTextField txt_grnabati = new JTextField();
    JTextField txt_grhewani = new JTextField();
    JTextField txt_grsayur = new JTextField();
    JTextField txt_grbuah = new JTextField();
    JButton btn_pokok = new JButton("+");
    JButton btn_nabati = new JButton("+");
    JButton btn_hewani = new JButton("+");
    JButton btn_sayur = new JButton("m+");
    JButton btn_buah = new JButton("m+m");
    JButton btn_submit = new JButton("Submit");
    Font x = new Font("Times New Roman", Font.BOLD, 15);
    Font y = new Font("Times New Romn", Font.BOLD, 30);
    JTextArea tx = new JTextArea();

    void tampil() {
        for (int i = 0; i <= mak_pokok.length; i++) {
            cb_pokok.addItem(new String().valueOf(i ));
        }
        for (int i = 0; i < nabati.length; i++) {
            cb_nabati.addItem(new String().valueOf(i + 1));
        }
        for (int i = 0; i < hewani.length; i++) {
            cb_hewani.addItem(new String().valueOf(i + 1));
        }
        for (int i = 0; i < sayur.length; i++) {
            cb_sayur.addItem(new String().valueOf(i + 1));
        }
        for (int i = 0; i < buah.length; i++) {
            cb_buah.addItem(new String().valueOf(i + 1));
        }
        getContentPane().add(lbl_judul);
        getContentPane().add(lbl_pokok);
        getContentPane().add(lbl_nabati);
        getContentPane().add(lbl_hewani);
        getContentPane().add(lbl_sayur);
        getContentPane().add(lbl_Buah);


        lbl_judul.setFont(y);
        lbl_pokok.setFont(x);
        lbl_nabati.setFont(x);
        lbl_hewani.setFont(x);
        lbl_sayur.setFont(x);
        lbl_Buah.setFont(x);

        btn_pokok.setFont(x);
        btn_nabati.setFont(x);
        btn_hewani.setFont(x);
        btn_sayur.setFont(x);
        btn_buah.setFont(x);

        getContentPane().add(cb_pokok);
        getContentPane().add(cb_nabati);
        getContentPane().add(cb_hewani);
        getContentPane().add(cb_sayur);
        getContentPane().add(cb_buah);



        getContentPane().add(lbl_gr);
        lbl_gr.setFont(x);
        getContentPane().add(txt_grpokok);
        getContentPane().add(txt_grnabati);
        getContentPane().add(txt_grhewani);
        getContentPane().add(txt_grsayur);
        getContentPane().add(txt_grbuah);

        getContentPane().add(btn_pokok);
        getContentPane().add(btn_nabati);
        getContentPane().add(btn_hewani);
        getContentPane().add(btn_sayur);
        getContentPane().add(btn_buah);
        getContentPane().add(lbl_ket);
        getContentPane().add(tx);
        getContentPane().add(lbl_ket);
        getContentPane().add(btn_submit);

        lbl_judul.setBounds(200, 20, 400, 25);
        lbl_pokok.setBounds(30, 80, 400, 25);
        lbl_nabati.setBounds(30, 160, 400, 25);
        lbl_hewani.setBounds(30, 240, 400, 25);
        lbl_sayur.setBounds(30, 320, 400, 25);
        lbl_Buah.setBounds(30, 400, 400, 25);

        cb_pokok.setBounds(30, 120, 150, 25);
        cb_nabati.setBounds(30, 200, 150, 25);
        cb_hewani.setBounds(30, 280, 150, 25);
        cb_sayur.setBounds(30, 360, 150, 25);
        cb_buah.setBounds(30, 440, 150, 25);

        lbl_ket.setBounds(430, 80, 400, 25);
        lbl_gr.setBounds(250, 80, 400, 25);
        txt_grpokok.setBounds(250, 120, 80, 25);
        txt_grnabati.setBounds(250, 200, 80, 25);
        txt_grhewani.setBounds(250, 280, 80, 25);
        txt_grsayur.setBounds(250, 360, 80, 25);
        txt_grbuah.setBounds(250, 440, 80, 25);

        btn_pokok.setBounds(350, 120, 35, 25);
        btn_nabati.setBounds(350, 200, 35, 25);
        btn_hewani.setBounds(350, 280, 35, 25);
        btn_sayur.setBounds(350, 360, 35, 25);
        btn_buah.setBounds(350, 440, 35, 25);

        tx.setBounds(430, 120, 330, 350);

        btn_submit.setBounds(570, 480, 100, 25);

    }

    void aksi() {
        btn_submit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        });
        btn_pokok.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                if (event.getSource() == btn_pokok) {
                    String s = cb_pokok.getSelectedItem() + " ";
                    tx.setText(s);

                }


            }
        });

        btn_nabati.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                if (event.getSource() == btn_nabati) {
                    String s = cb_nabati.getSelectedItem() + " ";
                    tx.setText(s);

                }


            }
        });
        btn_hewani.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                if (event.getSource() == btn_hewani) {
                    String s = cb_hewani.getSelectedItem() + " ";
                    tx.setText(s);

                }


            }
        });
        btn_sayur.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                if (event.getSource() == btn_sayur) {
                    String s = cb_sayur.getSelectedItem() + " ";
                    tx.setText(s);

                }


            }
        });
        btn_buah.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                if (event.getSource() == btn_buah) {
                    String s = cb_buah.getSelectedItem() + " ";
                    tx.setText(s);

                }


            }
        });

    }

    void resetpokok() {


        txt_grpokok.setText("");
    }

    void resetnabati() {


        txt_grnabati.setText("");

    }

    void resethewani() {


        txt_grhewani.setText("");
    }

    void resetsayur() {

        txt_grsayur.setText("");
    }

    void resetbuah() {

        txt_grbuah.setText("");
    }

    public hitung_gizi2() {
        setLayout(null);
        setLocation(300, 100);
        aksi();
        tampil();
        setResizable(false);
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setSize(800, 600);
        setVisible(true);
    }

    void submit() {
    }

    public static void main(String[] args) {
        hitung_gizi2 a = new hitung_gizi2();
        a.tampil();
        a.aksi();

    }
}










Rabu, 09 Mei 2012

KALKULATOR SEDERHANA#MODUL9

Malam rabu merupakan malam dimana saya ga bisa tidur tenang.. kenapa??
hehe.. jawabnya..karena besok pagi jadwalnya praktikum daspro,,huhu.. belajar sambil takut ,, dagdigdug ga karuan.. maklum saya termasuk paling ga bisa.. jadi harus studyhard,,,
praktikum kali ini adalah membuat kalkulator sederhana dengan output

berikut ini source kodenya


package modul9;

/**
 *
 * @author Acer
 *
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class no1 extends JFrame{
JLabel lb1 = new JLabel("Masukkan Angka Pertama : ");
  JLabel lb2 = new JLabel("Masukkan Angka Kedua : ");
  JLabel lb3 = new JLabel("Hasil : ");

  JTextField tx1 = new JTextField(15);
  JTextField tx2 = new JTextField(15);
  JTextField tx3 = new JTextField(15);

  JButton bt1 = new JButton(" + ");
  JButton bt2 = new JButton(" - ");
  JButton bt3 = new JButton(" / ");
  JButton bt4 = new JButton(" * ");
void tampil(){
  getContentPane().add(lb1);
  getContentPane().add(tx1);
  getContentPane().add(lb2);
  getContentPane().add(tx2);
  getContentPane().add(lb3);
  getContentPane().add(tx3);

  getContentPane().add(bt1);
  getContentPane().add(bt2);
  getContentPane().add(bt3);
  getContentPane().add(bt4);}
void aksi(){
  bt1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
      int x = Integer.parseInt(tx1.getText());
      int y = Integer.parseInt(tx2.getText());
      String z = String.valueOf( x + y );
      tx3.setText(z);}});
  bt2.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
      int x = Integer.parseInt(tx1.getText());
      int y = Integer.parseInt(tx2.getText());
      String z = String.valueOf( x - y );
      tx3.setText(z);}});
  bt3.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
      int x = Integer.parseInt(tx1.getText());
      int y = Integer.parseInt(tx2.getText());
      String z = String.valueOf( x / y );
      tx3.setText(z);}});
  bt4.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
      int x = Integer.parseInt(tx1.getText());
      int y = Integer.parseInt(tx2.getText());
      String z = String.valueOf( x * y );
      tx3.setText(z);}});}
public static void main(String[] args){
    no1 a = new no1();
    a.setLayout(new FlowLayout());
    a.setBackground(Color.yellow);
    a.aksi();
    a.tampil();
    a.setLocation(1000, 400);
    a.setTitle("Skenario FlowLayout");
    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a.setSize(200, 245);
    a.setVisible(true);}}
























                 

Sabtu, 05 Mei 2012

JAVA(LOOPING)


Hii…. Dasar pemrograman , awalnya aku kira susah banget.. .. butuh aku lama untuk aku ngerti.. yah bener aja.. terlebih looping.. tapi alhamdulillah sekarang aq udah bisa … ini salah satu hasil kodingku , yang beberapa waktu lalu d jadiin UTS sama dosenku.. ibu roro indah melani..
Makasih ya allah
Outputnya
55555
32323
55555
#3#3#

package newpackage;

/**
 *
 * @author Acer
 */
public class sanggi3 {

    public static void main(String[] ars) {
        for (int i = 1; i <= 4; i++) {
            for (int j = 5; j >= 1; j--) {
                if (i==1) {System.out.print("5");

                }
                  
                       
                if (i == 2) {
                    if ((j % 2) == 0) {
                        System.out.print("2");

                    } else {
                        System.out.print("3");
                    }

                }
                if (i == 3) {


                    System.out.print("5");
                }
                if (i == 4) {
                    if ((j % 2) == 1) {
                        System.out.print("#");

                    } else {
                        System.out.print("3");
                    }

                }

            }
            System.out.println(" ");

        }
    }
}