⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sholat.java

📁 pembelajaran sholat untuk anak TK
💻 JAVA
字号:
// program belajar sholat

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.util.*;
import javax.sound.sampled.*;

class Sholat implements ActionListener
    {
     	  
    	 		
  				//buat Panel
          JPanel topPanel,bottomPanel,tengah;
      	  JScrollPane scrollPane;
      	  JFrame frame;
      	  
      	  //buat nampilin gambar menggunakan button agar bisa berubah
      	  JButton b1;
      	  
      	  //buat suara
      	  private Clip theSound;

      	 
       	  Toolkit kit = Toolkit.getDefaultToolkit();
       	  Dimension screenSize = kit.getScreenSize();
       	  int screenHeight = screenSize.height;
       	  int screenWidth = screenSize.width;
       	  int index;
       	  
       	  Image img = kit.getImage("images/icon.jpg");
   	 
    	  //buat frame sholat
    	  Sholat()
    	    {
    	   	 
            	    frame = new JFrame("Belajar Sholat");
            	    frame.setSize(600,500);
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLocation(screenWidth/4, screenHeight/4);
                    frame.setIconImage(img);
         
                    addWidgets();
                    frame.show();
                  
                                     
                              
            }
                                    
                                    
    	  
         public void addWidgets()
         
            {
    
       	            
       	            //definisiin displaynya disini
       	            b1 = new JButton(new ImageIcon("images/image0.jpg"));
       	            b1.setBorder(null);
       	            b1.setHorizontalTextPosition(SwingConstants.CENTER);
       	            b1.setVerticalTextPosition(SwingConstants.TOP);
       	           
       	            
       	            JPanel topPanel = new JPanel(); 
       	            JPanel tengah = new JPanel();           
                   
                    JPanel bottomPanel = new JPanel();
                   
                    tengah.add(b1);
                    
                  
                    
                    //Add Buttons To Bottom Panel
                    JButton Kembali = new JButton("Kembali");
                    JButton Lanjut = new JButton("Lanjut");
                    JButton Dengarkan = new JButton("Dengarkan");
                    JButton Info = new JButton("Info");
                    JButton Keluar = new JButton("Keluar");
                   
                                                  
                    //Add Action Listeners
                    Kembali.addActionListener(this);
                    Lanjut.addActionListener(this);
                    Dengarkan.addActionListener(this);
                    Keluar.addActionListener(this);
                    Info.addActionListener(this);                     
                    
                
                      
                    bottomPanel.add(Kembali);
                    bottomPanel.add(Lanjut);
                    bottomPanel.add(Dengarkan);
                    bottomPanel.add(Info);
                    bottomPanel.add(Keluar);
                    

                    
		   
		    						frame.getContentPane().add(topPanel, BorderLayout.NORTH);
                    frame.getContentPane().add(tengah, BorderLayout.CENTER);
		    						frame.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
                    frame.setResizable(false);
            	
            				//// Get the current directory...
        						File soundFile = new File("sound/Sound"+index+".WAV");
										
										// Attempt to load the sound file...
						        try
						        {
						            AudioInputStream source = AudioSystem
						                .getAudioInputStream(soundFile);
						            DataLine.Info clipInfo = new DataLine.Info(Clip.class,
						                source.getFormat());
						            
						            if(AudioSystem.isLineSupported(clipInfo))
						            {
						                theSound = (Clip) AudioSystem.getLine(clipInfo);
						                theSound.open(source);
						            }
						            
						        }
						        catch(UnsupportedAudioFileException e)
						        {
						            System.out.println(e);    
						        }
						        catch(LineUnavailableException e)
						        {
						            System.out.println(e);    
						        }
						        catch(IOException e)
						        {
						            System.out.println(e);    
						        }
        
											
            			
									
										
				}
         
         

         
         public static void main(String args[])
            {
            	Sholat add = new Sholat();
            	
            }
            
         
    	 
    	 public void actionPerformed(ActionEvent ae)
    	    {
    	        
    	        
    	        if(ae.getActionCommand() == "Info")
    	            { 
    	                  JOptionPane.showMessageDialog(frame, "Belajar Sholat dibuat untuk membantu anak-anak Muslim,\norang dewasa, maupun Muallaf yang ingin belajar sholat\ndengan program belajar sholat secara audio visual\n\nSemoga Aplikasi ini dapat bermanfaat","Tentang Belajar Sholat", JOptionPane.INFORMATION_MESSAGE);
    	                 
    	            }
    	            
    	      
    	         
    	         
    	         else if(ae.getActionCommand() == "Kembali")
    	         {
    	         		index--; //ngurangin index
									if(index < 0){ 
									index = 0;
									}
									b1.setIcon(new ImageIcon("images/image"+index+".jpg"));
									theSound.stop();
							 }
							
							else if(ae.getActionCommand() == "Lanjut")
    	         {
    	         		index++; //Nambah index
									if(index > 11) {
									index = 11;
									}
									b1.setIcon(new ImageIcon("images/image"+index+".jpg"));
									theSound.stop();
							 }
							
							
							else if (ae.getActionCommand() == "Dengarkan")
							{
									
									//// Get the current directory...
        						File soundFile = new File("sound/sound"+index+".WAV");
										
										// Attempt to load the sound file...
						        try
						        {
						            AudioInputStream source = AudioSystem
						                .getAudioInputStream(soundFile);
						            DataLine.Info clipInfo = new DataLine.Info(Clip.class,
						                source.getFormat());
						            
						            if(AudioSystem.isLineSupported(clipInfo))
						            {
						                theSound = (Clip) AudioSystem.getLine(clipInfo);
						                theSound.open(source);
						            }
						            
						        }
						        catch(UnsupportedAudioFileException e)
						        {
						            System.out.println(e);    
						        }
						        catch(LineUnavailableException e)
						        {
						            System.out.println(e);    
						        }
						        catch(IOException e)
						        {
						            System.out.println(e);    
						        }
									
									if(theSound.isActive())
			            {
			                theSound.stop();
			            }
			            theSound.setFramePosition(0);
			            theSound.loop(0);

							}
								   
    	         else if(ae.getActionCommand() == "Keluar")
    	         {
    	         		
      						System.exit(0);
      				 }
    	         

    	                    	                
    	    }       
    	                          
					
    
    }
    


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -