<x-layout>
    <x-slot:title>{{ $title }}</x-slot:title>
    <style>
        .code {
            background-color: #f4f4f4;
            border-left: 10px solid #ccc;
            padding: 10px;
            font-family: monospace;
            overflow-x: auto;
        }

        .code pre {
            margin: 0;
        }
    </style>
    <div class="card card-responsive mb-3">
        <div class="card-body">
            <h1>KelasAudio Documentation</h1>
            <p><strong>Author:</strong> ASUS</p>
            <p>This class is a simple audio player using Java Swing and the sun.audio package to play and stop audio.
            </p>

            <h2>Class: KelasAudio</h2>
            <p>The <code>KelasAudio</code> class extends <code>javax.swing.JFrame</code> and provides a GUI for playing
                and stopping an audio file.</p>

            <h3>Fields</h3>
            <ul>
                <li><code>private AudioStream audioStream;</code> - Holds the audio stream object.</li>
                <li><code>private boolean isPlaying = false;</code> - Indicates whether the audio is currently playing.
                </li>
            </ul>

            <h3>Constructor</h3>
            <div class="code">
                <pre>
public KelasAudio() {
    initComponents();
}
            </pre>
            </div>
            <p>The constructor initializes the components of the form.</p>

            <h3>Methods</h3>

            <h4>private void initComponents()</h4>
            <p>This method is called from within the constructor to initialize the form. It sets up the GUI components.
            </p>

            <h4>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)</h4>
            <div class="code">
                <pre>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    if (!isPlaying) {
        try {
            InputStream in = new FileInputStream(new File("C:\\Users\\bagas\\Music\\Taylor Swift - Style (Taylor's Version).wav"));
            audioStream = new AudioStream(in);
            AudioPlayer.player.start(audioStream);
            isPlaying = true;
        } catch (IOException e) {
            System.out.println(e);
        } 
    }
}
            </pre>
            </div>
            <p>This method is called when the play button (<code>jButton1</code>) is pressed. It starts playing the
                audio if it is not already playing.</p>

            <h4>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)</h4>
            <div class="code">
                <pre>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    if (isPlaying) {
        AudioPlayer.player.stop(audioStream);
        isPlaying = false;
    }
}
            </pre>
            </div>
            <p>This method is called when the pause button (<code>jButton2</code>) is pressed. It stops the audio if it
                is currently playing.</p>

            <h3>Main Method</h3>
            <div class="code">
                <pre>
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new KelasAudio().setVisible(true);
        }
    });
}
            </pre>
            </div>
            <p>The main method launches the application by creating an instance of <code>KelasAudio</code> and making it
                visible.</p>

            <h3>GUI Components</h3>
            <p>The following GUI components are declared and initialized in the <code>initComponents</code> method:</p>
            <ul>
                <li><code>jPanel1</code> - A JPanel that holds the other components.</li>
                <li><code>jButton1</code> - A JButton for playing audio.</li>
                <li><code>jButton2</code> - A JButton for pausing audio.</li>
                <li><code>jLabel1</code> - A JLabel displaying an image.</li>
                <li><code>jLabel2</code> - A JLabel displaying text.</li>
            </ul>

            <h3>Full Code</h3>
            <div class="code">
                <pre>
package audio;

import java.io.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import sun.audio.*;

/**
 *
 * @author ASUS
 */
public class KelasAudio extends javax.swing.JFrame {

    /**
     * Creates new form KelasAudio
     */
    public KelasAudio() {
        initComponents();
    }
    private AudioStream audioStream;
    private boolean isPlaying = false;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings('unchecked')
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(185, 148, 107));

        jButton1.setBackground(new java.awt.Color(185, 148, 107));
        jButton1.setForeground(new java.awt.Color(185, 148, 107));
        jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\bagas\\Downloads\\play.png")); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(185, 148, 107));
        jButton2.setForeground(new java.awt.Color(185, 148, 107));
        jButton2.setIcon(new javax.swing.ImageIcon("C:\\Users\\bagas\\Downloads\\pause (2).png")); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\bagas\\Downloads\\style taylor swift (2).jpeg")); // NOI18N

        jLabel2.setFont(new java.awt.Font("Segoe Script", 0, 18)); // NOI18N
        jLabel2.setText("Taylor Swift - Style (Taylor's Version) ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(91, 91, 91)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(jLabel1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 63, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(30, 30, 30))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if (!isPlaying) {
            try {
                InputStream in = new FileInputStream(new File("C:\\Users\\bagas\\Music\\Taylor Swift - Style (Taylor's Version).wav"));
                audioStream = new AudioStream(in);
                AudioPlayer.player.start(audioStream);
                isPlaying = true;
            } catch (IOException e) {
                System.out.println(e);
            } 
        }
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        if (isPlaying) {
            AudioPlayer.player.stop(audioStream);
            isPlaying = false;
        }
        
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(KelasAudio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(KelasAudio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(KelasAudio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(KelasAudio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new KelasAudio().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration                   
}

              </pre>
            </div>


            <h3 class="mt-4">Tampilan</h3>
            <img src="{{ asset('assets/img/dd.png') }}" width="300">

        </div>
    </div>


</x-layout>
