Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING JAVA II LANGUAGE GUI You work for Rupp Arena in Lexington and have been as

ID: 3879191 • Letter: U

Question

USING JAVA II LANGUAGE

GUI

You work for Rupp Arena in Lexington and have been asked to develop a Java application to collect information from bands who want to audition as an opening band for major concerts that come to town. Music concerts are only booked on Tuesdays, Fridays, and Saturdays. You have sketched out a GUI to use:

You may use a Layout Manager for this application. If you do, use one that is demonstrated in the
textbook, requires only 1 panel, and is easy to use.
Add an image to display at the top of the form (small graphic no larger than 50 kb to accommodate
downloading for grading)
Use text fields for the name of the band, website/facebook page address, contact name, and
contact phone number.
Use radio buttons for the two sound clips. If one of the radio buttons is clicked, the corresponding
sound clip should play. If a sound clip is playing and another radio button is clicked, you should
make sure the first sound clips stops before the second one plays. The two sound clips should be
short and have a small file size. Samples are provided in Blackboard if you want to use those.
Please DO NOT use large files.
The days of the week (Tuesday, Friday, and Saturday) are checkboxes. The user may check all that
apply.
When the Submit Audition button is clicked, the output area shown on page 1 should be
populated using data from the form and as illustrated on page 1.
When the Clear Form button is clicked, the form should be cleared (text boxes cleared, radio
button cleared (not selected), checkboxes cleared (not selected) and output area should be cleared.
Place the focus (cursor) in the first textbox so that the user is ready to enter data.
When the Exit button is clicked, the GUI application closes.
Deductions

use the same GUI structure as is illustrated in Chapter 6 (use one panel and one driver). Keep your solutions simple. DO NOT USE MULTIPLE PANELS FOR THIS SOLUTION.

Some tmage You Choose Name of Band: Band websíte or Facebook page sample sound clips of songs o samplei o sample 2 Days of the week you are typically available for playing (check all that apply) Tuesday Friday Saturday contact Name: contact Phone Submit Audition Clear Form Exit rextArea below is populated after the Submit Audition button is clicked The following information was successfully submitted Band: The Eagles website/FB Page: https://www.eagles.com Sound clips were successfully upolateo The Eagles are available to play ovn -Friday saturday Contact tnformation: Don Henley at 606-555-1212

Explanation / Answer

import javax.sound.sampled.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.File;

import java.net.URL;

public class Registration extends JFrame implements ActionListener

{

JLabel l1, l2, l3, l4, l5, l6, l7;

JTextField tf1, tf2, tf3, tf4;

JButton btn1, btn2, btn3;

JRadioButton r1,r2;

JCheckBox chk1,chk2,chk3;

TextArea ta1;

File wavFile;

URL defaultSound;

public static Clip clip;

public static AudioInputStream audioInputStream;

Registration()

{

setVisible(true);

setSize(700, 700);

setLayout(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setTitle("Band Registeration Form");

ImageIcon img=new ImageIcon("saved.png");

l1 = new JLabel(img);

l2 = new JLabel("Name of Band:");

l3 = new JLabel("Band website or Facebook page:");

l4 = new JLabel("Sample sound clips of songs:");

l5 = new JLabel("Days of week you are typically available for playing(check all that apply):");

l6 = new JLabel("Contact Name:");

l7 = new JLabel("Contact Phone:");

tf1 = new JTextField();

tf2 = new JTextField();

r1 = new JRadioButton("Sampe1");

r2 = new JRadioButton("Sample2");

  

ButtonGroup songs=new ButtonGroup();

  

songs.add(r1);   

songs.add(r2);

  

r1.addActionListener(this);

  

r2.addActionListener(this);

  

chk1=new JCheckBox("Tuesday");

  

chk2=new JCheckBox("Friday");

  

chk3=new JCheckBox("Saturday");

  

  

tf3 = new JTextField();

tf4 = new JTextField();

btn1 = new JButton("Submit Form");

btn2 = new JButton("Clear Form");

btn3 = new JButton("Exit");

ta1 =new TextArea();

btn1.addActionListener(this);

btn2.addActionListener(this);

btn3.addActionListener(this);

l1.setBounds(100, 30, 400, 30);

l2.setBounds(80, 70, 200, 30);

l3.setBounds(80, 110, 200, 30);

l4.setBounds(80, 150, 200, 30);

r1.setBounds(80, 170, 200, 30);

r2.setBounds(80, 190, 200, 30);

l5.setBounds(80, 230, 500, 30);

chk1.setBounds(80, 250, 200, 30);

chk2.setBounds(80,270,200,30);

chk3.setBounds(80,290,200,30);

l6.setBounds(80, 330, 200, 30);

l7.setBounds(80, 370, 200, 30);

tf1.setBounds(300, 70, 200, 30);

tf2.setBounds(300, 110, 200, 30);

tf3.setBounds(300, 330, 200, 30);

tf4.setBounds(300, 370, 200, 30);

btn1.setBounds(50, 410, 130, 30);

btn2.setBounds(200, 410, 100, 30);

btn3.setBounds(350, 410, 100, 30);

ta1.setBounds(50, 470, 400, 150);

add(l1);

add(l2);

add(tf1);

add(l3);

add(tf2);

add(l4);

add(r1);

add(r2);

add(l5);

add(chk1);

add(chk2);

add(chk3);

add(l6);

add(tf3);

add(l7);

add(tf4);

add(btn1);

add(btn2);

add(btn3);

add(ta1);

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource() == btn1)

{

try

{

String s1 = tf1.getText();

String s2 = tf2.getText();

String s3 = tf3.getText();

String s4 = tf4.getText();

String s5=" ",s6=" ",s7=" ";

if(chk1.isSelected())

{

s5=chk1.getText();

}

if(chk2.isSelected())

{

s6=chk2.getText();

}

if(chk3.isSelected())

{

s7=chk3.getText();

}

String str="The following information was successfully submitted: Band: "+s1+" Website/FB Page:"+s2+" Sound clips were successfully updated "+s1+" are available to play on "+s5+" "+s6+" "+s7+" "+"Contact Information: "+s3 +" at "+s4;

ta1.setText(str);

}

catch (Exception ex)

{

System.out.println(ex);

}

}  

else if (e.getSource() == btn2)

{

tf1.setText("");

tf2.setText("");

tf3.setText("");

tf4.setText("");

r1.setSelected(false);

r2.setSelected(false);

chk1.setSelected(false);

chk2.setSelected(false);

chk3.setSelected(false);

tf1.setFocusable(true);

}

else if (e.getSource() == btn3)

{

System.exit(0);

}

else if (e.getSource() == r1)

{

play();

}

else if (e.getSource() == r2)

{

play();

}

}

public void play() {

try {

defaultSound = new URL ("file:C:/image/song.wav");

audioInputStream = AudioSystem.getAudioInputStream(defaultSound);

try {

clip = AudioSystem.getClip();

clip.open(audioInputStream);

clip.loop(20000);

clip.start();

} catch (LineUnavailableException e) {

}

} catch (Exception e) {

}

}

public void stop() {

clip.stop();

}

public static void main(String args[])

{

new Registration();

}

}