SlideShare ist ein Scribd-Unternehmen logo
1 von 10
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

Weitere ähnliche Inhalte

Was ist angesagt?

Digital logic circuit
Digital logic circuit Digital logic circuit
Digital logic circuit Prabhu R
 
1.ripple carry adder, full adder implementation using half adder.
1.ripple carry adder, full adder implementation using half adder.1.ripple carry adder, full adder implementation using half adder.
1.ripple carry adder, full adder implementation using half adder.MdFazleRabbi18
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your networkPushpendra Tiwari
 
Adder Presentation
Adder PresentationAdder Presentation
Adder PresentationMoeez Ahmad
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adderASHISH MANI
 
What is Adder-Half and Full Adder
What is Adder-Half and Full AdderWhat is Adder-Half and Full Adder
What is Adder-Half and Full AdderAdeel Rasheed
 
Expertise aircraft sli_h_lefi_01
Expertise aircraft sli_h_lefi_01Expertise aircraft sli_h_lefi_01
Expertise aircraft sli_h_lefi_01Hatem Lefi
 
Ripple look-ahead-header
Ripple look-ahead-headerRipple look-ahead-header
Ripple look-ahead-headerAbid Ali
 
Butterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite NetworksButterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite NetworksSeyed-Vahid Sanei-Mehri
 
Mi primer map reduce
Mi primer map reduceMi primer map reduce
Mi primer map reducebetabeers
 

Was ist angesagt? (20)

35th 36th Lecture
35th 36th Lecture35th 36th Lecture
35th 36th Lecture
 
Digital logic circuit
Digital logic circuit Digital logic circuit
Digital logic circuit
 
1.ripple carry adder, full adder implementation using half adder.
1.ripple carry adder, full adder implementation using half adder.1.ripple carry adder, full adder implementation using half adder.
1.ripple carry adder, full adder implementation using half adder.
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your network
 
PyLecture2 -NetworkX-
PyLecture2 -NetworkX-PyLecture2 -NetworkX-
PyLecture2 -NetworkX-
 
Ripple Carry Adder
Ripple Carry AdderRipple Carry Adder
Ripple Carry Adder
 
4 bit add sub
4 bit add sub4 bit add sub
4 bit add sub
 
07f03 carryskip
07f03 carryskip07f03 carryskip
07f03 carryskip
 
Adder Presentation
Adder PresentationAdder Presentation
Adder Presentation
 
My Report on adders
My Report on addersMy Report on adders
My Report on adders
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adder
 
What is Adder-Half and Full Adder
What is Adder-Half and Full AdderWhat is Adder-Half and Full Adder
What is Adder-Half and Full Adder
 
Adder
Adder Adder
Adder
 
Expertise aircraft sli_h_lefi_01
Expertise aircraft sli_h_lefi_01Expertise aircraft sli_h_lefi_01
Expertise aircraft sli_h_lefi_01
 
Half adder layout design
Half adder layout designHalf adder layout design
Half adder layout design
 
Ripple look-ahead-header
Ripple look-ahead-headerRipple look-ahead-header
Ripple look-ahead-header
 
Hardcore functional programming
Hardcore functional programmingHardcore functional programming
Hardcore functional programming
 
Butterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite NetworksButterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite Networks
 
Mi primer map reduce
Mi primer map reduceMi primer map reduce
Mi primer map reduce
 

Ähnlich wie 15b more gui

Actionscript 3 - Session 2 Getting Started Flash IDE
Actionscript 3 - Session 2 Getting Started Flash IDEActionscript 3 - Session 2 Getting Started Flash IDE
Actionscript 3 - Session 2 Getting Started Flash IDEOUM SAOKOSAL
 
C++ Windows Forms L09 - GDI P2
C++ Windows Forms L09 - GDI P2C++ Windows Forms L09 - GDI P2
C++ Windows Forms L09 - GDI P2Mohammad Shaker
 
