/*========================================================== * File:                 SimpleApp3.java * Function:             Demonstartes GUI passing of numerical args to a jMusic                          program and window closing * Author:               Andrew R. Brown * Environment           JDK1.1.7 *============================================================*/import java.awt.*;import java.awt.event.*;import jm.JMC;import jm.music.data.*;import jm.util.*;public class SimpleGUI3 extends Frame implements ActionListener, WindowListener,                                                                             JMC{	//--------------	// Attributes shared within the class	//--------------	TextField fileNameBox;	TextField minPitch;	TextField maxPitch;	TextField numOfNotes;        Button composeBtn;        //--------------	// simple main method called when the class in run	//--------------	public static void main(String[] args) {		new SimpleGUI3();	}		//--------------	// constructor	//--------------	public SimpleGUI3() {		//give the window a name		super("An almost real Application");				//register the closebox event		this.addWindowListener(this);				//set the layout for the Frame		this.setLayout(new GridLayout(5, 2, 5, 0));				//add the components		Label minPL = new Label("Minimum MIDI Pitch", Label.RIGHT);		this.add(minPL);				minPitch = new TextField("50");		this.add(minPitch);				Label maxPL = new Label("Maximun MIDI Pitch", Label.RIGHT);		this.add(maxPL);				maxPitch = new TextField("70");		this.add(maxPitch);				Label numNL = new Label("Number of notes", Label.RIGHT);		this.add(numNL);				numOfNotes = new TextField("12");		this.add(numOfNotes);				Label fNameLable = new Label("MIDI file name", Label.RIGHT);		this.add(fNameLable);				fileNameBox = new TextField("SimpleGUI_3.mid");		this.add(fileNameBox);				Label dummy = new Label("", Label.RIGHT);		this.add(dummy);				//create a panel to put the button on		// so it doesn't fill the grid space 		Panel p = new Panel();				//add the button		composeBtn = new Button("Compose");		composeBtn.addActionListener(this);		composeBtn.setActionCommand("Create");		p.add(composeBtn);				//put the panel in the frame		this.add(p);				//display the window		this.pack();									this.show();	}	//--------------	// Class Methods	//--------------		// Deal with the window closebox	public void windowClosing(WindowEvent we) {		System.exit(0);	}                //other WindowListener interface methods	//They do nothing but are required to be present	public void windowActivated(WindowEvent we) {};	public void windowClosed(WindowEvent we) {};	public void windowDeactivated(WindowEvent we) {};	public void windowIconified(WindowEvent we) {};	public void windowDeiconified(WindowEvent we) {};	public void windowOpened(WindowEvent we) {};		// Deal with the button click	public void actionPerformed(ActionEvent ae) {		if (ae.getSource() == composeBtn) {			String fn = fileNameBox.getText();				if (fn != null) {					makeMusic(fn,                                                   Integer.valueOf(                                                 minPitch.getText()).intValue(), 						  Integer.valueOf(                                                 maxPitch.getText()).intValue(),                                                   Integer.valueOf(                                              numOfNotes.getText()).intValue());				} else makeMusic("SimpleGUI_3.mid",                                                  Integer.valueOf(                                                 minPitch.getText()).intValue(), 						 Integer.valueOf(                                                 maxPitch.getText()).intValue(), 						 Integer.valueOf(                                              numOfNotes.getText()).intValue());		}	}		//--------------	// The code that creates the jMusic score	// and writes it as MIDI and jm files.	//--------------	public void makeMusic(String fileName, int minPitchVal, int maxPitchVal,                               int numOfNotesVal) {		Score scale = new Score("JMDemo - SimpleGUI_3", 130);		Part inst = new Part("Music", ATMOSPHERE, 0);		Phrase phr = new Phrase(0.0); 				for(short i=0;i<numOfNotesVal;i++){			Note note = new Note((int)((Math.random()*                                                    Math.abs(maxPitchVal-                                                             minPitchVal))+                                                   minPitchVal),                                                    SQ,                                                    (int)(Math.random() * 80 +                                                          40));			phr.addNote(note);		}		inst.addPhrase(phr);		scale.addPart(inst);				//save file to disk		Write.midi(scale, "SimpleGUI_3.mid");	}}