Membuat Progam Alay di jFrame Java

selamat malam,siang , sore agan2....sekalian :)

kali ini ane mau share, gmn buat program alay sederhana menggunakan bahasa java

program ini mencakup enskripsi, iostream dll

ane buat nya di JCreator......
oke kita langsung ngoding aja y...

pertama buat project baru, terserah mau kasih nama apa, kemudian buat  2 package terserah juga agan mau kasih nama apa, di sini ane kasih nama enkripsi dan main.
langkah selanjutnya di package enkripsi buat 3 class, di sini ane kasih nama Alay, cecar, dan class iostream.
di package main buat class dgn nama view (di gunakan untuk memanggil class2 yg lain nya).


oke,, copy kan coding di bawah ini di class Alay

package Enkripsi;
public class Alay {
public static String jadiAlay(String kalimatasli) {
        char[] huruf = new char[kalimatasli.length()];
 for (int i = 0; i < kalimatasli.length(); i++) {
            if (kalimatasli.charAt(i)=='a'||kalimatasli.charAt(i)=='A'){
                huruf[i]='4';
            }else if(kalimatasli.charAt(i)=='i'||kalimatasli.charAt(i)=='I'){
            huruf[i]='!';
            }            
            else if(kalimatasli.charAt(i)=='e'||kalimatasli.charAt(i)=='E'){
                huruf[i]='3';
                                }
               else if(kalimatasli.charAt(i)=='o'||kalimatasli.charAt(i)=='O'){
            huruf[i]='0';
            }    
            else if(kalimatasli.charAt(i)=='s'||kalimatasli.charAt(i)=='S'){
            huruf[i]='$';
            }   
            else if(kalimatasli.charAt(i)=='b'||kalimatasli.charAt(i)=='B'){
            huruf[i]='8';
            }  
            else if(kalimatasli.charAt(i)=='l'||kalimatasli.charAt(i)=='L'){
            huruf[i]='£';
            }   
            else if(kalimatasli.charAt(i)=='y'||kalimatasli.charAt(i)=='Y'){
            huruf[i]='¥';
            }  
            else{
                huruf[i]=kalimatasli.charAt(i);
            }
        }
        String alay = new String(huruf);
        return alay;
    }
    public void tampil_alay(){
    System.out.println("Kalimat alay : " + jadiAlay("aaaa"));
    }
}



kalo coding diatas telah di copy, maka langkah selanjutnya buka class iostream dan copykan coding di bawah ini :


package Enkripsi;
import main.*;
import java.io.*;
import java.util.Scanner;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JOptionPane;


public class iostream extends view {
public void writefile() {
        JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showSaveDialog(texfield_satu) == JFileChooser.APPROVE_OPTION) { }
try {
  
            File f = new File(fileChooser.getSelectedFile()+".txt");
            if (!f.exists()) {
                f.createNewFile();
                FileWriter fw = new FileWriter(f);
                BufferedWriter bw = new BufferedWriter(fw);
                
                bw.write(y.getText());
                bw.close();
                System.out.println("Program Sukses");
            } else {
                System.out.println("Nama File Sudah Ada, Masukkan kembali Alamat File !!");
            }
        } catch (Exception e) {
            System.out.println("Ada Kesalahan Saat Program Berjalan Silahkan Ulangi Program");
        }
    }
    
    
     public String open(String f) throws FileNotFoundException {
      
        String isi="";
        File file = new File(f);
        StringBuilder fileContents = new StringBuilder((int) file.length());
        Scanner scanner = new Scanner(file);
        String lineSeparator = System.getProperty("line.separator");

        try {
            while (scanner.hasNextLine()) {
           
                fileContents.append(scanner.nextLine() + lineSeparator);
            }
            isi=fileContents.toString();
        } finally {
            scanner.close();           
        }
        return isi;
    } 
}



selanjutnya copy kan coding di bawah ini pada class cecar
package Enkripsi;
import main.view;

public class cecar extends view {
public static String encode(String enc, int offset) {
offset = offset % 26 + 26;
StringBuilder encoded = new StringBuilder();
for (char i : enc.toLowerCase().toCharArray()) {
if (Character.isLetter(i)) {
int j = (i - 'a' + offset) % 26;
encoded.append((char) (j + 'a'));
} else {
encoded.append(i);
}
}
return encoded.toString();
}
}


nah untuk class view copy kan source code di bawah ini
(sedikit panjang sihhh :)     )


package main;
import Enkripsi.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;


public class view extends JFrame {
JLabel text = new JLabel();
public JTextArea texfield_satu = new JTextArea();
public JTextArea y = new JTextArea();
JButton btn_open = new JButton();
JButton btn_save = new JButton();
JButton btn_wrap = new JButton();
JButton btn_clear = new JButton("Clear");
JButton btn_proses = new JButton();
JButton btn_author = new JButton();
JRadioButton rb_alay = new JRadioButton();
JRadioButton rb_cecar = new JRadioButton();
JRadioButton rb_normal = new JRadioButton();
ButtonGroup group = new ButtonGroup();
public view(){
setTitle("Program Nge-Alay");
setSize(400,550);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
setVisible(true);
add(text);
text.setText("+++ ALAY & RAHASIA2an Yuk +++");
text.setBounds(80,20,250,60);
add(texfield_satu);
texfield_satu.setBounds(20,60,350,150);
add(y);
y.setBounds(20,215,350,150);
add (btn_open);
btn_open.setText("Open");
btn_open.setBounds(20,370,80,35);
        btn_open.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
           
        JFileChooser fileChooser = new JFileChooser();            
                int userSelection = fileChooser.showOpenDialog(null);
                if (userSelection == JFileChooser.APPROVE_OPTION) {
                    File fileToOpen = fileChooser.getSelectedFile();
                    String f = fileToOpen.getAbsolutePath();
                    try {
                    iostream xx = new iostream();
                       String isi = xx.open(f);
                       texfield_satu.setText(isi);
                    } catch (FileNotFoundException ex) {
                        ex.printStackTrace();
                    }
                }        
}
        });
