Miletone

Rp0 / Rp1.000.000

Showing posts with label [JAVA]. Show all posts
Showing posts with label [JAVA]. Show all posts

Monday, January 11, 2021

[JAVA] HOW TO MAKE FILE (.txt) with filled.

 import java.io.*;

import java.util.Scanner;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args) throws IOException{

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

//attach keyboard to DataInputStream 

        DataInputStream dis=new DataInputStream(System.in); 

  

        // attach file to FileOutputStream 

        FileOutputStream fout=new FileOutputStream("file.txt"); 

  

        //attach FileOutputStream to BufferedOutputStream 

        BufferedOutputStream bout=new BufferedOutputStream(fout,1024); 

        System.out.println("Enter text (@ at the end):"); 

        char ch; 

  

        //read characters from dis into ch. Then write them into bout. 

        //repeat this as long as the read character is not @ 

        while((ch=(char)dis.read())!='@') 

        { 

            bout.write(ch); 

        } 

        //close the file 

        bout.close(); 

    }  

    }


[JAVA] MEMBUAT FILE TEXT (.txt) dengan isinya.

[JAVA] HOW TO MAKE FILE (UNCATHEGORY).

  import java.io.*;

import java.util.Scanner;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

try  

{  

Scanner sc=new Scanner(System.in);         //object of Scanner class  

System.out.print("Enter the file name: ");  

String name=sc.nextLine();              //variable name to store the file name  

FileOutputStream fos=new FileOutputStream(name, true);  // true for append mode  

System.out.print("Enter file content: ");         

String str=sc.nextLine()+"\n";      //str stores the string which we have entered  

byte[] b= str.getBytes();       //converts string into bytes  

fos.write(b);           //writes bytes into file  

fos.close();            //close the file  

System.out.println("file saved.");  

}  

catch(Exception e)  

{  

e.printStackTrace();          

}     System.out.println("Data yang anda input, selesai");

    }

}


[JAVA] MEMBUAT FILE (BELUM TERKATEGORI).

 import java.io.*;

import java.util.Scanner;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

try  

{  

Scanner sc=new Scanner(System.in);         //object of Scanner class  

System.out.print("Enter the file name: ");  

String name=sc.nextLine();              //variable name to store the file name  

FileOutputStream fos=new FileOutputStream(name, true);  // true for append mode  

System.out.print("Enter file content: ");         

String str=sc.nextLine()+"\n";      //str stores the string which we have entered  

byte[] b= str.getBytes();       //converts string into bytes  

fos.write(b);           //writes bytes into file  

fos.close();            //close the file  

System.out.println("file saved.");  

}  

catch(Exception e)  

{  

e.printStackTrace();          

}     System.out.println("Data yang anda input, selesai");

    }

}


[JAVA] MAKE A FOLDER.

 import java.io.*;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

       String dirname = "D:\\test";

      File d = new File(dirname);

      

      // Create directory now.

      d.mkdirs();

        System.out.println("Data yang anda input, selesai");

    }

}

[JAVA] MEMBUAT FOLDER.

 import java.io.*;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

       String dirname = "D:\\test";

      File d = new File(dirname);

      

      // Create directory now.

      d.mkdirs();

        System.out.println("Data yang anda input, selesai");

    }

}

[JAVA] How to read data stream from the any file.

 import java.io.*;


/**

 *

 * @author ANDI

 */

public class JavaStream {


    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

        //baca stream dari text

        try {

            FileInputStream fstream = new FileInputStream("D:\\File Netbeans\\JavaStream\\src\\stream\\test.txt  ");

            DataInputStream dataInput = new DataInputStream(fstream);

            while(dataInput.available()!=0)

            {

                String data = dataInput.readLine();

                System.out.println(data);

            }

            dataInput.close();

        }

        catch (Exception e) {

            System.err.println("File Input Error");

            }

        }

        

    }

[JAVA] Membaca data dari suatu file/program dengan menggunakan stream.

 import java.io.*;


/**

 *

 * @author ANDI

 */

public class JavaReaderStream {


    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

        //baca stream dari text

