Getting back to graphics…<br />LIS4930 © PIC<br />There are three ways to put things on a GUI.<br />1<br />2<br />3<br />P...
FYI – The Graphics Reference is to a Graphics2D Object<br />LIS4930 © PIC<br />public void paintComponent(Graphicsg) {   }...
We can get an event.We can paint graphics.But can we paint graphics when we get an event?<br />LIS4930 © PIC<br />
GUI Layouts<br />LIS4930 © PIC<br />NORTH<br />WEST<br />EAST<br />CENTER<br />frame.getContentPane().add(BorderLayout.CEN...
What If There Were Two Buttons?<br />LIS4930 © PIC<br />
How can we listen to two buttons with only one actionPerformed() method?<br />LIS4930 © PIC<br />1<br />2<br />3<br />Opti...
Using An Inner Class for Animation<br />LIS4930 © PIC<br />
Getting Back to Our Music Machine<br />LIS4930 © PIC<br />1<br />2<br />3<br />4<br />The thing that plays the music<br />...
We Then Need 5 Steps<br />LIS4930 © PIC<br />1<br />2<br />3<br />4<br />5<br />Get a Sequencer and open it<br />	Sequence...
Anatomy of a Message<br />LIS4930 © PIC<br />The first argument to setMessage() always represents the message ‘type’, whil...
Upcoming SlideShare
Loading in …5
×

15b more gui

449
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
449
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

15b more gui

  1. 1. Getting back to graphics…<br />LIS4930 © PIC<br />There are three ways to put things on a GUI.<br />1<br />2<br />3<br />Put widgets on a frame<br /> Add buttons, menus, radio buttons, etc.<br />frame.getContentPane( ).add(myButton);<br />Draw 2D graphics on a widget<br /> Use a graphics object to paint shapes<br /> graphics.fillOval(70,70,100,100);<br />Put a JPEG on a widget<br /> You can put your own images on a widget<br /> graphics.drawImage(myPic,10,10,this);<br />
  2. 2. FYI – The Graphics Reference is to a Graphics2D Object<br />LIS4930 © PIC<br />public void paintComponent(Graphicsg) { }<br />g is a Graphics reference and can call:<br />drawImage(), drawLine(), drawPolygon(), drawRect(), drawOval(), fillRect(), fillOval(), fillRoundRect(), and setColor().<br />But, g is also a Graphics2D reference which extends the Graphics class. It is still accepted by paintComponent because of polymorphism. Graphics2D references can call:<br />fill3DRect(), draw3DRect(), rotate(), scale(), shear(), transform(), setRenderingHints(), paint(), and many more.<br />However, we need to cast g from a Graphics reference to a Graphics2D reference to access the extra methods.<br />Graphics2D g2d = (Graphics2D) g;<br />
  3. 3. We can get an event.We can paint graphics.But can we paint graphics when we get an event?<br />LIS4930 © PIC<br />
  4. 4. GUI Layouts<br />LIS4930 © PIC<br />NORTH<br />WEST<br />EAST<br />CENTER<br />frame.getContentPane().add(BorderLayout.CENTER, button);<br />SOUTH<br />
  5. 5. What If There Were Two Buttons?<br />LIS4930 © PIC<br />
  6. 6. How can we listen to two buttons with only one actionPerformed() method?<br />LIS4930 © PIC<br />1<br />2<br />3<br />Option 1 (page 373)<br />Implement twoactionPerformed( ) methods?<br />Option 2 (page 373)<br />Register the same listener with both buttons?<br />Option 3 (page 374)<br />Create two separateActionListener classes?<br />There is a better way! Enter the INNER CLASS.<br />
  7. 7. Using An Inner Class for Animation<br />LIS4930 © PIC<br />
  8. 8. Getting Back to Our Music Machine<br />LIS4930 © PIC<br />1<br />2<br />3<br />4<br />The thing that plays the music<br /> Sequencer<br />The music to be played… a song.<br />Sequence<br />The part of the Sequence that holds the actual information.<br />Track<br />The actual music information: notes to play, how long, etc.<br />music information<br />
  9. 9. We Then Need 5 Steps<br />LIS4930 © PIC<br />1<br />2<br />3<br />4<br />5<br />Get a Sequencer and open it<br /> Sequencer player = MidiSystem.getSequencer( );<br />player.open( );<br />Make a new Sequence<br /> Sequence seq = new Sequence(timing, 4);<br />Get a new Track from the Sequence<br /> Track t = seq.createTrack( );<br />Fill the Track with MidiEvents and give the Sequence to the Sequencer<br /> t.add(MidiEvent1);<br />player.setSequence(seq);<br />Push the play button<br />player.start( );<br />DEMO TIME<br />
  10. 10. Anatomy of a Message<br />LIS4930 © PIC<br />The first argument to setMessage() always represents the message ‘type’, while the other three arguments represent different things depending on the message type.<br />a.setMessage(144, 1, 44, 100);<br />velocity<br />channel<br />note to play<br />message type<br />Check out some other messages: http://www.midi.org/about-midi/table2.shtml<br />Check out some other instruments: http://www.midi.org/techspecs/gm1sound.php#instrument<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×