Programming the BBC micro:bit with MicroPython by Dunham High School
Programming the BBC micro:bit with MicroPython by Dunham High SchoolProgramming the BBC micro:bit with MicroPython by Dunham High School
Programming the BBC micro:bit with MicroPython by Dunham High SchoolPYCON MY PLT
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 
Graphical Password Authentication Using Modified Persuasive Cued Click-Point
Graphical Password Authentication Using Modified Persuasive Cued Click-PointGraphical Password Authentication Using Modified Persuasive Cued Click-Point
Graphical Password Authentication Using Modified Persuasive Cued Click-Pointpaperpublications3
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfoptimusnotch44
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...bhargavi804095
 
Hands on Raspberry Pi - Creative Technologists
Hands on Raspberry Pi - Creative TechnologistsHands on Raspberry Pi - Creative Technologists
Hands on Raspberry Pi - Creative Technologistsbennuttall
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI ProgrammingRTS Tech
 
Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Unity Technologies
 
Keynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxKeynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxEqraKhattak
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1ssusera7a08a
 
intro_gui
intro_guiintro_gui
intro_guifilipb2
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfUmarMustafa13
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - IntroductionFrancis Seriña
 
Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185Mahmoud Samir Fayed
 

Ähnlich wie 15b more gui (20)

Objects and Graphics
Objects and GraphicsObjects and Graphics
Objects and Graphics
 
Chapter04.pptx
Chapter04.pptxChapter04.pptx
Chapter04.pptx
 
Actionscript 3 - Session 2 Getting Started Flash IDE
Actionscript 3 - Session 2 Getting Started Flash IDEActionscript 3 - Session 2 Getting Started Flash IDE
Actionscript 3 - Session 2 Getting Started Flash IDE
 
C++ Windows Forms L09 - GDI P2
C++ Windows Forms L09 - GDI P2C++ Windows Forms L09 - GDI P2
C++ Windows Forms L09 - GDI P2
 
Programming the BBC micro:bit with MicroPython by Dunham High School
Programming the BBC micro:bit with MicroPython by Dunham High SchoolProgramming the BBC micro:bit with MicroPython by Dunham High School
Programming the BBC micro:bit with MicroPython by Dunham High School
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Graphical Password Authentication Using Modified Persuasive Cued Click-Point
Graphical Password Authentication Using Modified Persuasive Cued Click-PointGraphical Password Authentication Using Modified Persuasive Cued Click-Point
Graphical Password Authentication Using Modified Persuasive Cued Click-Point
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...
 
Hands on Raspberry Pi - Creative Technologists
Hands on Raspberry Pi - Creative TechnologistsHands on Raspberry Pi - Creative Technologists
Hands on Raspberry Pi - Creative Technologists
 
Chap1
Chap1Chap1
Chap1
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
 
Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)
 
Keynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxKeynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptx
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
 
intro_gui
intro_guiintro_gui
intro_gui
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdf
 
Game Programming I - Introduction
Game Programming I - IntroductionGame Programming I - Introduction
Game Programming I - Introduction
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185
 

Mehr von Program in Interdisciplinary Computing (20)

Phpmysqlcoding
PhpmysqlcodingPhpmysqlcoding
Phpmysqlcoding
 
Database basics
Database basicsDatabase basics
Database basics
 
CGS2835 HTML5
CGS2835 HTML5CGS2835 HTML5
CGS2835 HTML5
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
CGS2835 HTML5
CGS2835 HTML5CGS2835 HTML5
CGS2835 HTML5
 
01 intro tousingjava
01 intro tousingjava01 intro tousingjava
01 intro tousingjava
 
Web architecture v3
Web architecture v3Web architecture v3
Web architecture v3
 
Xhtml
XhtmlXhtml
Xhtml
 
Webdev
WebdevWebdev
Webdev
 
Web architecture
Web architectureWeb architecture
Web architecture
 
Sdlc
SdlcSdlc
Sdlc
 
Mysocial
MysocialMysocial
Mysocial
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Html5
Html5Html5
Html5
 
Frameworks
FrameworksFrameworks
Frameworks
 
Drupal
DrupalDrupal
Drupal
 
Database
DatabaseDatabase
Database
 
Javascript2
Javascript2Javascript2
Javascript2
 

15b more gui

  • 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