SlideShare a Scribd company logo
Need help having my buttons play songs when clicked.
package jukebox;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MusicFrame extends JFrame {
private Title title;
private Songs song;
public MusicFrame(){
setTitle("Dean's Fabulous Jukebox");
title = new Title();
song = new Songs();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(700, 900);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(title, BorderLayout.NORTH);
add(song, BorderLayout.SOUTH);
setVisible(true);
}
}
////////////////////////
package jukebox;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Title extends JPanel {
public Title(){
Icon icon = new ImageIcon(getClass().getResource("Images/DJ.jpg"));
JLabel label1 = new JLabel("Dean's JukeBox", icon, JLabel.LEFT);
add(label1);
}
}
////////////////
package jukebox;
import java.awt.GridLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
public class Songs extends JPanel{
public Songs(){
setLayout(new GridLayout(1,2));
Icon Song1Icon = new ImageIcon(getClass().getResource("Images/Down.jpg"));
JButton song1 = new JButton("Don't Let Me Down", Song1Icon);
add(song1);
Icon Song2Icon = new ImageIcon(getClass().getResource("Images/Paris.jpg"));
JButton song2 = new JButton("Paris", Song2Icon);
add(song2);
}
}
Solution
add this code ClassLoader CLDR = this.getClass().getClassLoader(); InputStream soundName
= CLDR.getResourceAsStream("yourDirectory/soundclip.wav"); AudioStream audioStream =
new AudioStream(soundName); AudioPlayer.player.start(audioStream);

More Related Content

More from ezycolours78

An epic bribe scandal at Petrobras, a major oil company controlled b.pdf
An epic bribe scandal at Petrobras, a major oil company controlled b.pdfAn epic bribe scandal at Petrobras, a major oil company controlled b.pdf
An epic bribe scandal at Petrobras, a major oil company controlled b.pdf
ezycolours78
 
6. Edit the following for the format of a reference listREFERENCE.pdf
6. Edit the following for the format of a reference listREFERENCE.pdf6. Edit the following for the format of a reference listREFERENCE.pdf
6. Edit the following for the format of a reference listREFERENCE.pdf
ezycolours78
 
2.Distinguish between assigned and emergent leaders. Give an example.pdf
2.Distinguish between assigned and emergent leaders. Give an example.pdf2.Distinguish between assigned and emergent leaders. Give an example.pdf
2.Distinguish between assigned and emergent leaders. Give an example.pdf
ezycolours78
 
16) What are the two types of current What is different about the fl.pdf
16) What are the two types of current What is different about the fl.pdf16) What are the two types of current What is different about the fl.pdf
16) What are the two types of current What is different about the fl.pdf
ezycolours78
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
ezycolours78
 
The correct sequence of the phases of the cell cycle are A. prophase.pdf
The correct sequence of the phases of the cell cycle are  A. prophase.pdfThe correct sequence of the phases of the cell cycle are  A. prophase.pdf
The correct sequence of the phases of the cell cycle are A. prophase.pdf
ezycolours78
 

More from ezycolours78 (20)

An epic bribe scandal at Petrobras, a major oil company controlled b.pdf
An epic bribe scandal at Petrobras, a major oil company controlled b.pdfAn epic bribe scandal at Petrobras, a major oil company controlled b.pdf
An epic bribe scandal at Petrobras, a major oil company controlled b.pdf
 
6. Edit the following for the format of a reference listREFERENCE.pdf
6. Edit the following for the format of a reference listREFERENCE.pdf6. Edit the following for the format of a reference listREFERENCE.pdf
6. Edit the following for the format of a reference listREFERENCE.pdf
 
2.Distinguish between assigned and emergent leaders. Give an example.pdf
2.Distinguish between assigned and emergent leaders. Give an example.pdf2.Distinguish between assigned and emergent leaders. Give an example.pdf
2.Distinguish between assigned and emergent leaders. Give an example.pdf
 
3. What lines of evidence do we have that evolution has taken place.pdf
3. What lines of evidence do we have that evolution has taken place.pdf3. What lines of evidence do we have that evolution has taken place.pdf
3. What lines of evidence do we have that evolution has taken place.pdf
 
4. Where in your home would endospores most likely be found Wh b. .pdf
4. Where in your home would endospores most likely be found Wh b. .pdf4. Where in your home would endospores most likely be found Wh b. .pdf
4. Where in your home would endospores most likely be found Wh b. .pdf
 
25. Radium is called a _________ and replaces calcium in bones and c.pdf
25. Radium is called a _________ and replaces calcium in bones and c.pdf25. Radium is called a _________ and replaces calcium in bones and c.pdf
25. Radium is called a _________ and replaces calcium in bones and c.pdf
 
What skills does law enforcement need to combat cyber crimesSol.pdf
What skills does law enforcement need to combat cyber crimesSol.pdfWhat skills does law enforcement need to combat cyber crimesSol.pdf
What skills does law enforcement need to combat cyber crimesSol.pdf
 
