Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Beginning Java
Music Player
Spandan Pandey
Greenhorn
Posts: 10
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I ran this program,it compiled but nothing happened.
Would love your help!!Thanks!!
import javax.sound.midi.*; import java.io.*; import javax.swing.*; import java.awt.*; public class MiniMusicPlayer3 { static JFrame f = new JFrame("My First Music Video"); static MyDrawPanel m1; public static void main(String[ ] args) { MiniMusicPlayer3 mini = new MiniMusicPlayer3( ); mini.go( ); } public void setUpGUI( ) { m1 = new MyDrawPanel( ); f.setContentPane(m1); f.setBounds(30,30,300,300); f.setVisible(true); } public void go ( ) { try { Sequencer sequencer = MidiSystem.getSequencer( ); sequencer.open( ); sequencer.addControllerEventListener(m1, new int[ ] {127} ); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack( ); int r = 0; for(int i= 0;i<60;i+=4) { r = (int) ((Math.random( ) * 50 ) + 1); track.add(makeEvent(144,1,r,100,i)); track.add(makeEvent(176,1,127,0,i)); track.add(makeEvent(128,1,r,100,i+2)); } sequencer.setSequence(seq); sequencer.start( ); sequencer.setTempoInBPM(120); }catch (Exception ex) {ex.printStackTrace( ) ; } } public MidiEvent makeEvent( int comd, int chan,int one,int two,int tick) { MidiEvent event = null; try { ShortMessage a = new ShortMessage ( ); a.setMessage(comd,chan,one,two); event = new MidiEvent(a,tick); }catch(Exception e) { } return event; } class MyDrawPanel extends JPanel implements ControllerEventListener { boolean msg = false; public void controlChange(ShortMessage event) { msg = true; repaint ( ); } public void paintComponent(Graphics g) { if(msg) { Graphics2D g2 = (Graphics2D) g; int r =(int) (Math.random( ) * 250); int gr=(int) (Math.random( ) * 250); int b = (int) (Math.random( ) * 250); g.setColor(new Color(r,gr,b)); int ht= (int) ((Math.random( ) * 120)+10); int width=(int) ((Math.random ( ) * 120)+10); int x =(int) ((Math.random( ) * 40) + 10); int y =(int) ((Math.random( ) * 40)+ 10); g.fillRect(x,y,ht,width); msg = false; } } } }
Ulf Dittmer
Rancher
Posts: 43081
77
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
As to the GUI code, none of that is ever called, so it's to be expected that nothing is shown.
As to the Mid code, empty exception handlers like "}catch(Exception e) { }" are generally a bad idea.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Java Class hangs after run
Head First Java problem
Head First Java, Ch12, MiniMusicPlayer3 not working as advertised
widget not loading in frame
MiniMusicPlayer HFJ
More...