Your SlideShare is downloading. ×
15b more gui
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×