Using Microsoft Visual Basics (.NET) ONLY!(This assignment encompa.pdf
Using Microsoft Visual Basics (.NET) ONLY!(This assignment encompa.pdfUsing Microsoft Visual Basics (.NET) ONLY!(This assignment encompa.pdf
Using Microsoft Visual Basics (.NET) ONLY!(This assignment encompa.pdf
 
were CPA involved in Enron scandal act with integrity as defined by .pdf
were CPA involved in Enron scandal act with integrity as defined by .pdfwere CPA involved in Enron scandal act with integrity as defined by .pdf
were CPA involved in Enron scandal act with integrity as defined by .pdf
 
16) What are the two types of current What is different about the fl.pdf
16) What are the two types of current What is different about the fl.pdf16) What are the two types of current What is different about the fl.pdf
16) What are the two types of current What is different about the fl.pdf
 
What are some weakness of the NERC standard CPS1 and CPS2.Please lis.pdf
What are some weakness of the NERC standard CPS1 and CPS2.Please lis.pdfWhat are some weakness of the NERC standard CPS1 and CPS2.Please lis.pdf
What are some weakness of the NERC standard CPS1 and CPS2.Please lis.pdf
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
 
The correct sequence of the phases of the cell cycle are A. prophase.pdf
The correct sequence of the phases of the cell cycle are  A. prophase.pdfThe correct sequence of the phases of the cell cycle are  A. prophase.pdf
The correct sequence of the phases of the cell cycle are A. prophase.pdf
 
Suppose an ant walks counterclockwise on the unit circle from the poi.pdf
Suppose an ant walks counterclockwise on the unit circle from the poi.pdfSuppose an ant walks counterclockwise on the unit circle from the poi.pdf
Suppose an ant walks counterclockwise on the unit circle from the poi.pdf
 
1. Which of the following statements correctly describes pulsating s.pdf
1. Which of the following statements correctly describes pulsating s.pdf1. Which of the following statements correctly describes pulsating s.pdf
1. Which of the following statements correctly describes pulsating s.pdf
 
The approach used in the U.S. to measure the economys aggregate per.pdf
The approach used in the U.S. to measure the economys aggregate per.pdfThe approach used in the U.S. to measure the economys aggregate per.pdf
The approach used in the U.S. to measure the economys aggregate per.pdf
 
Take the Leadership Interestingly, we study much about leadershi.pdf
Take the Leadership Interestingly, we study much about leadershi.pdfTake the Leadership Interestingly, we study much about leadershi.pdf
Take the Leadership Interestingly, we study much about leadershi.pdf
 
Relating to Emergency Managment, what evenys of the 1970s led to t.pdf
Relating to Emergency Managment, what evenys of the 1970s led to t.pdfRelating to Emergency Managment, what evenys of the 1970s led to t.pdf
Relating to Emergency Managment, what evenys of the 1970s led to t.pdf
 
Real Analysis proof not a regular calc limit questionSolutiont.pdf
Real Analysis proof not a regular calc limit questionSolutiont.pdfReal Analysis proof not a regular calc limit questionSolutiont.pdf
Real Analysis proof not a regular calc limit questionSolutiont.pdf
 
5. In the actual lab, you will also introduce liquid B into the stopp.pdf
5. In the actual lab, you will also introduce liquid B into the stopp.pdf5. In the actual lab, you will also introduce liquid B into the stopp.pdf
5. In the actual lab, you will also introduce liquid B into the stopp.pdf
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
YibeltalNibretu
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

Need help having my buttons play songs when clicked.package jukebo.pdf

  • 1. Need help having my buttons play songs when clicked. package jukebox; import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class MusicFrame extends JFrame { private Title title; private Songs song; public MusicFrame(){ setTitle("Dean's Fabulous Jukebox"); title = new Title(); song = new Songs(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(700, 900); setLayout(new FlowLayout(FlowLayout.CENTER)); add(title, BorderLayout.NORTH); add(song, BorderLayout.SOUTH); setVisible(true); } } //////////////////////// package jukebox; import javax.swing.Icon;
  • 2. import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; public class Title extends JPanel { public Title(){ Icon icon = new ImageIcon(getClass().getResource("Images/DJ.jpg")); JLabel label1 = new JLabel("Dean's JukeBox", icon, JLabel.LEFT); add(label1); } } //////////////// package jukebox; import java.awt.GridLayout; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; public class Songs extends JPanel{ public Songs(){ setLayout(new GridLayout(1,2)); Icon Song1Icon = new ImageIcon(getClass().getResource("Images/Down.jpg")); JButton song1 = new JButton("Don't Let Me Down", Song1Icon); add(song1);
  • 3. Icon Song2Icon = new ImageIcon(getClass().getResource("Images/Paris.jpg")); JButton song2 = new JButton("Paris", Song2Icon); add(song2); } } Solution add this code ClassLoader CLDR = this.getClass().getClassLoader(); InputStream soundName = CLDR.getResourceAsStream("yourDirectory/soundclip.wav"); AudioStream audioStream = new AudioStream(soundName); AudioPlayer.player.start(audioStream);