26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 22 <strong>Java</strong> Media Framework and <strong>Java</strong> Sound (on CD) 1303<br />

157 // set up configuration controls<br />

158 private void makeConfigureControls()<br />

159 {<br />

160 JPanel configurePanel =<br />

161 new JPanel( new GridLayout( 5, 1 ) );<br />

162<br />

163 controlPanel.add( configurePanel, BorderLayout.WEST );<br />

164<br />

165 instrumentBox = new JComboBox(<br />

166 midiSynthesizer.getInstruments() );<br />

167<br />

168 configurePanel.add( instrumentBox );<br />

169<br />

170 // register an ActionListener for instrumentBox events<br />

171 instrumentBox.addActionListener(<br />

172<br />

173 // anonymous inner class <strong>to</strong> handle instrument selec<strong>to</strong>r<br />

174 new ActionListener() {<br />

175<br />

176 // change current instrument program<br />

177 public void actionPerformed( ActionEvent event )<br />

178 {<br />

179 // change instrument in synthesizer<br />

180 midiSynthesizer.changeInstrument(<br />

181 instrumentBox.getSelectedIndex() );<br />

182 }<br />

183<br />

184 } // end ActionListener<br />

185<br />

186 ); // end call <strong>to</strong> method addActionListener<br />

187<br />

188 JLabel volumeLabel = new JLabel( "volume" );<br />

189 configurePanel.add( volumeLabel );<br />

190<br />

191 volumeSlider = new JSlider(<br />

192 SwingConstants.HORIZONTAL, 5, 80, 30 );<br />

193<br />

194 // register a ChangeListener for slider change events<br />

195 volumeSlider.addChangeListener(<br />

196<br />

197 // anonymous inner class <strong>to</strong> handle volume slider events<br />

198 new ChangeListener() {<br />

199<br />

200 // change volume<br />

201 public void stateChanged( ChangeEvent changeEvent )<br />

202 {<br />

203 midiVolume = volumeSlider.getValue();<br />

204 }<br />

205<br />

206 } // end class ChangeListener<br />

207<br />

208 ); // end call <strong>to</strong> method addChangeListener<br />

Fig. Fig. Fig. 22.10 22.10 22.10 MidiDemo provides the GUI than enables users <strong>to</strong> interact with the<br />

application (part 4 of 14).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!