        try {

            FileInputStream fstream = new FileInputStream("D:\\File Netbeans\\JavaStream\\src\\stream\\test.txt  ");

            DataInputStream dataInput = new DataInputStream(fstream);

            while(dataInput.available()!=0)

            {

                String data = dataInput.readLine();

                System.out.println(data);

            }

            dataInput.close();

        }

        catch (Exception e) {

            System.err.println("File Input Error");

            }

        }

        

    }

[JAVA] HOW TO RUN ANY APPLICATION PROGRAM.

 ACTION PERFORMED :

try {

            Runtime runTime = Runtime.getRuntime();

            

            String executablePath = "C:\\Users\\sdkca\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"; //THIS CHANGE FROM YOUR APPLICATION LOCATION

            

            Process process = runTime.exec(executablePath);

        } catch (IOException e) {

            e.printStackTrace();

        }

[JAVA] CARA MENJALANKAN APLIKASI PROGRAM.

 ACTION PERFORMED :

try {

            Runtime runTime = Runtime.getRuntime();

            

            String executablePath = "C:\\Users\\sdkca\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"; //GANTI DI LOKASI PADA FOLDER ANDA.

            

            Process process = runTime.exec(executablePath);

        } catch (IOException e) {

            e.printStackTrace();

        }

Wednesday, November 25, 2020

[JAVA] Connection Database MySQL

 import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;


/**

 *

 * @author USER

 */

public class Koneksi {

    private static Connection koneksi;


public static Connection getKoneksi() {

if (koneksi == null) {

try {

String url = "jdbc:mysql://localhost/laundry";

String username = "root";

String password = "";


DriverManager.registerDriver(new com.mysql.jdbc.Driver());

koneksi = DriverManager.getConnection(url, username, password);

} catch (Exception ex) {

                    JOptionPane.showMessageDialog(null, "KONEKSI KE SERVER GAGAL !\n PERIKSALAH KEMBALI KONEKSI JARINGAN!");

                

}

}

return koneksi;

}

}

Sunday, September 29, 2019

[JAVA] Software Data-in on Shop Free


Sistem ini terdiri dari Login dan Data. Untuk yang telah disediakan selain itu, masih belum tersedia saat ini.Gambar sebagai berikut :
Login
Electronic
Untuk username dan admin : admin dan admin
Kata sandi ZIP : dlcam.blogspot.com
Download :

[JAVA] How to Search Database to JTextField

Action Performed :
try                
                    {
                        Connection connect = Connect.getConnect();
        Statement stat = connect.createStatement();                    
        String sql="SELECT * FROM other Where coder like'"+jTextField7.getText()+"'";                    
        ResultSet isi = stat.executeQuery(sql);                    
       //isi that is Variable 
if(isi.next())
       {                     
           jTextField1.setText(isi.getString(1)); 
           jTextField2.setText(isi.getString(2));                       
           jTextField3.setText(isi.getString(3));
           jTextField5.setText(isi.getString(4));
           jTextField4.setText(isi.getString(5));
           jTextField6.setText(isi.getString(6));
           jTextArea1.setText(isi.getString(7));
       }                  
       else
       {                        
           JOptionPane.showMessageDialog(null,"Invalid Code");
       }                  
       stat.close();
       }                
       catch (Exception ex)               
        {
            JOptionPane.showMessageDialog(null,"Error :"+ex);
                }

[JAVA] How to Search on JTable

Action Performed :
try {
            Connection connect = Connect.getConnect();
            String sql = "select * from other Where coder like '" + jTextField1.getText() + "'";
            Statement stat = connect.createStatement();
            ResultSet res = stat.executeQuery(sql);
            while (res.next()) {
                table.addRow(new Object[]{res.getString(1), res.getString(2), res.getString(3), res.getString(4), res.getString(5), res.getString(6), res.getString(7)});
                //setVisible(true);
                res.close();
                stat.close();
            }

            jTable1.setModel(table);
        } catch (Exception e) {
        }

[JAVA] How to Edit Database on Button

Action Performed :
try
                {
                    Connection connect = Connect.getConnect();
                    //Statement stm=connect.createStatement();
                    String sql="update other set coder ='?', a='?', b='?', c='?', d='?', e='?', f='?' where coder ='?'";
                     PreparedStatement prepare = (PreparedStatement) connect.prepareStatement(sql);
        prepare.setString(1, jTextField1.getText());
        prepare.setString(2, jTextField2.getText());
        prepare.setString(3, jTextField3.getText());
        prepare.setString(4, jTextField5.getText());
        prepare.setString(5, jTextField4.getText());
        prepare.setString(6, jTextField4.getText());
        prepare.setString(7, jTextArea1.getText());
        prepare.executeUpdate();
                    JOptionPane.showMessageDialog(null,"Success");
                    //reset();
                    //table();
                }
                catch(Exception ex)
                {
                    JOptionPane.showMessageDialog(null,"Error :"+ex);
                }

[JAVA] How to JTable Click to JTextField

Click Right on the table, selecr mouse, select and click mouseclicked then you fill code :
try{
            int Linha = jTable1.getSelectedRow();
            nik.setText(jTable1.getValueAt(Linha, 0).toString());
            transnik.setText(jTable1.getValueAt(Linha, 0).toString());
            nama.setText(jTable1.getValueAt(Linha, 1).toString());
            ttl.setText(jTable1.getValueAt(Linha, 2).toString());
            daerahasal.setText(jTable1.getValueAt(Linha, 3).toString());
            asalkiriman.setText(jTable1.getValueAt(Linha, 4).toString());
            /**Blob filenameBlob = (Blob) (jTable1.getValueAt(Linha, 6));
            byte[] content = filenameBlob.getBytes(1L,(int)filenameBlob.length());
            if(jTable1.getValueAt(Linha, 6) !=null){
                ImageIcon image = new ImageIcon(content);
                Image image1 = image.getImage().getScaledInstance(FOTO.getWidth(), FOTO.getHeight(), Image.SCALE_SMOOTH);
                ImageIcon image2 = new ImageIcon(image1);
                FOTO.setIcon(image2);
            }**/
        } catch (Exception e){

        }

[JAVA] How to Print Database on Button Print

Action Performed :
Connection connect = Connect.getConnect();
        try{
                JasperReport JASP_REP = JasperCompileManager.compileReport("src/print/DataPrint.jrxml");
                JasperPrint JASP_PRINT = JasperFillManager.fillReport(JASP_REP, null, connect);
                JasperViewer.viewReport(JASP_PRINT);
        } catch (Exception ev){
         
        }
 Libraries : Jasper Report

[JAVA] How to Open URL on Browser

Action Performed :

try {
  Desktop desktop = java.awt.Desktop.getDesktop();
  URI oURL = new URI("www.dlcam.blogspot.com");
  desktop.browse(oURL);
} catch (Exception e) {
  e.printStackTrace();
}

[JAVA] Contoh Program Java : Menghitung Gaji Karyawan

