Gui Java by Dee_Clop

VIEWS: 216 PAGES: 8

									    LAPORAN PRAKTIKUM
APLIKASI BERBASIS WINDOWS




                   Oleh:

          Dian Eka P. (0831140081)




   KEMENTRIAN PENDIDIKAN NASIONAL

      POLITEKNIK NEGERI MALANG

       JURUSAN TEKNIK ELEKTRO

 PROGRAM STUDI MANAJEMEN INFORMATIKA
1. Aplikasi Penghitung Karakter Nama

  • Inputan Nama :

  Design :




  Source:
            import javax.swing.JOptionPane;
            public class Karakter extends javax.swing.JFrame {
              public String name;
              public static int karakter;

                /** Creates new form Karakter */
                public Karakter() {
                  initComponents();
                }

                @SuppressWarnings("unchecked")

                private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
                   // TODO add your handling code here:
                   if (evt.getSource()==jButton1){
                      name=new String (jTextField1.getText());
                      karakter=name.length();

                        new Tampil().setVisible(true);
                        jTextField1.setText("");
                    }
                }

                public static void main(String args[]) {
                  java.awt.EventQueue.invokeLater(new Runnable() {
                     public void run() {
                        new Karakter().setVisible(true);
                     }
                  });
                }

                private javax.swing.JButton jButton1;
                private javax.swing.JLabel jLabel1;
                private javax.swing.JTextField jTextField1;

            }
•   Tampilan Hasil
    Design:




    Source:
     public class Tampil extends javax.swing.JFrame {




         /** Creates new form Tampil */

         public Tampil() {

             initComponents();

             jLabel2.setText(String.valueOf(Karakter.karakter));

         }

         @SuppressWarnings("unchecked")

         private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {

             // TODO add your handling code here:

             this.dispose();

         }

         public static void main(String args[]) {

             java.awt.EventQueue.invokeLater(new Runnable() {

                   public void run() {

                       new Tampil().setVisible(true);

                   }

             });

         }

         private javax.swing.JButton jButton1;

         private javax.swing.JLabel jLabel1;

         private javax.swing.JLabel jLabel2;

         private javax.swing.JLabel jLabel3;

     }
Running Program:
2. Aplikasi penghitung umur
  • Inputan :
        • Design:




       •   Source code bio.java:

           import java.awt.Component;
           import javax.swing.JOptionPane;

           public class Bio extends javax.swing.JFrame {
             private Component frame;
             String hari1, hari2, hari3, jhari;
             int tahun1, tahun2, bulan1, bulan2, tanggal1, tanggal2;
             String x,y,z;
             String tahun, bulan, hari;
             int hr1, hr2, hr3, jhr1;
             int th,bl,hr;
             String a;
             public Bio() {
                  initComponents();
             }

             @SuppressWarnings("unchecked")

           private void jButton1ActionPerformed(java.awt.event.ActionEvent
           evt) {
             x = String.valueOf(jComboBox3.getSelectedItem());
             tahun1 = Integer.parseInt(DateUtils.year());
             tahun2 = Integer.parseInt(x);
             hari1= String.valueOf((tahun1-tahun2)*365);

             y = String.valueOf(jComboBox2.getSelectedItem());
  z = String.valueOf(jComboBox1.getSelectedItem());
  bulan1 = Integer.parseInt(DateUtils.month());
  bulan2 = Integer.parseInt(y);
  tanggal1 = Integer.parseInt(DateUtils.date());
  tanggal2 = Integer.parseInt(z);
  hari2 = String.valueOf(tanggal2+((bulan2-1)*31));
  hari3 = String.valueOf(tanggal1+((bulan1-1)*31));
  hr1 = Integer.parseInt(hari1);
  hr2 = Integer.parseInt(hari2);
  hr3 = Integer.parseInt(hari3);
  jhari = String.valueOf(hr1-hr2+hr3);

  jhr1= Integer.parseInt(jhari);

  tahun = String.valueOf(jhr1/365);
  a = String.valueOf(jhr1%365);

 bl = Integer.parseInt(a);
 bulan = String.valueOf(bl/31);
 hari = String.valueOf(bl%31);

   JOptionPane.showMessageDialog(null,"Selamat Datang " +
jTextField2.getText()+" Hari ini" +
        " anda berusia "+ tahun+" tahun " + bulan+" bulan " +
hari+" hari");
  }

  private void
jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
  }

  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
          new Bio().setVisible(true);
        }
    });
  }
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JComboBox jComboBox2;
        private javax.swing.JComboBox jComboBox3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        // End of variables declaration

    }

•   Code DateUtils.java:

    import java.text.SimpleDateFormat;
    import java.util.Calendar;

    public class DateUtils extends Bio {
    public static final String YEAR_FORMAT_NOW = "yyyy";
    public static final String MONTH_FORMAT_NOW = "MM";
    public static final String DATE_FORMAT_NOW = "dd";

     public static String year() {
       Calendar cal = Calendar.getInstance();
       SimpleDateFormat sdf = new
    SimpleDateFormat(YEAR_FORMAT_NOW);
       return sdf.format(cal.getTime());
     }

      public static String month() {
       Calendar cal = Calendar.getInstance();
       SimpleDateFormat sdf = new
    SimpleDateFormat(MONTH_FORMAT_NOW);
       return sdf.format(cal.getTime());
     }
           public static String date() {
           Calendar cal = Calendar.getInstance();
           SimpleDateFormat sdf = new
        SimpleDateFormat(DATE_FORMAT_NOW);
           return sdf.format(cal.getTime());
         }

            public static void main(String arg[]) {
              System.out.println("Tanggal : " + DateUtils.date());
              System.out.println("Bulan : " + DateUtils.month());
              System.out.println("Tahun : " + DateUtils.year());
            }
        }

•   Hasilnya:

								
To top