San José State University
College of Science/Computer Science Department
CS 151 – Object-Oriented Design, Section 5, Fall 2019
Learning to use Midi Components with Java
Problem: Analysis Phase
Create a Swing window with 2 buttons and a menu. One button plays a musical scale and the other stops it. The menu has an "Exit" menu item for quitting.
Details: Design and Implementation Phase
- You should write a Main class with a method with header "public static void main(String args)" that starts things going. To run your program, the user just needs to execute that method. The main method should create and display a JFrame (window).
- The window should have a File menu with one menu item "Exit". If the user selects this menu item, then the window disappears and the application quits.
- There should be a button named "Play" in the window that, when clicked, causes a dialog to appear asking the user for a note number in the range 0 to 115. Then an 8-note scale is played starting at the given note. The scale should be the usual Do Re Mi Fa Sol La Ti Do notes, not just any notes. You do not need to do error checking--that is, if the user enters something other than an integer from 0 to 115, it is okay for your program to crash.
- There should be a button named "Stop" in the window that, when clicked, causes the scale to stop playing immediately. If there is no scale currently playing, then nothing happens.
- Use a BorderLayout for the window, with the "Play" button at the left and the "Stop" button in the middle.
- All your methods need to have Javadoc style headers. If you are unfamiliar with Javadoc, take a look at http://java.sun.com/j2se/javadoc/writingdoccomments/
- The purpose of this project is to get you started practicing using libraries and learning how to read, use, and modify existing code. Therefore, I will not be giving you much written guidance in how to do what I want you to do in this project and you are expected to read the documentation and experiment with library code and code I give you to figure out how to do it. However, as mentioned in the course syllabus, I will be happy to help you if you come to me with questions after trying unsuccessfully to do it yourself first.
- To learn how to create the window I want, I recommend that you read the Java and SwingTutorial.
- A good place to look to find out what Swing classes (and other Java library classes) can do is the online Java 8 API. You are welcome to use Java 11 or 12 if you prefer.
- To help you play the notes, I have created a SimpleMidiPlayer class for you to use. It uses the javax.sound.midi package to generate MIDI sounds. It simplifies the interface to playing MIDI sounds so that you don't have to worry about all the details such as Sequencers, Tracks, and MidiEvents.
- You are welcome to learn more about MIDI and expand on the SimpleMidiPlayer if you wish, but you aren't required to do so. If you want to learn more about playing sounds in Java so that you can understand better the code that I gave you, you should read about the Java Sound API. In particular, you might want acquaint yourself with the Java Sound Demo, the Sound API Programmer's Guide and the documentation of the classes in the javax.sound.midi package that are part of the Java 1.3 (or higher) distribution. The guide and demo have a lot more information than you will ever need to know, so don't worry if you feel overwhelmed.
- You are welcome to create any additional classes and methods you wish.
- For extra credit, add the following feature: When the close box (in the upper right corner of the JFrame) is clicked, the application quits just like when the Exit menu item is chosen.
Back to Homepage