import java.util.Scanner;
class perhitungan_gaji_karyawan
{ //Andi Mahyudin
    public static void main(String[]args)
    {
        int gajipokok = 0;
        int bonus = 0;
        int pajak = 0;
        int total_gaji = 0;
        int gajikotor = 0;
        Scanner sc = new Scanner (System.in);
        System.out.println("Golongan : 1 ");
        System.out.println("(1). SMA = 1jt");
        System.out.println("(2). S1  = 1,5jt");
        System.out.println("(3). S2  = 2jt");
        System.out.println("");
        System.out.println("Golongan : 2 ");
        System.out.println("(4). SMA = 1,5jt");
        System.out.println("(5). S1  = 2,5jt");
        System.out.println("(6). S2  = 3jt");
        System.out.println("");
        System.out.println("Pilih dan masukkan dari data salah satu diatas !");
        System.out.print("Masukan Golongan Anda             : ");
        String golongan = sc.next();
        System.out.print("Masukan Nomor Pendidikan          : ");
        int pendidikan = sc.nextInt ();
        System.out.println("");
 
System.out.println("========================KETERANGAN========================");
        if (pendidikan==1 )
        {
            gajipokok=1000000;
            bonus=gajipokok*10/100;
            gajikotor=gajipokok+bonus;
            pajak=gajikotor*5/100;
            total_gaji=gajipokok+bonus-pajak;
       
    System.out.println("Golongan                            = " + golongan);
    System.out.println("Nomor Pilihan Pendidikan Anda       = " + pendidikan);
    System.out.println("Nama Pendidikan                     = SMA");
    System.out.println("Gaji Pokok                          = Rp. " + gajipokok);
    System.out.println("Bonus                               = Rp. " + bonus);
    System.out.println("Pajak                               = Rp. " + pajak);
    System.out.println("Total Gaji yang Diterima            = Rp. " + total_gaji);
        }
        else if (pendidikan==2)
        {
            gajipokok=1500000;
            bonus=gajipokok*10/100;
            gajikotor=gajipokok+bonus;
            pajak=gajikotor*5/100;
            total_gaji=gajipokok+bonus-pajak;
    System.out.println("Golongan                            = " + golongan);      
    System.out.println("Nomor Pilihan Pendidikan Anda       = " + pendidikan);
    System.out.println("Nama Pendidikan                     = S1");
    System.out.println("Gaji Pokok                          = Rp. " + gajipokok);
    System.out.println("Bonus                               = Rp. " + bonus);
    System.out.println("Pajak                               = Rp. " + pajak);
    System.out.println("Total Gaji yang Diterima            = Rp. " + total_gaji);
        }
        else if (pendidikan==3)
        {
            gajipokok=2000000;
            bonus=gajipokok*10/100;
            gajikotor=gajipokok+bonus;
            pajak=gajikotor*5/100;
            total_gaji=gajipokok+bonus-pajak;
    System.out.println("Golongan                            = " + golongan);
    System.out.println("Nomor Pilihan Pendidikan Anda       = " + pendidikan);
    System.out.println("Nama Pendidikan                     = S2");
    System.out.println("Gaji Pokok                          = Rp. " + gajipokok);
    System.out.println("Bonus                               = Rp. " + bonus);
    System.out.println("Pajak                               = Rp. " + pajak);
    System.out.println("Total Gaji yang Diterima            = Rp. " + total_gaji);
        }
        else if (pendidikan==4)
        {
            gajipokok=1500000;
            bonus=gajipokok*10/100;
            gajikotor=gajipokok+bonus;
            pajak=gajikotor*5/100;
            total_gaji=gajipokok+bonus-pajak;
    System.out.println("Golongan                            = " + golongan);
    System.out.println("Nomor Pilihan Pendidikan Anda       = " + pendidikan);
    System.out.println("Nama Pendidikan                     = SMA");
    System.out.println("Gaji Pokok                          = Rp. " + gajipokok);
    System.out.println("Bonus                               = Rp. " + bonus);
    System.out.println("Pajak                               = Rp. " + pajak);
    System.out.println("Total Gaji yang Diterima            = Rp. " + total_gaji);    
        }
        else if (pendidikan==5)
        {
             gajipokok=2500000;
            bonus=gajipokok*10/100;
            gajikotor=gajipokok+bonus;
            pajak=gajikotor*5/100;
            total_gaji=gajipokok+bonus-pajak;
    System.out.println("Golongan                            = " + golongan);
    System.out.println("Nomor Pilihan Pendidikan Anda       = " + pendidikan);
    System.out.println("Nama Pendidikan                     = S1");
    System.out.println("Gaji Pokok                          = Rp. " + gajipokok);
    System.out.println("Bonus                               = Rp. " + bonus);
    System.out.println("Pajak                               = Rp. " + pajak);
    System.out.println("Total Gaji yang Diterima            = Rp. " + total_gaji);
        }
        else if (pendidikan==6)
        {
             gajipokok=3500000;
            bonus=gajipokok*10/100;
            gajikotor=gajipokok+bonus;
            pajak=gajikotor*5/100;
            total_gaji=gajipokok+bonus-pajak;
    System.out.println("Golongan                            = " + golongan);
    System.out.println("Nomor Pilihan Pendidikan Anda       = " + pendidikan);
    System.out.println("Nama Pendidikan                     = S2");
    System.out.println("Gaji Pokok                          = Rp. " + gajipokok);
    System.out.println("Bonus                               = Rp. " + bonus);
    System.out.println("Pajak                               = Rp. " + pajak);
    System.out.println("Total Gaji yang Diterima            = Rp. " + total_gaji);
        }
    System.out.println("==========================================================");
    }
}

Output :