05_inout - Input and Output 1.5 Input and Output Input...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 1.5 Input and Output 2 Input and Output Input devices. Output devices. Goal. Java programs that interact with the outside world. Display Speakers MP3 Player Printer Mouse Keyboard Digital camera Microphone Hard drive Network Hard drive Network 3 Input and Output Input devices. Output devices. Our approach. Define Java libraries of functions for input and output. Use operating system (OS) to connect Java programs to: file system, each other, keyboard, mouse, display, speakers. Display Speakers MP3 Player Printer Mouse Keyboard Digital camera Microphone Hard drive Network Hard drive Network 4 Digital Michelangelo Project Goal. Precise 3D description of the David. Laser rangefinder. 5,000 hours of scanning, 32 Gigabytes !
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 5 Terminal. Application where you can type commands to control the operating system. Terminal Mac OS X Microsoft Windows 6 Operating System Specific Details Common OS abstractions. <, >, | <, >, | <, >, | Redirection, pipes Ctrl-d <Enter>Ctrl-d Ctrl-z End of file more less more less more Scroll through text, one screenful at a time File system List files in current directory Newline character File name completion Cycle through recent command Operation \n \n or \r \r\n ls ls dir C:\introcs\Hi.java Tab Up, down arrows Windows XP /u/introcs/Hi.java /u/introcs/Hi.java Tab Tab Up, down arrows Up, down arrows Unix OS X Unix means Unix variants (Linux, Solaris, Aix) Most Windows XP commands also supported in other version of Windows. 7 User Interfaces Command line interface. User types commands at terminal. Easily customizable. Extends to complex command sequences. Point and click. User launches applications by clicking. – File Open HelloWorld.java Restricted to pre-packaged menu options. 8 Swing Graphical User Interface "Swing" is Java's GUI. Buttons. Menus. Scrollbars. Toolbars. File choosers. Ignore details. import javax . swing .*; import java . awt .*; import java . awt . event .*; public class GUI implements ActionListener { private int clicks = 0 ; private JFrame frame = new JFrame (); private JLabel label = new JLabel ( "Number of clicks: 0 " ); public GUI () { JButton button = new JButton ( "Click Me" ); button . addActionListener ( this ); JPanel panel = new JPanel (); panel . setBorder ( BorderFactory . createEmptyBorder ( 30 , 30 , 10 , 30 )); panel . setLayout ( new GridLayout ( 0 , 1 )); panel . add ( button ); panel . add ( label ); frame . add ( panel , BorderLayout . CENTER ); frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ); frame . setTitle ( "GUI" ); frame . pack (); frame . show (); } public void actionPerformed ( ActionEvent e ) { clicks ++; label . setText ( "Number of clicks: " + clicks ); } ; public static void main ( String [] args ) { GUI gui = new GUI (); } } a sample Swing application
Background image of page 2
3 9 Command-Line Input and Standard Output
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

05_inout - Input and Output 1.5 Input and Output Input...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online