15b more gui
Upcoming SlideShare
Loading in...5
×
 

15b more gui

on

  • 567 views

 

Statistics

Views

Total Views
567
Slideshare-icon Views on SlideShare
567
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    15b more gui 15b more gui Presentation Transcript

    • 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);
    • 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;
    • We can get an event.We can paint graphics.But can we paint graphics when we get an event?
      LIS4930 © PIC
    • GUI Layouts
      LIS4930 © PIC
      NORTH
      WEST
      EAST
      CENTER
      frame.getContentPane().add(BorderLayout.CENTER, button);
      SOUTH
    • What If There Were Two Buttons?
      LIS4930 © PIC
    • 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.
    • Using An Inner Class for Animation
      LIS4930 © PIC
    • 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
    • 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
    • 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