add (btn_save);
btn_save.setText("Save");
btn_save.setBounds(110,370,80,35);
btn_save.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent arg0) {
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showSaveDialog(texfield_satu) == JFileChooser.APPROVE_OPTION) { }
try {
            File f = new File(fileChooser.getSelectedFile()+".txt");
            if (!f.exists()) {
                f.createNewFile();
                FileWriter fw = new FileWriter(f);
                BufferedWriter bw = new BufferedWriter(fw);       
                bw.write(y.getText());
                bw.close();
                System.out.println("Program Sukses");
            } else {
                System.out.println("Nama File Sudah Ada, Masukkan kembali Alamat File !!");
            }
        } catch (Exception e) {
            System.out.println("Ada Kesalahan Saat Program Berjalan Silahkan Ulangi Program");
        }
            }
        });
add (btn_wrap);
btn_wrap.setText("Wrap");
btn_wrap.setBounds(20,410,80,35);
btn_wrap.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                texfield_satu.setLineWrap(false);
                y.setLineWrap(false);
            }
        });
add (btn_clear);
btn_clear.setText("Clear");
btn_clear.setBounds(110,410,80,35);
btn_clear.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
texfield_satu.setText(null);
y.setText(null);
}});
add (btn_proses);
btn_proses.setText("Proses");
btn_proses.setBounds(240,450,80,35);
btn_proses.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String tampil = texfield_satu.getText();
   int n=0;
                for (int i = 0; i < tampil.length() ; i++) {
                    if (tampil.charAt(i) == 'a' || tampil.charAt(i) == 'A'||tampil.charAt(i)=='i'||tampil.charAt(i)=='I'||
                            tampil.charAt(i)=='u'||tampil.charAt(i)=='U'||tampil.charAt(i)=='e'||tampil.charAt(i)=='E'||
                            tampil.charAt(i)=='o'||tampil.charAt(i)=='O'){
                n++;
            }
        }
        int vokal_alay=0; 
        
        String lihat = (cecar.encode(" "+texfield_satu.getText(),3));
   int m=0;
        for (int j = 0; j < lihat.length() ; j++) {
                    if (lihat.charAt(j) == 'a' || lihat.charAt(j) == 'A'||lihat.charAt(j)=='i'||lihat.charAt(j)=='I'||
                            lihat.charAt(j)=='u'||lihat.charAt(j)=='U'||lihat.charAt(j)=='e'||lihat.charAt(j)=='E'||
                            lihat.charAt(j)=='o'||lihat.charAt(j)=='O'){
                m++;
            }
        }

        
       if(rb_normal.isSelected()){
 y.setText(" "+texfield_satu.getText());
 
} else if(rb_cecar.isSelected()){
y.setText(" "+cecar.encode(" "+texfield_satu.getText(),3)+"\n\n panjang Karakter Kalimat Asli "+tampil.length()
+"\n dan jumlah huruf vokal kalimat asli "+n
+"\n\n panjang kalimat setelah di dienkripsi "+tampil.length()
+"\n jumlah huruf vokal setelah dienkripsi "+m );
} else if(rb_alay.isSelected()) { 
y.setText(" "+Alay.jadiAlay(" "+texfield_satu.getText())+"\n\n panjang Karakter Kalimat Asli "+tampil.length()
+"\n dan jumlah huruf vokal kalimat asli "+n
+"\n\n panjang kalimat setelah di dienkripsi "+tampil.length()
+"\n jumlah huruf vokal setelah dienkripsi "+vokal_alay);
}
}
});
add (rb_alay);
rb_alay.setText("Alay");
rb_alay.setBounds(200,370,50,40);
add (rb_cecar);
rb_cecar.setText("cecar");
rb_cecar.setBounds(280,370,70,40);
add (rb_normal);
rb_normal.setText("Normal");
rb_normal.setBounds(240,410,70,40);
group.add(rb_alay);
group.add(rb_cecar);
group.add(rb_normal);
add (btn_author);
btn_author.setText("Author");
btn_author.setBounds(20,450,80,35);
btn_author.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                texfield_satu.setText("Created by : \n\n1. Wasis Pancoro 672012210");              
                     }
        });

public static void main(String args[]) {
new view();
}
}




sekarang coba build dan run
pastikan langkah awal sampai akhir benar
maka output nya seperti berikut :

 


oke sekian dari ane....
terima kasih telah berkunjung....
jangan lupa tinggalin jempol nya...... :)

1 komentar:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

    BalasHapus

Copyright © 2013 Gagal Coding