├── README.md ├── javanotes9-swing ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── BUILD-exercise-programs.sh ├── README-exercise-solutions.txt ├── README-running-the-examples.txt ├── README.txt ├── c1-overview │ ├── overview-GUIDemo.png │ └── overview-fig5.png ├── c11-IO │ └── CheckersWithFiles.png ├── c12-threads │ ├── estimating-pi.png │ ├── multiprocessing-demo-1.png │ └── towers-of-hanoi-gui.png ├── c13-GUI2 │ ├── button-with-icon.png │ ├── cards.png │ ├── exercises.xml │ ├── high-low-with-images.png │ ├── intro.xml │ ├── java-button.png │ ├── mandelbrot.png │ ├── measuring-strings.png │ ├── paint-demo.png │ ├── quiz.xml │ ├── s1.xml │ ├── s2.xml │ ├── s3.xml │ ├── s4.xml │ ├── s5.xml │ ├── scatter-plot-demo.png │ ├── silly-stamper.png │ ├── smudgedRectangle.png │ ├── stroke-demo.png │ └── toolbar.png ├── c2-basics │ └── eclipse-create-project.png ├── c3-control │ └── random-circles.png ├── c4-subroutines │ └── mosaic.png ├── c5-OOP │ └── shapedraw-screenshot.png ├── c6-GUI1 │ ├── blackjack-gui.png │ ├── border-demo.png │ ├── border-layout.png │ ├── clickable-checkerboard.png │ ├── crisscross.png │ ├── event-handling.png │ ├── exercises.xml │ ├── flow-layout-demo.png │ ├── grid-layout.png │ ├── high-low-gui.png │ ├── intro.xml │ ├── mosaic-draw.png │ ├── null-layout-demo.png │ ├── panels-in-layout.png │ ├── pixel-coordinates.png │ ├── polygon.png │ ├── quiz.xml │ ├── roll-dice-gui.png │ ├── s1.xml │ ├── s2.xml │ ├── s3.xml │ ├── s4.xml │ ├── s5.xml │ ├── s6.xml │ ├── s7.xml │ ├── s8.xml │ ├── simple-calc.png │ ├── simple-paint.png │ ├── simple-stamper-with-drag.png │ ├── simple-stamper.png │ ├── slider-and-button-demo.png │ ├── slider-demo.png │ ├── square-in-circle.png │ ├── stat-calc-gui.png │ ├── sub-killer.png │ └── text-count.png ├── c7-arrays │ ├── checkers-game.png │ └── gomoku-board.png ├── c8-robustness │ └── SimpleGrapher.png ├── c9-recursion │ ├── blobs.png │ └── depth-breadth.png ├── convert-check-sourcerefs.xsl ├── convert-epub.xsl ├── convert-exercise-progs.xsl ├── convert-lulu.xsl ├── convert-tex-linked.xsl ├── convert-tex.xsl ├── convert-web.xsl ├── image-sources-inkscape │ ├── border-layout.svg │ ├── event-handling.svg │ ├── grid-layout.svg │ ├── overview-fig5.svg │ ├── panels-in-layout.svg │ └── pixel-coordinates.svg ├── images-tex │ ├── CheckersWithFiles.eps │ ├── SimpleGrapher.eps │ ├── blackjack-gui.eps │ ├── blobs.eps │ ├── border-demo.eps │ ├── border-layout.eps │ ├── button-with-icon.eps │ ├── cards.eps │ ├── checkers-game.eps │ ├── clickable-checkerboard.eps │ ├── depth-breadth.eps │ ├── eclipse-create-project.eps │ ├── estimating-pi.eps │ ├── event-handling.eps │ ├── flow-layout-demo.eps │ ├── gomoku-board.eps │ ├── grid-layout.eps │ ├── high-low-gui.eps │ ├── high-low-with-images.eps │ ├── java-button.eps │ ├── mandelbrot.eps │ ├── measuring-strings.eps │ ├── mosaic-draw.eps │ ├── multiprocessing-demo-1.eps │ ├── null-layout-demo.eps │ ├── overview-GUIDemo.eps │ ├── overview-fig5.eps │ ├── paint-demo.eps │ ├── panels-in-layout.eps │ ├── pixel-coordinates.eps │ ├── polygon.eps │ ├── random-circles.eps │ ├── roll-dice-gui.eps │ ├── scatter-plot-demo.eps │ ├── shapedraw-screenshot.eps │ ├── silly-stamper.eps │ ├── simple-calc.eps │ ├── simple-paint.eps │ ├── simple-stamper-with-drag.eps │ ├── simple-stamper.eps │ ├── slider-and-button-demo.eps │ ├── slider-demo.eps │ ├── smudgedRectangle.eps │ ├── square-in-circle.eps │ ├── stat-calc-gui.eps │ ├── stroke-demo.eps │ ├── sub-killer.eps │ ├── text-count.eps │ ├── toolbar.eps │ └── towers-of-hanoi-gui.eps ├── javanotes9-cover-180x235.png ├── javanotes9-cover-518x675.jpg ├── javanotes9.dtd ├── make-jar-files.bat ├── make-jar-files.sh ├── publish.sh ├── src-c1 │ └── GUIDemo.java ├── src-c11 │ ├── SimplePaintWithFiles.java │ ├── SimplePaintWithXML.java │ ├── TrivialEdit.java │ └── XMLDemo.java ├── src-c12 │ ├── BackgroundCompWithInvoke.java │ ├── BackgroundComputationDemo.java │ ├── GUIChat.java │ ├── MultiprocessingDemo1.java │ ├── MultiprocessingDemo2.java │ ├── MultiprocessingDemo3.java │ ├── MultiprocessingDemo4.java │ ├── QuicksortThreadDemo.java │ ├── RandomArtWithThreads.java │ ├── TowersOfHanoiGUI.java │ └── netgame │ │ ├── chat │ │ ├── ChatRoomServer.java │ │ └── ChatRoomWindow.java │ │ ├── common │ │ ├── Client.java │ │ ├── DisconnectMessage.java │ │ ├── ForwardedMessage.java │ │ ├── Hub.java │ │ ├── ResetSignal.java │ │ └── StatusMessage.java │ │ ├── fivecarddraw │ │ ├── Main.java │ │ ├── PokerCard.java │ │ ├── PokerDeck.java │ │ ├── PokerGameState.java │ │ ├── PokerHub.java │ │ ├── PokerRank.java │ │ ├── PokerWindow.java │ │ └── cards.png │ │ └── tictactoe │ │ ├── Main.java │ │ ├── TicTacToeGameHub.java │ │ ├── TicTacToeGameState.java │ │ └── TicTacToeWindow.java ├── src-c13 │ ├── ChoiceDemo.java │ ├── CursorDemo.java │ ├── CustomComponentTest.java │ ├── HighLowWithImages.java │ ├── MirrorText.java │ ├── PaintDemo.java │ ├── PaintWithOffScreenCanvas.java │ ├── QueenOfHearts.png │ ├── ScatterPlotTableDemo.java │ ├── SillyStamper.java │ ├── SimpleRTFEdit.java │ ├── SimpleWebBrowser.java │ ├── SimpleWebBrowserWithThread.java │ ├── StatesAndCapitalsTableDemo.java │ ├── StopWatchLabel.java │ ├── StrokeDemo.java │ ├── TinySmiley.png │ ├── ToolBarDemo.java │ ├── TransformDemo.java │ ├── TransparencyDemo.java │ ├── cards.png │ ├── edu │ │ └── hws │ │ │ └── eck │ │ │ └── mdb │ │ │ ├── I18n.java │ │ │ ├── Main.java │ │ │ ├── MandelbrotDisplay.java │ │ │ ├── MandelbrotFrame.java │ │ │ ├── MandelbrotPanel.java │ │ │ ├── Menus.java │ │ │ ├── SetImageSizeDialog.java │ │ │ ├── SetLimitsDialog.java │ │ │ ├── examples │ │ │ ├── README.txt │ │ │ ├── settings1.mdb │ │ │ ├── settings10.mdb │ │ │ ├── settings11.mdb │ │ │ ├── settings12.mdb │ │ │ ├── settings2.mdb │ │ │ ├── settings3.mdb │ │ │ ├── settings4.mdb │ │ │ ├── settings5.mdb │ │ │ ├── settings6.mdb │ │ │ ├── settings7.mdb │ │ │ ├── settings8.mdb │ │ │ └── settings9.mdb │ │ │ └── strings.properties │ ├── face-smile.png │ └── stamper_icons │ │ ├── README.txt │ │ ├── icon10.png │ │ ├── icon11.png │ │ ├── icon24.png │ │ ├── icon25.png │ │ ├── icon26.png │ │ ├── icon31.png │ │ ├── icon33.png │ │ ├── icon34.png │ │ ├── icon5.png │ │ ├── icon7.png │ │ ├── icon8.png │ │ └── icon9.png ├── src-c3 │ ├── MovingRects.java │ ├── SimpleAnimationStarter.java │ └── SimpleGraphicsStarter.java ├── src-c4 │ ├── Mosaic.java │ ├── MosaicCanvas.java │ ├── RandomMosaicWalk.java │ └── RandomMosaicWalk2.java ├── src-c5 │ ├── CircleInfo.java │ ├── GrowingCircleAnimation.java │ └── ShapeDraw.java ├── src-c6 │ ├── BashfulButton.java │ ├── BorderDemo.java │ ├── ClickableRandomStrings.java │ ├── HelloWorldGUI1.java │ ├── HelloWorldGUI2.java │ ├── HelloWorldGUI3.java │ ├── HighLowGUI.java │ ├── KeyboardAndFocusDemo.java │ ├── MosaicDraw.java │ ├── MosaicDrawController.java │ ├── NullLayoutDemo.java │ ├── RandomArt.java │ ├── RandomArtWithNestedClass.java │ ├── RandomStrings.java │ ├── RandomStringsPanel.java │ ├── RandomStringsPanelWithMain.java │ ├── SimpleCalc.java │ ├── SimpleColorChooser.java │ ├── SimpleDialogDemo.java │ ├── SimplePaint.java │ ├── SimpleStamper.java │ ├── SimpleTrackMouse.java │ ├── SliderAndButtonDemo.java │ ├── SliderDemo.java │ ├── SliderDemoWithLambda.java │ ├── SubKiller.java │ └── TextAreaDemo.java ├── src-c7 │ ├── Checkers.java │ ├── Life.java │ ├── RandomStringsWithArray.java │ └── SimplePaint2.java ├── src-c9 │ ├── Blobs.java │ ├── DepthBreadth.java │ ├── LittlePentominos.java │ └── Maze.java ├── src-extra │ ├── BlackjackHand.java │ ├── Card.java │ ├── Deck.java │ └── Hand.java └── texmacros.tex └── javanotes9 ├── .classpath ├── .gitignore ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── BUILD-env.sh ├── BUILD-epub.sh ├── BUILD-exercise-programs.sh ├── BUILD-linked-pdf.sh ├── BUILD-lulu.sh ├── BUILD-pdf.sh ├── BUILD-web-site.sh ├── README-exercise-solutions.txt ├── README-running-the-examples.txt ├── README.txt ├── TextIO_Javadoc ├── allclasses-frame.html ├── allclasses-noframe.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index.html ├── package-list ├── script.js ├── stylesheet.css └── textio │ ├── TextIO.html │ ├── package-frame.html │ └── package-summary.html ├── c1-overview ├── intro.xml ├── overview-GUIDemo.png ├── overview-fig1.png ├── overview-fig2.png ├── overview-fig3.png ├── overview-fig4.png ├── overview-fig5.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml ├── s6.xml └── s7.xml ├── c10-generics ├── exercises.xml ├── hash-table.png ├── intro.xml ├── list-positions.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml └── s6.xml ├── c11-IO ├── CheckersWithFiles.png ├── exercises.xml ├── intro.xml ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml └── s5.xml ├── c12-threads ├── estimate_pi_figure.png ├── estimating-pi.png ├── exercises.xml ├── hub-and-client-threads.png ├── hub-and-clients.png ├── intro.xml ├── multiprocessing-demo-1.png ├── producer-consumer.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml ├── threads-vs-subroutines.png └── towers-of-hanoi-gui.png ├── c13-GUI2 ├── alerts.png ├── bound-property-demo.png ├── edit-list-demo.png ├── exercises.xml ├── gradient-rect.png ├── intro.xml ├── line-attributes.png ├── linear-gradient.png ├── mandelbrot.png ├── paint-demo.png ├── quiz.xml ├── radial-gradient.jpg ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml ├── scatter-plot.png ├── scratch-off.jpg ├── silly-stamper.png ├── smudge-rect.png ├── stroke-demo.png ├── table-demo.png └── transforms.png ├── c2-basics ├── eclipse-create-project.png ├── eclipse-fx.png ├── exercises.xml ├── intro.xml ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml └── s6.xml ├── c3-control ├── array-of-ints.png ├── checkerboard.png ├── coords-and-shapes.png ├── exercises.xml ├── for-loop-flow-control.png ├── if-else-flow-control.png ├── intro.xml ├── motion-demo.png ├── moving-rects.png ├── multiway-if-flow-control.png ├── parallel-lines.png ├── quiz.xml ├── random-circles.png ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml ├── s6.xml ├── s7.xml ├── s7a.xml ├── s8.xml ├── two-d-array.png └── while-and-if-flow-control.png ├── c4-subroutines ├── exercise-mosaic-brighten.png ├── exercise-mosaic-convert.png ├── exercises.xml ├── intro.xml ├── mosaic.png ├── package-class-subroutine.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s4a.xml ├── s5.xml ├── s6.xml └── s7.xml ├── c5-OOP ├── beveled-rects.png ├── class-userdata.png ├── exercises.xml ├── growing-circles.png ├── instance-of-PlayerData.png ├── intro.xml ├── multiple-inheritance.png ├── objects-in-heap.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml ├── s6.xml ├── s7.xml ├── s8.xml ├── shapedraw-screenshot.png ├── subclass-superclass.png ├── various-shapes.png └── vehicle-hierarchy.png ├── c6-GUI1 ├── HelloWorldFX-screenshot.png ├── StatCalcGUI-less-ugly.png ├── StatCalcGUI-ugly.png ├── TextInputDemo.png ├── blackjack-gui.png ├── border-demo.png ├── border-layout.png ├── cards.png ├── clickable-checkerboard.png ├── colorRadioButtons.png ├── crisscross.png ├── event-handling.png ├── exercises.xml ├── grid-layout.png ├── high-low-gui.png ├── intro.xml ├── mosaic-draw.png ├── null-layout-demo.png ├── panels-in-layout.png ├── pixel-coordinates.png ├── polygon.png ├── quiz.xml ├── randomCards.png ├── randomStrings.png ├── roll-dice-gui.png ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml ├── s6.xml ├── s7.xml ├── s8.xml ├── scene-graph.png ├── simple-calc.png ├── simple-paint.png ├── simple-stamper-with-drag.png ├── simple-stamper.png ├── slider-and-button-demo.png ├── slider-demo.png ├── square-in-circle.png ├── stat-calc-gui.png ├── sub-killer.png └── text-count.png ├── c7-arrays ├── checkerboard-contents.png ├── checkers-game.png ├── delete-from-array.png ├── exercises.xml ├── gomoku-board.png ├── insertion-sort.png ├── intro.xml ├── life-neighbors.png ├── life-rules.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s3a.xml ├── s4.xml ├── s5.xml ├── symmetric-matrix.png └── two-dimensional-array.png ├── c8-robustness ├── SimpleGrapher.png ├── exception-hierarchy.png ├── exercises.xml ├── intro.xml ├── quiz.xml ├── rates-of-growth.png ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml └── s5.xml ├── c9-recursion ├── QuicksortStep.png ├── TowersOfHanoi.png ├── binary-sort-tree.png ├── binary-tree.png ├── blobs.png ├── build-bst.png ├── depth-breadth.png ├── exercises.xml ├── expression-tree.png ├── insert-in-list.png ├── intro.xml ├── linked-data-structures.png ├── list-with-head.png ├── looped-list.png ├── queue.png ├── quiz.xml ├── s1.xml ├── s2.xml ├── s3.xml ├── s4.xml ├── s5.xml └── stack.png ├── convert-check-sourcerefs.xsl ├── convert-epub.xsl ├── convert-exercise-progs.xsl ├── convert-lulu.xsl ├── convert-tex-linked.xsl ├── convert-tex.xsl ├── convert-web.xsl ├── epub-files ├── META-INF │ └── container.xml ├── OEBPS │ ├── cover.html │ ├── exercise-answers-intro.html │ └── quiz-answers-intro.html └── mimetype ├── export-source-swing.sh ├── export-source.sh ├── glossary.xml ├── image-sources-inkscape ├── array-of-ints.svg ├── beveled-rects.svg ├── binary-sort-tree.svg ├── binary-tree.svg ├── border-layout.svg ├── build-bst.svg ├── checkerboard-contents.svg ├── class-userdata.svg ├── coords-and-shapes.svg ├── delete-from-array.svg ├── event-handling.svg ├── exception-hierarchy.svg ├── expression-tree.svg ├── for-loop-flow-control.svg ├── grid-layout.svg ├── hash-table.svg ├── hub-and-client-threads.svg ├── hub-and-clients.svg ├── if-else-flow-control.svg ├── insert-in-list.svg ├── insertion-sort.svg ├── instance-of-PlayerData.svg ├── life-neighbors.svg ├── life-rules.svg ├── line-attributes.svg ├── linked-data-structures.svg ├── list-positions.svg ├── list-with-head.svg ├── looped-list.svg ├── measuring-strings.svg ├── multiple-inheritance.svg ├── multiway-if-flow-control.svg ├── objects-in-heap.svg ├── objects-in-heap.svg.2014_06_17_11_44_31.0.svg ├── overview-fig1.svg ├── overview-fig2.svg ├── overview-fig3.svg ├── overview-fig4.svg ├── overview-fig5.svg ├── package-class-subroutine.svg ├── panels-in-layout.svg ├── parallel-lines.svg ├── pixel-coordinates.svg ├── producer-consumer.svg ├── queue.svg ├── scene-graph.svg ├── stack.svg ├── subclass-superclass.svg ├── symmetric-matrix.svg ├── threads-vs-subroutines.svg ├── transforms.svg ├── two-d-array.svg ├── two-dimensional-array.svg ├── various-shapes.svg ├── vehicle-hierarchy.svg └── while-and-if-flow-control.svg ├── images-tex ├── CheckersWithFiles.eps ├── HelloWorldFX-screenshot.eps ├── QuicksortStep.eps ├── SimpleGrapher.eps ├── StatCalcGUI-less-ugly.eps ├── StatCalcGUI-ugly.eps ├── TextInputDemo.eps ├── TowersOfHanoi.eps ├── alerts.eps ├── array-of-ints.eps ├── beveled-rects.eps ├── binary-sort-tree.eps ├── binary-tree.eps ├── blackjack-gui.eps ├── blobs.eps ├── border-demo.eps ├── border-layout.eps ├── bound-property-demo.eps ├── build-bst.eps ├── cards.eps ├── checkerboard-contents.eps ├── checkerboard.eps ├── checkers-game.eps ├── class-userdata.eps ├── clickable-checkerboard.eps ├── colorRadioButtons.eps ├── coords-and-shapes.eps ├── delete-from-array.eps ├── depth-breadth.eps ├── eclipse-create-project.eps ├── eclipse-fx.eps ├── edit-list-demo.eps ├── estimate_pi_figure.eps ├── estimating-pi.eps ├── event-handling.eps ├── exception-hierarchy.eps ├── expression-tree.eps ├── for-loop-flow-control.eps ├── gomoku-board.eps ├── gradient-rect.eps ├── grid-layout.eps ├── growing-circles.eps ├── hash-table.eps ├── high-low-gui.eps ├── hub-and-client-threads.eps ├── hub-and-clients.eps ├── if-else-flow-control.eps ├── insert-in-list.eps ├── insertion-sort.eps ├── instance-of-PlayerData.eps ├── life-neighbors.eps ├── life-rules.eps ├── line-attributes.eps ├── linear-gradient.eps ├── linked-data-structures.eps ├── list-positions.eps ├── list-with-head.eps ├── looped-list.eps ├── mandelbrot.eps ├── mosaic-draw.eps ├── mosaic.eps ├── motion-demo.eps ├── moving-rects.eps ├── multiple-inheritance.eps ├── multiprocessing-demo-1.eps ├── multiway-if-flow-control.eps ├── null-layout-demo.eps ├── objects-in-heap.eps ├── overview-GUIDemo.eps ├── overview-fig1.eps ├── overview-fig2.eps ├── overview-fig3.eps ├── overview-fig4.eps ├── overview-fig5.eps ├── package-class-subroutine.eps ├── paint-demo.eps ├── panels-in-layout.eps ├── parallel-lines.eps ├── pixel-coordinates.eps ├── polygon.eps ├── producer-consumer.eps ├── queue.eps ├── radial-gradient.eps ├── random-circles.eps ├── randomCards.eps ├── randomStrings.eps ├── rates-of-growth.eps ├── roll-dice-gui.eps ├── scatter-plot.eps ├── scene-graph.eps ├── scratch-off.eps ├── shapedraw-screenshot.eps ├── silly-stamper.eps ├── simple-calc.eps ├── simple-paint.eps ├── simple-stamper-with-drag.eps ├── simple-stamper.eps ├── slider-and-button-demo.eps ├── slider-demo.eps ├── smudge-rect.eps ├── square-in-circle.eps ├── stack.eps ├── stat-calc-gui.eps ├── stroke-demo.eps ├── sub-killer.eps ├── subclass-superclass.eps ├── symmetric-matrix.eps ├── table-demo.eps ├── text-count.eps ├── threads-vs-subroutines.eps ├── towers-of-hanoi-gui.eps ├── transforms.eps ├── two-d-array.eps ├── two-dimensional-array.eps ├── various-shapes.eps ├── vehicle-hierarchy.eps └── while-and-if-flow-control.eps ├── javafx-src-setup.png ├── javanotes-epub.css ├── javanotes.css ├── javanotes9-cover-180x235.png ├── javanotes9-cover-518x675.jpg ├── javanotes9-epub.xml ├── javanotes9-tex.xml ├── javanotes9-xml-includes.txt ├── javanotes9.dtd ├── javanotes9.xml ├── make-jar-files.bat ├── make-jar-files.sh ├── news-for-web.html ├── news.html ├── preface.xml ├── publish.sh ├── source.xml ├── src-c1 └── GUIDemo.java ├── src-c10 ├── RiemannSumStreamExperiment.java ├── SimpleInterpreter.java ├── WordCount.java ├── WordListWithPriorityQueue.java └── WordListWithTreeSet.java ├── src-c11 ├── CLChatClient.java ├── CLChatServer.java ├── CopyFile.java ├── CopyFileAsResources.java ├── DateClient.java ├── DateServer.java ├── DirectoryList.java ├── FetchURL.java ├── PhoneDirectoryFileDemo.java ├── ReverseFileWithResources.java ├── ReverseFileWithScanner.java ├── ShowMyNetwork.java ├── SimplePaintWithFiles.java ├── SimplePaintWithXML.java ├── TextReader.java ├── TrivialEdit.java └── XMLDemo.java ├── src-c12 ├── BackgroundComputationDemo.java ├── CLMandelbrotMaster.java ├── CLMandelbrotTask.java ├── CLMandelbrotWorker.java ├── DateServerWithThreadPool.java ├── DateServerWithThreads.java ├── GUIChat.java ├── MultiprocessingDemo1.java ├── MultiprocessingDemo2.java ├── MultiprocessingDemo3.java ├── MultiprocessingDemo4.java ├── MyLinkedBlockingQueue.java ├── QuicksortThreadDemo.java ├── RandomArtWithThreads.java ├── ThreadTest1.java ├── ThreadTest2.java ├── ThreadTest3.java ├── ThreadTest4.java ├── TowersOfHanoiGUI.java └── netgame │ ├── chat │ ├── ChatRoomServer.java │ └── ChatRoomWindow.java │ ├── common │ ├── Client.java │ ├── DisconnectMessage.java │ ├── ForwardedMessage.java │ ├── Hub.java │ ├── ResetSignal.java │ └── StatusMessage.java │ ├── fivecarddraw │ ├── Main.java │ ├── PokerCard.java │ ├── PokerDeck.java │ ├── PokerGameState.java │ ├── PokerHub.java │ ├── PokerRank.java │ ├── PokerWindow.java │ └── cards.png │ └── tictactoe │ ├── Main.java │ ├── TicTacToeGameHub.java │ ├── TicTacToeGameState.java │ └── TicTacToeWindow.java ├── src-c13 ├── BoundPropertyDemo.java ├── BrowserWindow.java ├── CanvasResizeDemo.java ├── EditListDemo.java ├── PaintDemo.java ├── ScatterPlotTableDemo.java ├── SillyStamper.java ├── SimpleDialogs.java ├── SimpleTableDemo.java ├── StopWatchLabel.java ├── StrokeDemo.java ├── TestDialogs.java ├── TestStopWatch.java ├── ToolPaint.java ├── TransformDemo.java ├── WebBrowser.java ├── cards.png ├── edu │ └── hws │ │ └── eck │ │ └── mdbfx │ │ ├── I18n.java │ │ ├── Main.java │ │ ├── MandelbrotCanvas.java │ │ ├── MandelbrotPane.java │ │ ├── Menus.java │ │ ├── SetImageSizeDialog.java │ │ ├── SetLimitsDialog.java │ │ ├── examples │ │ ├── README.txt │ │ ├── settings1.mdb │ │ ├── settings10.mdb │ │ ├── settings11.mdb │ │ ├── settings12.mdb │ │ ├── settings2.mdb │ │ ├── settings3.mdb │ │ ├── settings4.mdb │ │ ├── settings5.mdb │ │ ├── settings6.mdb │ │ ├── settings7.mdb │ │ ├── settings8.mdb │ │ └── settings9.mdb │ │ └── strings.properties ├── face-smile.png ├── nature-images │ ├── .DS_Store │ ├── README.txt │ ├── bluejay.jpg │ ├── chipmunk.jpg │ ├── collie.jpg │ ├── elephants.jpg │ ├── faun.jpg │ ├── lion.jpg │ ├── polar-bear.jpg │ └── stork.jpg ├── stamper_icons │ ├── README.txt │ ├── icon10.png │ ├── icon11.png │ ├── icon24.png │ ├── icon25.png │ ├── icon26.png │ ├── icon31.png │ ├── icon33.png │ ├── icon34.png │ ├── icon5.png │ ├── icon7.png │ ├── icon8.png │ └── icon9.png └── tile.png ├── src-c2 ├── CreateProfile.java ├── Day.java ├── EnumDemo.java ├── HelloWorld.java ├── Interest.java ├── Interest2.java ├── Interest2WithScanner.java ├── Month.java ├── PrintSquare.java ├── SeparateEnumDemo.java ├── TextBlockDemo.java └── TimedComputation.java ├── src-c3 ├── AverageNumbersFromFile.java ├── BirthdayProblem.java ├── ComputeAverage.java ├── ComputeAverage2.java ├── CountDivisors.java ├── Interest3.java ├── LengthConverter.java ├── ListLetters.java ├── MovingRects.java ├── RandomCircles.java ├── ReverseInputNumbers.java ├── SimpleAnimationStarter.java ├── SimpleGraphicsStarter.java └── ThreeN1.java ├── src-c4 ├── ArrayProcessor.java ├── CopyTextFile.java ├── GuessingGame.java ├── GuessingGame2.java ├── Mosaic.java ├── MosaicCanvas.java ├── RandomMosaicWalk.java ├── RandomMosaicWalk2.java ├── RowsOfChars.java └── ThreeN2.java ├── src-c5 ├── BlackjackHand.java ├── Card.java ├── CircleInfo.java ├── Deck.java ├── GrowingCircleAnimation.java ├── Hand.java ├── HighLow.java ├── PairOfDice.java ├── RollTwoPairs.java ├── ShapeDraw.java └── StatCalc.java ├── src-c6 ├── HelloWorldFX.java ├── HighLowGUI.java ├── KeyboardEventDemo.java ├── MosaicDraw.java ├── OwnLayoutDemo.java ├── RandomCards.java ├── RandomStrings.java ├── SimpleCalc.java ├── SimpleColorChooser.java ├── SimplePaint.java ├── SimpleTrackMouse.java ├── SliderDemo.java ├── SubKiller.java ├── TextInputDemo.java └── cards.png ├── src-c7 ├── Checkers.java ├── Complex.java ├── DynamicArrayOfInt.java ├── FullName.java ├── Life.java ├── PhoneDirectory.java ├── PhoneDirectory2.java ├── RandomStringsWithArray.java ├── RecordDemo.java ├── ReverseWithArrayList.java ├── ReverseWithDynamicArray.java ├── SimplePaint2.java ├── SymmetricMatrix.java └── TestSymmetricMatrix.java ├── src-c8 ├── Expr.java ├── LengthConverter2.java ├── LengthConverter3.java └── TryStatementDemo.java ├── src-c9 ├── Blobs.java ├── DepthBreadth.java ├── ListDemo.java ├── LittlePentominos.java ├── Maze.java ├── PostfixEval.java ├── SimpleParser1.java ├── SimpleParser2.java ├── SimpleParser3.java ├── SortTreeDemo.java ├── StackOfDouble.java ├── StackOfInt.java ├── StringList.java └── TowersOfHanoi.java ├── src-textio ├── textio │ └── TextIO.java └── textiogui │ ├── System.java │ └── TextIO.java ├── texmacros.tex └── textio-for-windows-jar-files ├── README.txt ├── System.java └── TextIO.java /javanotes9-swing/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /javanotes9-swing/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /javanotes9-swing/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | javanotes9-swing 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /javanotes9-swing/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=17 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=17 15 | -------------------------------------------------------------------------------- /javanotes9-swing/c1-overview/overview-GUIDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c1-overview/overview-GUIDemo.png -------------------------------------------------------------------------------- /javanotes9-swing/c1-overview/overview-fig5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c1-overview/overview-fig5.png -------------------------------------------------------------------------------- /javanotes9-swing/c11-IO/CheckersWithFiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c11-IO/CheckersWithFiles.png -------------------------------------------------------------------------------- /javanotes9-swing/c12-threads/estimating-pi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c12-threads/estimating-pi.png -------------------------------------------------------------------------------- /javanotes9-swing/c12-threads/multiprocessing-demo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c12-threads/multiprocessing-demo-1.png -------------------------------------------------------------------------------- /javanotes9-swing/c12-threads/towers-of-hanoi-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c12-threads/towers-of-hanoi-gui.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/button-with-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/button-with-icon.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/cards.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/high-low-with-images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/high-low-with-images.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

It's possible to program a wide variety of GUI 6 | applications using only the techniques covered in . In many 7 | cases, the basic events, components, layouts, and graphics routines covered in 8 | that chapter suffice. But the Swing graphical user interface library is far 9 | richer than what we have seen so far, and it can be used to build highly 10 | sophisticated applications. This chapter is a further introduction to Swing 11 | and other aspects of GUI programming. 12 | Although the title of the chapter is "Advanced GUI Programming," it is still 13 | just an introduction. Full coverage of this topic would require at least another 14 | complete book.

15 | 16 |
-------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/java-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/java-button.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/mandelbrot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/mandelbrot.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/measuring-strings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/measuring-strings.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/paint-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/paint-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/scatter-plot-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/scatter-plot-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/silly-stamper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/silly-stamper.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/smudgedRectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/smudgedRectangle.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/stroke-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/stroke-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c13-GUI2/toolbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c13-GUI2/toolbar.png -------------------------------------------------------------------------------- /javanotes9-swing/c2-basics/eclipse-create-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c2-basics/eclipse-create-project.png -------------------------------------------------------------------------------- /javanotes9-swing/c3-control/random-circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c3-control/random-circles.png -------------------------------------------------------------------------------- /javanotes9-swing/c4-subroutines/mosaic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c4-subroutines/mosaic.png -------------------------------------------------------------------------------- /javanotes9-swing/c5-OOP/shapedraw-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c5-OOP/shapedraw-screenshot.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/blackjack-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/blackjack-gui.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/border-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/border-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/border-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/border-layout.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/clickable-checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/clickable-checkerboard.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/crisscross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/crisscross.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/event-handling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/event-handling.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/flow-layout-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/flow-layout-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/grid-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/grid-layout.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/high-low-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/high-low-gui.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Computer users today expect to interact 6 | with their computers using a graphical user interface (GUI). Java can 7 | be used to write sophisticated GUI programs.

8 | 9 |

GUI programs 10 | differ from traditional "straight-through" programs that you have 11 | encountered in the first few chapters of this book. One big difference is 12 | that GUI programs are event-driven. That is, user actions such as 13 | clicking on a button or pressing a key on the keyboard generate events, and the 14 | program must respond to these events as they occur.

15 | 16 |

Event-driven programming builds on all the skills you have learned in the 17 | first five chapters of this text. You need to be able to write the methods 18 | that respond to events. Inside those methods, you are doing the kind of 19 | programming-in-the-small that was covered in 20 | and . 21 | And of course, objects are everywhere in GUI programming. 22 | Events are objects. Colors and fonts are objects. GUI components such as buttons and 23 | menus are objects. Events are handled by instance methods contained in objects. 24 | In Java, GUI programming is object-oriented programming.

25 | 26 |

This chapter covers the basics of GUI programming. 27 | The discussion will continue in 28 | with more details and with more advanced 29 | techniques.

30 | 31 |

This edition of this textbook covers GUI programming using the Swing GUI toolkit, 32 | which is a standard part of Java and has been included in the JDK since Java 2. 33 | An alternative edition covers JavaFX instead of Swing. That edition can be found 34 | at https://math.hws.edu/javanotes9. 35 | The only really significant differences between the two editions are in this 36 | chapter and in .

37 | 38 |
-------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/mosaic-draw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/mosaic-draw.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/null-layout-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/null-layout-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/panels-in-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/panels-in-layout.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/pixel-coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/pixel-coordinates.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/polygon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/polygon.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/roll-dice-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/roll-dice-gui.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/s2.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/simple-calc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/simple-calc.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/simple-paint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/simple-paint.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/simple-stamper-with-drag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/simple-stamper-with-drag.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/simple-stamper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/simple-stamper.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/slider-and-button-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/slider-and-button-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/slider-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/slider-demo.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/square-in-circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/square-in-circle.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/stat-calc-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/stat-calc-gui.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/sub-killer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/sub-killer.png -------------------------------------------------------------------------------- /javanotes9-swing/c6-GUI1/text-count.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c6-GUI1/text-count.png -------------------------------------------------------------------------------- /javanotes9-swing/c7-arrays/checkers-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c7-arrays/checkers-game.png -------------------------------------------------------------------------------- /javanotes9-swing/c7-arrays/gomoku-board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c7-arrays/gomoku-board.png -------------------------------------------------------------------------------- /javanotes9-swing/c8-robustness/SimpleGrapher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c8-robustness/SimpleGrapher.png -------------------------------------------------------------------------------- /javanotes9-swing/c9-recursion/blobs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c9-recursion/blobs.png -------------------------------------------------------------------------------- /javanotes9-swing/c9-recursion/depth-breadth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/c9-recursion/depth-breadth.png -------------------------------------------------------------------------------- /javanotes9-swing/convert-check-sourcerefs.xsl: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | source/ 24 | source/chapter/ 25 | 26 | 27 | 28 | Cannot find . 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 | -------------------------------------------------------------------------------- /javanotes9-swing/convert-exercise-progs.xsl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | exercise-programs/chapter/.java 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /javanotes9-swing/javanotes9-cover-180x235.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/javanotes9-cover-180x235.png -------------------------------------------------------------------------------- /javanotes9-swing/javanotes9-cover-518x675.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/javanotes9-cover-518x675.jpg -------------------------------------------------------------------------------- /javanotes9-swing/src-c12/netgame/chat/ChatRoomServer.java: -------------------------------------------------------------------------------- 1 | package netgame.chat; 2 | 3 | import java.io.IOException; 4 | import netgame.common.Hub; 5 | 6 | /** 7 | * This class contains just a small main class that creates a Hub 8 | * and starts it listening on port 37829. This port is used 9 | * by the ChatRoomWindow application. This program should be run 10 | * on the computer that "hosts" the chat room. See the ChatRoomWindow 11 | * class for more details. Once the server starts listening, it 12 | * will listen for connection requests from clients until the 13 | * ChatRoomServer program is terminated (for example by a 14 | * Control-C). 15 | *

Note that the ChatRoom application uses a basic, generic 16 | * Hub, which simply forwards any message that it received from 17 | * a client to all connected clients (including the one that 18 | * sent it), wrapped in an object of type ForwardedMessage. 19 | */ 20 | public class ChatRoomServer { 21 | 22 | private final static int PORT = 37829; 23 | 24 | public static void main(String[] args) { 25 | try { 26 | new Hub(PORT); 27 | } 28 | catch (IOException e) { 29 | System.out.println("Can't create listening socket. Shutting down."); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c12/netgame/common/DisconnectMessage.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * A DisconnectMesaage is sent from a Client to the Hub when that 7 | * client wants to disconnect. A DisconnectMessage is also sent from 8 | * the Hub to each client just before it shuts down normally. DisconnectMessages 9 | * are for internal use in the netgame.common package and are not used 10 | * directly by users of the package. 11 | */ 12 | final class DisconnectMessage implements Serializable { 13 | 14 | /** 15 | * The message associated with the disconnect. When the Hub 16 | * sends disconnects because it is shutting down, the message 17 | * is "*shutdown*". 18 | */ 19 | final public String message; 20 | 21 | /** 22 | * Creates a DisconnectMessage containing a given String, which 23 | * is meant to describe the reason for the disconnection. 24 | */ 25 | public DisconnectMessage(String message) { 26 | this.message = message; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c12/netgame/common/ForwardedMessage.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Represents a message that was received by the Hub from 7 | * one clients and that is being forwarded to all clients. 8 | * A ForwardedMessage includes the message that was sent 9 | * by a client to the Hub and the ID number of the client 10 | * who sent it. The default action of a Hub -- defined 11 | * in the messageReceived(playerID,message) method of 12 | * that class -- is to wrap the message in a ForwardedMessage 13 | * and send the ForwardedMessage to all connected client, 14 | * including the client who sent the original message. 15 | * When an application uses a subclass of Hub, it is 16 | * likely to override that behavior. 17 | */ 18 | public class ForwardedMessage implements Serializable { 19 | 20 | public final Object message; // Original message from a client. 21 | public final int senderID; // The ID of the client who sent that message. 22 | 23 | /** 24 | * Create a ForwadedMessage to wrap a message sent by a client. 25 | * @param senderID the ID number of the original sender. 26 | * @param message the original message. 27 | */ 28 | public ForwardedMessage(int senderID, Object message) { 29 | this.senderID = senderID; 30 | this.message = message; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c12/netgame/common/ResetSignal.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | /** 4 | * This package private class is used internally in Hub and Client 5 | * to send a signal to the message output thread that the output 6 | * stream should be reset. A ResetSignal has no data. 7 | */ 8 | class ResetSignal { 9 | } 10 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c12/netgame/common/StatusMessage.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * The Hub sends a StatusMessage to all connected clients when 7 | * a player connects or disconnects. When a player connects, 8 | * that player receives the status message caused by their 9 | * connecting. When a player disconnects, that player does 10 | * not receive a copy of the status message that is sent. 11 | * StatusMessages are from internal use in the netgame.common 12 | * package and users of this package do not have to deal with 13 | * them. This package private class is only used internally 14 | * in the netgame.common package. Users of the package will 15 | * not see these messages; instead, the Client's playerConnected() 16 | * or playerDisconnected() method will be called. 17 | */ 18 | final class StatusMessage implements Serializable { 19 | 20 | /** 21 | * The ID number of the player who has connected or disconnected. 22 | */ 23 | public final int playerID; 24 | 25 | /** 26 | * True if the player has just connected; false if the player 27 | * has just disconnected. 28 | */ 29 | public final boolean connecting; 30 | 31 | /** 32 | * The list of players after the change has been made. 33 | */ 34 | public final int[] players; 35 | 36 | public StatusMessage(int playerID, boolean connecting, int[] players) { 37 | this.playerID = playerID; 38 | this.connecting = connecting; 39 | this.players = players; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c12/netgame/fivecarddraw/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c12/netgame/fivecarddraw/cards.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/QueenOfHearts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/QueenOfHearts.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/StopWatchLabel.java: -------------------------------------------------------------------------------- 1 | import java.awt.event.*; 2 | import javax.swing.*; 3 | 4 | /** 5 | * A custom component that acts as a simple stop-watch. When the user clicks 6 | * on it, this component starts timing. When the user clicks again, 7 | * it displays the time between the two clicks. Clicking a third time 8 | * starts another timer, etc. While it is timing, the label just 9 | * displays the message "Timing....". 10 | */ 11 | public class StopWatchLabel extends JLabel implements MouseListener { 12 | 13 | private long startTime; // Start time of timer. 14 | // (Time is measured in milliseconds.) 15 | 16 | private boolean running; // True when the timer is running. 17 | 18 | /** 19 | * Constructor sets initial text on the label to 20 | * "Click to start timer." and sets up a mouse listener 21 | * so the label can respond to clicks. 22 | */ 23 | public StopWatchLabel() { 24 | super(" Click to start timer. ", JLabel.CENTER); 25 | addMouseListener(this); 26 | } 27 | 28 | 29 | /** 30 | * Tells whether the timer is currently running. 31 | */ 32 | public boolean isRunning() { 33 | return running; 34 | } 35 | 36 | 37 | /** 38 | * React when the user presses the mouse by starting 39 | * or stopping the timer and changing the text that 40 | * is shown on the label. 41 | */ 42 | public void mousePressed(MouseEvent evt) { 43 | if (running == false) { 44 | // Record the time and start the timer. 45 | running = true; 46 | startTime = evt.getWhen(); // Time when mouse was clicked. 47 | setText("Timing...."); 48 | } 49 | else { 50 | // Stop the timer. Compute the elapsed time since the 51 | // timer was started and display it. 52 | running = false; 53 | long endTime = evt.getWhen(); 54 | double seconds = (endTime - startTime) / 1000.0; 55 | setText("Time: " + seconds + " sec."); 56 | } 57 | } 58 | 59 | public void mouseReleased(MouseEvent evt) { } 60 | public void mouseClicked(MouseEvent evt) { } 61 | public void mouseEntered(MouseEvent evt) { } 62 | public void mouseExited(MouseEvent evt) { } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/TinySmiley.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/TinySmiley.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/cards.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/README.txt: -------------------------------------------------------------------------------- 1 | 2 | The files in this "examples" directory are used in the applet 3 | version of the Mandelbrot Viewer program , which is defined in 4 | the file MandelbrotApplet.java. They are NOT needed by any 5 | other part of the program. 6 | 7 | Note that these are "Params" files that can also be loaded by 8 | hand into the stand-alone application version of the program 9 | using its Open Params command. 10 | 11 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings1.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings10.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings11.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings12.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings2.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings3.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings4.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings5.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings6.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings7.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings8.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/edu/hws/eck/mdb/examples/settings9.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/face-smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/face-smile.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/README.txt: -------------------------------------------------------------------------------- 1 | The icons in this folder are for the sample program 2 | SillyStamper.java. They were taken from the KDE desktop 3 | icon collection. 4 | 5 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon10.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon11.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon24.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon25.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon26.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon31.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon33.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon34.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon5.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon7.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon8.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c13/stamper_icons/icon9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9-swing/src-c13/stamper_icons/icon9.png -------------------------------------------------------------------------------- /javanotes9-swing/src-c5/CircleInfo.java: -------------------------------------------------------------------------------- 1 | import java.awt.Color; 2 | import java.awt.Graphics; 3 | 4 | /** 5 | * A simple class that holds the size, color, and location of a colored disk, 6 | * with a method for drawing the circle in a graphics context. The circle 7 | * is drawn as a filled oval, with a black outline. 8 | */ 9 | public class CircleInfo { 10 | 11 | public int radius; // The radius of the circle. 12 | public int x,y; // The location of the center of the circle. 13 | public Color color; // The color of the circle. 14 | 15 | /** 16 | * Create a CircleInfo with a given location and radius and with a 17 | * randomly selected, semi-transparent color. 18 | * @param centerX The x coordinate of the center. 19 | * @param centerY The y coordinate of the center. 20 | * @param rad The radius of the circle. 21 | */ 22 | public CircleInfo( int centerX, int centerY, int rad ) { 23 | x = centerX; 24 | y = centerY; 25 | radius = rad; 26 | int red = (int)(256*Math.random()); 27 | int green = (int)(256*Math.random()); 28 | int blue = (int)(256*Math.random()); 29 | color = new Color(red,green,blue,100); 30 | } 31 | 32 | /** 33 | * Draw the disk in graphics context g, with a black outline. 34 | */ 35 | public void draw( Graphics g ) { 36 | g.setColor( color ); 37 | g.fillOval( x - radius, y - radius, 2*radius, 2*radius ); 38 | g.setColor( Color.BLACK ); 39 | g.drawOval( x - radius, y - radius, 2*radius, 2*radius ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/BorderDemo.java: -------------------------------------------------------------------------------- 1 | 2 | import java.awt.*; 3 | import javax.swing.*; 4 | import javax.swing.border.Border; 5 | 6 | /** 7 | * A simple program that shows six different types of border. The 8 | * borders are used on labels which are contained in a panel that 9 | * itself uses an EmptyBorder. 10 | */ 11 | public class BorderDemo extends JPanel { 12 | 13 | /** 14 | * A main routine allows this class to be run as an application. 15 | */ 16 | public static void main(String[] args) { 17 | JFrame window = new JFrame("Slider Demo"); 18 | BorderDemo content = new BorderDemo(); 19 | window.setContentPane(content); 20 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 21 | window.setLocation(120,70); 22 | window.pack(); 23 | window.setVisible(true); 24 | } 25 | 26 | //--------------------------------------------------------------------- 27 | 28 | 29 | public BorderDemo() { 30 | setBackground(Color.LIGHT_GRAY); 31 | setLayout( new GridLayout(0,1,10,10) ); 32 | setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 33 | make(BorderFactory.createLineBorder(Color.RED,2), 34 | " BorderFactory.createLineBorder(Color.RED,2) "); 35 | make(BorderFactory.createMatteBorder(2,2,5,5,Color.RED), 36 | " BorderFactory.createMatteBorder(2,2,5,5,Color.RED) "); 37 | make(BorderFactory.createEtchedBorder(), 38 | " BorderFactory.createEtchedBorder() "); 39 | make(BorderFactory.createRaisedBevelBorder(), 40 | " BorderFactory.createRaisedBevelBorder() "); 41 | make(BorderFactory.createLoweredBevelBorder(), 42 | " BorderFactory.createLoweredBevelBorder() "); 43 | make(BorderFactory.createTitledBorder("Title Goes Here"), 44 | " BorderFactory.createTitledBorder(\"Title Goes Here\") "); 45 | } 46 | 47 | /** 48 | * Make a label showing the string and with the specified border. 49 | * The label will be opaque and will have a light gray background. 50 | * The label is added to the content pane. 51 | */ 52 | void make(Border border, String command) { 53 | JLabel label = new JLabel(command, JLabel.CENTER); 54 | label.setBorder(border); 55 | add(label); 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/ClickableRandomStrings.java: -------------------------------------------------------------------------------- 1 | import java.awt.Component; 2 | import java.awt.event.MouseEvent; 3 | import java.awt.event.MouseListener; 4 | import javax.swing.JFrame; 5 | 6 | /** 7 | * Displays a window that shows 25 copies of the string "Java!" in 8 | * random colors, fonts, and positions. The content of the window 9 | * is an object of type RandomStringsPanel. When the user clicks 10 | * the window, the content of the window is repainted, with the 11 | * strings in newly selected random colors, fonts, and positions. 12 | */ 13 | public class ClickableRandomStrings { 14 | 15 | public static void main(String[] args) { 16 | JFrame window = new JFrame("Click Me to Redraw"); 17 | RandomStringsPanel content = new RandomStringsPanel(); 18 | content.addMouseListener( new RepaintOnClick() ); 19 | window.setContentPane(content); 20 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 21 | window.setLocation(120,70); 22 | window.setSize(350,250); 23 | window.setVisible(true); 24 | } 25 | 26 | private static class RepaintOnClick implements MouseListener { 27 | 28 | public void mousePressed(MouseEvent evt) { 29 | Component source = (Component)evt.getSource(); 30 | source.repaint(); 31 | } 32 | 33 | public void mouseClicked(MouseEvent evt) { } 34 | public void mouseReleased(MouseEvent evt) { } 35 | public void mouseEntered(MouseEvent evt) { } 36 | public void mouseExited(MouseEvent evt) { } 37 | 38 | } 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/HelloWorldGUI1.java: -------------------------------------------------------------------------------- 1 | import javax.swing.JOptionPane; 2 | 3 | /** 4 | * Puts up a dialog box that says "Hello World." The program 5 | * ends when the user closes the dialog box. This is, perhaps, 6 | * the simplest possible GUI program. 7 | */ 8 | public class HelloWorldGUI1 { 9 | 10 | public static void main(String[] args) { 11 | JOptionPane.showMessageDialog( null, "Hello World!" ); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/HelloWorldGUI2.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.awt.event.*; 3 | import javax.swing.*; 4 | 5 | /** 6 | * Create and show a window that displays the message "Hello World", 7 | * with an "OK" button. The program ends when the user clicks the button. 8 | * The GUI is constructed in the main() routine, which is not the best 9 | * way to do things. This program is a first example of using GUI components. 10 | */ 11 | public class HelloWorldGUI2 { 12 | 13 | private static class HelloWorldDisplay extends JPanel { 14 | public void paintComponent(Graphics g) { 15 | super.paintComponent(g); 16 | g.drawString( "Hello World!", 20, 30 ); 17 | } 18 | } 19 | 20 | private static class ButtonHandler implements ActionListener { 21 | public void actionPerformed(ActionEvent e) { 22 | System.exit(0); 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | 28 | HelloWorldDisplay displayPanel = new HelloWorldDisplay(); 29 | JButton okButton = new JButton("OK"); 30 | ButtonHandler listener = new ButtonHandler(); 31 | okButton.addActionListener(listener); 32 | 33 | JPanel content = new JPanel(); 34 | content.setLayout(new BorderLayout()); 35 | content.add(displayPanel, BorderLayout.CENTER); 36 | content.add(okButton, BorderLayout.SOUTH); 37 | 38 | JFrame window = new JFrame("GUI Test"); 39 | window.setContentPane(content); 40 | window.setSize(250,100); 41 | window.setLocation(100,100); 42 | window.setVisible(true); 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/HelloWorldGUI3.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import javax.swing.*; 3 | 4 | /** 5 | * Create and show a window that displays the message "Hello World", 6 | * with an "OK" button. The program ends when the user clicks the button. 7 | * The GUI is constructed in the main() routine, which is not the best 8 | * way to do things. This program is a first example of using GUI components. 9 | */ 10 | public class HelloWorldGUI3 { 11 | 12 | private static class HelloWorldDisplay extends JPanel { 13 | public void paintComponent(Graphics g) { 14 | super.paintComponent(g); 15 | g.drawString( "Hello World!", 20, 30 ); 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | 21 | HelloWorldDisplay displayPanel = new HelloWorldDisplay(); 22 | JButton okButton = new JButton("OK"); 23 | okButton.addActionListener( e -> System.exit(0) ); 24 | 25 | JPanel content = new JPanel(); 26 | content.setLayout(new BorderLayout()); 27 | content.add(displayPanel, BorderLayout.CENTER); 28 | content.add(okButton, BorderLayout.SOUTH); 29 | 30 | JFrame window = new JFrame("GUI Test"); 31 | window.setContentPane(content); 32 | window.setSize(250,100); 33 | window.setLocation(100,100); 34 | window.setVisible(true); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/MosaicDraw.java: -------------------------------------------------------------------------------- 1 | import java.awt.Dimension; 2 | import java.awt.Toolkit; 3 | 4 | import javax.swing.JFrame; 5 | 6 | /** 7 | * A MosaicDraw is a JFrame that shows a MosaicCanvas as its content pane. The mosaic 8 | * is made up of rows and columns of squares. The user can click-and-drag 9 | * the mouse to color the squares. A menu bar with some options is shown 10 | * at the top of the window. The window will be centered on the screen, 11 | * but will not be visible initially. 12 | * 13 | * This class also contains a main program, so that it can be run as a 14 | * stand-alone application. The main program creates a MosaicDrawFrame and 15 | * makes it visible on the screen. It also sets the program to end when 16 | * the user closes the window. 17 | * 18 | * Note that this class depends on MosaicCanvas.java and MosaicDrawController.java. 19 | */ 20 | public class MosaicDraw extends JFrame { 21 | 22 | public static void main(String[] args) { 23 | JFrame window = new MosaicDraw(); 24 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 25 | window.setVisible(true); 26 | } 27 | 28 | public MosaicDraw() { 29 | super("Mosaic Draw"); 30 | MosaicDrawController controller = new MosaicDrawController(); 31 | setContentPane(controller.getMosaicCanvas()); 32 | setJMenuBar(controller.getMenuBar()); 33 | pack(); 34 | Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); 35 | setLocation( (screensize.width - getWidth())/2, (screensize.height - getHeight())/2); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/RandomStrings.java: -------------------------------------------------------------------------------- 1 | 2 | import javax.swing.JFrame; 3 | 4 | /** 5 | * A program that shows a RandomStringsPanel as its content pane. 6 | */ 7 | public class RandomStrings { 8 | 9 | public static void main(String[] args) { 10 | JFrame window = new JFrame("Java!"); 11 | RandomStringsPanel content = new RandomStringsPanel(); 12 | window.setContentPane(content); 13 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 14 | window.setLocation(120,70); 15 | window.setSize(350,250); 16 | window.setVisible(true); 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/SliderDemo.java: -------------------------------------------------------------------------------- 1 | 2 | // A little program that demonstrates JSliders. 3 | 4 | import java.awt.*; 5 | 6 | import javax.swing.*; 7 | import javax.swing.event.*; 8 | 9 | public class SliderDemo extends JPanel implements ChangeListener { 10 | 11 | /** 12 | * A main routine allows this class to be run as an application. 13 | */ 14 | public static void main(String[] args) { 15 | JFrame window = new JFrame("Slider Demo"); 16 | SliderDemo content = new SliderDemo(); 17 | window.setContentPane(content); 18 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 19 | window.setLocation(120,70); 20 | window.setSize(350,200); 21 | window.setVisible(true); 22 | } 23 | 24 | //--------------------------------------------------------------------- 25 | 26 | JSlider slider1, slider2, slider3; // The sliders. 27 | 28 | JLabel label; // A label for reporting changes in the sliders' values. 29 | 30 | public SliderDemo() { 31 | 32 | setLayout(new GridLayout(4,1)); 33 | setBorder(BorderFactory.createCompoundBorder( 34 | BorderFactory.createLineBorder(Color.DARK_GRAY, 2), 35 | BorderFactory.createEmptyBorder(8,8,8,8))); 36 | 37 | label = new JLabel("Try dragging the sliders!", JLabel.CENTER); 38 | add(label); 39 | 40 | slider1 = new JSlider(0,10,0); 41 | slider1.addChangeListener(this); 42 | add(slider1); 43 | 44 | slider2 = new JSlider(); 45 | slider2.addChangeListener(this); 46 | slider2.setMajorTickSpacing(25); 47 | slider2.setMinorTickSpacing(5); 48 | slider2.setPaintTicks(true); 49 | add(slider2); 50 | 51 | slider3 = new JSlider(2000,2100,2014); 52 | slider3.addChangeListener(this); 53 | slider3.setLabelTable(slider3.createStandardLabels(50)); 54 | slider3.setPaintLabels(true); 55 | add(slider3); 56 | 57 | } // end constructor 58 | 59 | public void stateChanged(ChangeEvent evt) { 60 | if (evt.getSource() == slider1) 61 | label.setText("Slider one changed to " + slider1.getValue()); 62 | else if (evt.getSource() == slider2) 63 | label.setText("Slider two changed to " + slider2.getValue()); 64 | else if (evt.getSource() == slider3) 65 | label.setText("Slider three changed to " + slider3.getValue()); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/SliderDemoWithLambda.java: -------------------------------------------------------------------------------- 1 | 2 | // A little program that demonstrates JSliders. This is an alternative 3 | // version of SliderDemo.java that uses lambda expressions to define 4 | // the ChangeListeners are registered with the sliders. 5 | 6 | import java.awt.*; 7 | import javax.swing.*; 8 | 9 | public class SliderDemoWithLambda extends JPanel { 10 | 11 | /** 12 | * A main routine allows this class to be run as an application. 13 | */ 14 | public static void main(String[] args) { 15 | JFrame window = new JFrame("Slider Demo"); 16 | SliderDemoWithLambda content = new SliderDemoWithLambda(); 17 | window.setContentPane(content); 18 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 19 | window.setLocation(120,70); 20 | window.setSize(350,200); 21 | window.setVisible(true); 22 | } 23 | 24 | //--------------------------------------------------------------------- 25 | 26 | JSlider slider1, slider2, slider3; // The sliders. 27 | 28 | JLabel label; // A label for reporting changes in the sliders' values. 29 | 30 | public SliderDemoWithLambda() { 31 | 32 | setLayout(new GridLayout(4,1)); 33 | setBorder(BorderFactory.createCompoundBorder( 34 | BorderFactory.createLineBorder(Color.DARK_GRAY, 2), 35 | BorderFactory.createEmptyBorder(8,8,8,8))); 36 | 37 | label = new JLabel("Try dragging the sliders!", JLabel.CENTER); 38 | add(label); 39 | 40 | slider1 = new JSlider(0,10,0); 41 | slider1.addChangeListener( 42 | evt -> label.setText("Slider one changed to " + slider1.getValue()) ); 43 | add(slider1); 44 | 45 | slider2 = new JSlider(); 46 | slider2.addChangeListener( 47 | evt -> label.setText("Slider two changed to " + slider2.getValue()) ); 48 | slider2.setMajorTickSpacing(25); 49 | slider2.setMinorTickSpacing(5); 50 | slider2.setPaintTicks(true); 51 | add(slider2); 52 | 53 | slider3 = new JSlider(2000,2100,2014); 54 | slider3.addChangeListener( 55 | evt -> label.setText("Slider three changed to " + slider3.getValue()) ); 56 | slider3.setLabelTable(slider3.createStandardLabels(50)); 57 | slider3.setPaintLabels(true); 58 | add(slider3); 59 | 60 | } // end constructor 61 | 62 | } 63 | -------------------------------------------------------------------------------- /javanotes9-swing/src-c6/TextAreaDemo.java: -------------------------------------------------------------------------------- 1 | import java.awt.BorderLayout; 2 | import java.awt.Color; 3 | import java.awt.Font; 4 | import java.awt.Insets; 5 | 6 | import javax.swing.BorderFactory; 7 | import javax.swing.JFrame; 8 | import javax.swing.JPanel; 9 | import javax.swing.JScrollPane; 10 | import javax.swing.JTextArea; 11 | 12 | /** 13 | * This program simply demonstrates using a JTextArea in a JScrollPane. 14 | */ 15 | public class TextAreaDemo extends JPanel { 16 | 17 | 18 | /** 19 | * A main routine allows this class to be run as an application. 20 | */ 21 | public static void main(String[] args) { 22 | JFrame window = new JFrame("TextArea Demo"); 23 | TextAreaDemo content = new TextAreaDemo(); 24 | window.setContentPane(content); 25 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 26 | window.setLocation(120,70); 27 | window.setSize(400,250); 28 | window.setVisible(true); 29 | } 30 | 31 | //--------------------------------------------------------------------- 32 | 33 | public TextAreaDemo() { 34 | 35 | String text = "So, naturalists observe, a flea\n" 36 | + "Has smaller fleas that on him prey;\n" 37 | + "And these have smaller still to bite 'em;\n" 38 | + "And so proceed ad infinitum.\n\n" 39 | + " --Jonathan Swift"; 40 | 41 | JTextArea textArea = new JTextArea(); 42 | JScrollPane scrollPane = new JScrollPane(textArea); 43 | 44 | textArea.setText(text); 45 | textArea.setFont( new Font("Serif", Font.PLAIN, 24 )); 46 | textArea.setMargin( new Insets(7,7,7,7) ); 47 | 48 | setLayout(new BorderLayout()); 49 | setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); 50 | add(scrollPane, BorderLayout.CENTER); 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /javanotes9-swing/src-extra/BlackjackHand.java: -------------------------------------------------------------------------------- 1 | public class BlackjackHand extends Hand { 2 | 3 | /** 4 | * Computes and returns the value of this hand in the game 5 | * of Blackjack. 6 | */ 7 | public int getBlackjackValue() { 8 | 9 | int val; // The value computed for the hand. 10 | boolean ace; // This will be set to true if the 11 | // hand contains an ace. 12 | int cards; // Number of cards in the hand. 13 | 14 | val = 0; 15 | ace = false; 16 | cards = getCardCount(); // (method defined in class Hand.) 17 | 18 | for ( int i = 0; i < cards; i++ ) { 19 | // Add the value of the i-th card in the hand. 20 | Card card; // The i-th card; 21 | int cardVal; // The blackjack value of the i-th card. 22 | card = getCard(i); 23 | cardVal = card.getValue(); // The normal value, 1 to 13. 24 | if (cardVal > 10) { 25 | cardVal = 10; // For a Jack, Queen, or King. 26 | } 27 | if (cardVal == 1) { 28 | ace = true; // There is at least one ace. 29 | } 30 | val = val + cardVal; 31 | } 32 | 33 | // Now, val is the value of the hand, counting any ace as 1. 34 | // If there is an ace, and if changing its value from 1 to 35 | // 11 would leave the score less than or equal to 21, 36 | // then do so by adding the extra 10 points to val. 37 | 38 | if ( ace == true && val + 10 <= 21 ) 39 | val = val + 10; 40 | 41 | return val; 42 | 43 | } // end getBlackjackValue() 44 | 45 | } // end class BlackjackHand 46 | -------------------------------------------------------------------------------- /javanotes9/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /javanotes9/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /javanotes9/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | javanotes9 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /javanotes9/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=17 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 13 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 14 | org.eclipse.jdt.core.compiler.release=disabled 15 | org.eclipse.jdt.core.compiler.source=17 16 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 |
26 |

Deprecated API

27 |

Contents

28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/package-list: -------------------------------------------------------------------------------- 1 | textio 2 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/textio/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | textio 7 | 8 | 9 | 10 | 11 | 12 |

textio

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javanotes9/TextIO_Javadoc/textio/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | textio 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 |
26 |

Package textio

27 |
28 |
29 | 48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /javanotes9/c1-overview/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

When you begin a journey, it's a good idea to have 6 | a mental map of the terrain you'll be passing through. The same is true for an 7 | intellectual journey, such as learning to write computer programs. In this 8 | case, you'll need to know the basics of what computers are and how they work. 9 | You'll want to have some idea of what a computer program is and how one is 10 | created. Since you will be writing programs in the Java programming language, 11 | you'll want to know something about that language in particular and about the 12 | modern computing environment for which Java is designed.

13 |

As you read this chapter, don't worry if you can't understand everything in 14 | detail. (In fact, it would be impossible for you to learn all the details from 15 | the brief expositions in this chapter.) Concentrate on learning enough about 16 | the big ideas to orient yourself, in preparation for the rest of the book. 17 | Most of what is covered in this chapter will be covered in much greater detail 18 | later in the book.

19 |
20 | -------------------------------------------------------------------------------- /javanotes9/c1-overview/overview-GUIDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c1-overview/overview-GUIDemo.png -------------------------------------------------------------------------------- /javanotes9/c1-overview/overview-fig1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c1-overview/overview-fig1.png -------------------------------------------------------------------------------- /javanotes9/c1-overview/overview-fig2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c1-overview/overview-fig2.png -------------------------------------------------------------------------------- /javanotes9/c1-overview/overview-fig3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c1-overview/overview-fig3.png -------------------------------------------------------------------------------- /javanotes9/c1-overview/overview-fig4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c1-overview/overview-fig4.png -------------------------------------------------------------------------------- /javanotes9/c1-overview/overview-fig5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c1-overview/overview-fig5.png -------------------------------------------------------------------------------- /javanotes9/c10-generics/hash-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c10-generics/hash-table.png -------------------------------------------------------------------------------- /javanotes9/c10-generics/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

How to avoid reinventing the wheel? Many data 6 | structures and algorithms, such as those from , have been 7 | studied, programmed, and re-programmed by generations of computer science 8 | students. This is a valuable learning experience. Unfortunately, they have also 9 | been programmed and re-programmed by generations of working computer 10 | professionals, taking up time that could be devoted to new, more creative work. 11 | A programmer who needs a list or a binary tree shouldn't have to re-code these 12 | data structures from scratch. They are well-understood and have been programmed 13 | thousands of times before. The problem is how to make pre-written, robust data 14 | structures available to programmers. In this chapter, we'll look at Java's 15 | attempt to address this problem.

16 |

You have already seen part of the solution in . 17 | That section introduced parameterized types and the ArrayList 18 | class. Parameterized types make it possible for the same class to work with 19 | many different kinds of data. This idea—that the same code can be used 20 | for a variety of data types—is called generic programming.

21 |
-------------------------------------------------------------------------------- /javanotes9/c10-generics/list-positions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c10-generics/list-positions.png -------------------------------------------------------------------------------- /javanotes9/c11-IO/CheckersWithFiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c11-IO/CheckersWithFiles.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/estimate_pi_figure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/estimate_pi_figure.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/estimating-pi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/estimating-pi.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/hub-and-client-threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/hub-and-client-threads.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/hub-and-clients.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/hub-and-clients.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/multiprocessing-demo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/multiprocessing-demo-1.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/producer-consumer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/producer-consumer.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/threads-vs-subroutines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/threads-vs-subroutines.png -------------------------------------------------------------------------------- /javanotes9/c12-threads/towers-of-hanoi-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c12-threads/towers-of-hanoi-gui.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/alerts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/alerts.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/bound-property-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/bound-property-demo.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/edit-list-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/edit-list-demo.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/gradient-rect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/gradient-rect.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

It's possible to program a wide variety of GUI 6 | applications using only the techniques covered in . In many 7 | cases, the basic events, components, layouts, and graphics routines covered in 8 | that chapter suffice. But the JavaFX graphical user interface library is far 9 | richer than what we have seen so far, and it can be used to build highly 10 | sophisticated applications. This chapter continues the study of JavaFX, 11 | but still does not cover it fully. Some advanced topics, such as support 12 | for video and three-dimensional graphics, are not even mentioned. 13 | Full coverage of JavaFX would require at least another 14 | complete book. However, this chapter should deepen your understanding 15 | of JavaFX and GUI programming.

16 | 17 |
-------------------------------------------------------------------------------- /javanotes9/c13-GUI2/line-attributes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/line-attributes.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/linear-gradient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/linear-gradient.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/mandelbrot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/mandelbrot.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/paint-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/paint-demo.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/radial-gradient.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/radial-gradient.jpg -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/scatter-plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/scatter-plot.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/scratch-off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/scratch-off.jpg -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/silly-stamper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/silly-stamper.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/smudge-rect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/smudge-rect.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/stroke-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/stroke-demo.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/table-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/table-demo.png -------------------------------------------------------------------------------- /javanotes9/c13-GUI2/transforms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c13-GUI2/transforms.png -------------------------------------------------------------------------------- /javanotes9/c2-basics/eclipse-create-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c2-basics/eclipse-create-project.png -------------------------------------------------------------------------------- /javanotes9/c2-basics/eclipse-fx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c2-basics/eclipse-fx.png -------------------------------------------------------------------------------- /javanotes9/c3-control/array-of-ints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/array-of-ints.png -------------------------------------------------------------------------------- /javanotes9/c3-control/checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/checkerboard.png -------------------------------------------------------------------------------- /javanotes9/c3-control/coords-and-shapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/coords-and-shapes.png -------------------------------------------------------------------------------- /javanotes9/c3-control/for-loop-flow-control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/for-loop-flow-control.png -------------------------------------------------------------------------------- /javanotes9/c3-control/if-else-flow-control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/if-else-flow-control.png -------------------------------------------------------------------------------- /javanotes9/c3-control/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

The basic building blocks of programs—variables, 6 | expressions, assignment statements, and subroutine call statements—were 7 | covered in the previous chapter. Starting with this chapter, we look at how 8 | these building blocks can be put together to build complex programs with more 9 | interesting behavior.

10 | 11 |

Since we are still working on the level of "programming in the small" in 12 | this chapter, we are interested in the kind of complexity that can occur within 13 | a single subroutine. On this level, complexity is provided by control structures. 14 | The two types of control structures, loops 15 | and branches, can be used to repeat a sequence of statements over and over or 16 | to choose among two or more possible courses of action. Java includes several 17 | control structures of each type, and we will look at each of them in some 18 | detail.

19 | 20 |

Program complexity can be seen not just in control structures but also in 21 | data structures. A data structure is an organized collection 22 | of data, chunked together so that it can be treated as a unit. 23 | in this chapter includes an introduction to one of the most common data structures: 24 | arrays.

25 | 26 |

The chapter will also begin the study of program design. Given a problem, 27 | how can you come up with a program to solve that problem? We'll look at a 28 | partial answer to this question in . Finally, 29 | is a very brief first look at GUI programming. 30 |

31 | 32 |
-------------------------------------------------------------------------------- /javanotes9/c3-control/motion-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/motion-demo.png -------------------------------------------------------------------------------- /javanotes9/c3-control/moving-rects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/moving-rects.png -------------------------------------------------------------------------------- /javanotes9/c3-control/multiway-if-flow-control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/multiway-if-flow-control.png -------------------------------------------------------------------------------- /javanotes9/c3-control/parallel-lines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/parallel-lines.png -------------------------------------------------------------------------------- /javanotes9/c3-control/random-circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/random-circles.png -------------------------------------------------------------------------------- /javanotes9/c3-control/two-d-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/two-d-array.png -------------------------------------------------------------------------------- /javanotes9/c3-control/while-and-if-flow-control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c3-control/while-and-if-flow-control.png -------------------------------------------------------------------------------- /javanotes9/c4-subroutines/exercise-mosaic-brighten.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c4-subroutines/exercise-mosaic-brighten.png -------------------------------------------------------------------------------- /javanotes9/c4-subroutines/exercise-mosaic-convert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c4-subroutines/exercise-mosaic-convert.png -------------------------------------------------------------------------------- /javanotes9/c4-subroutines/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

One way to break up a complex program into 7 | manageable pieces is to use subroutines. A 8 | subroutine consists of the instructions for carrying out a certain task, 9 | grouped together and given a name. Elsewhere in the program, that name can be 10 | used as a stand-in for the whole set of instructions. As a computer executes a 11 | program, whenever it encounters a subroutine name, it executes all the 12 | instructions necessary to carry out the task associated with that 13 | subroutine.

14 | 15 |

Subroutines can be used over and over, at different places in the program. A 16 | subroutine can even be used inside another subroutine. This allows you to write 17 | simple subroutines and then use them to help write more complex subroutines, 18 | which can then be used in turn in other subroutines. In this way, very complex 19 | programs can be built up step-by-step, where each step in the construction is 20 | reasonably simple.

21 | 22 |

Subroutines in Java can be either static or non-static. This chapter 23 | covers static subroutines. Non-static subroutines, which are used in 24 | true object-oriented programming, will be covered in the next chapter.

25 | 26 |
-------------------------------------------------------------------------------- /javanotes9/c4-subroutines/mosaic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c4-subroutines/mosaic.png -------------------------------------------------------------------------------- /javanotes9/c4-subroutines/package-class-subroutine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c4-subroutines/package-class-subroutine.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/beveled-rects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/beveled-rects.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/class-userdata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/class-userdata.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/growing-circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/growing-circles.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/instance-of-PlayerData.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/instance-of-PlayerData.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Whereas a subroutine represents a single task, an 5 | object can encapsulate both data (in the form of instance variables) and a 6 | number of different tasks or "behaviors" related to that data (in the form of 7 | instance methods). Therefore objects provide another, more sophisticated type 8 | of structure that can be used to help manage the complexity of large 9 | programs.

10 | 11 |

The first four 12 | sections of this chapter introduce the basic things you need to know to work with objects 13 | and to define simple classes. The remaining sections cover more advanced topics; you 14 | might not understand them fully the first time through. In particular, 15 | covers the most central ideas of object-oriented programming: inheritance and 16 | polymorphism. However, in this textbook, we will generally use these ideas in a 17 | limited form, by creating independent classes and building on existing classes 18 | rather than by designing entire hierarchies of classes from scratch. 19 |

20 | 21 |
-------------------------------------------------------------------------------- /javanotes9/c5-OOP/multiple-inheritance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/multiple-inheritance.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/objects-in-heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/objects-in-heap.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/shapedraw-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/shapedraw-screenshot.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/subclass-superclass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/subclass-superclass.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/various-shapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/various-shapes.png -------------------------------------------------------------------------------- /javanotes9/c5-OOP/vehicle-hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c5-OOP/vehicle-hierarchy.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/HelloWorldFX-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/HelloWorldFX-screenshot.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/StatCalcGUI-less-ugly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/StatCalcGUI-less-ugly.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/StatCalcGUI-ugly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/StatCalcGUI-ugly.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/TextInputDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/TextInputDemo.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/blackjack-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/blackjack-gui.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/border-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/border-demo.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/border-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/border-layout.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/cards.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/clickable-checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/clickable-checkerboard.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/colorRadioButtons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/colorRadioButtons.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/crisscross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/crisscross.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/event-handling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/event-handling.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/grid-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/grid-layout.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/high-low-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/high-low-gui.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/mosaic-draw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/mosaic-draw.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/null-layout-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/null-layout-demo.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/panels-in-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/panels-in-layout.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/pixel-coordinates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/pixel-coordinates.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/polygon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/polygon.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/randomCards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/randomCards.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/randomStrings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/randomStrings.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/roll-dice-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/roll-dice-gui.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/s7.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/s8.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/scene-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/scene-graph.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/simple-calc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/simple-calc.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/simple-paint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/simple-paint.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/simple-stamper-with-drag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/simple-stamper-with-drag.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/simple-stamper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/simple-stamper.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/slider-and-button-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/slider-and-button-demo.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/slider-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/slider-demo.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/square-in-circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/square-in-circle.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/stat-calc-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/stat-calc-gui.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/sub-killer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/sub-killer.png -------------------------------------------------------------------------------- /javanotes9/c6-GUI1/text-count.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c6-GUI1/text-count.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/checkerboard-contents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/checkerboard-contents.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/checkers-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/checkers-game.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/delete-from-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/delete-from-array.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/gomoku-board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/gomoku-board.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/insertion-sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/insertion-sort.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/life-neighbors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/life-neighbors.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/life-rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/life-rules.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/symmetric-matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/symmetric-matrix.png -------------------------------------------------------------------------------- /javanotes9/c7-arrays/two-dimensional-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c7-arrays/two-dimensional-array.png -------------------------------------------------------------------------------- /javanotes9/c8-robustness/SimpleGrapher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c8-robustness/SimpleGrapher.png -------------------------------------------------------------------------------- /javanotes9/c8-robustness/exception-hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c8-robustness/exception-hierarchy.png -------------------------------------------------------------------------------- /javanotes9/c8-robustness/rates-of-growth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c8-robustness/rates-of-growth.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/QuicksortStep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/QuicksortStep.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/TowersOfHanoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/TowersOfHanoi.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/binary-sort-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/binary-sort-tree.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/binary-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/binary-tree.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/blobs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/blobs.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/build-bst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/build-bst.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/depth-breadth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/depth-breadth.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/expression-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/expression-tree.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/insert-in-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/insert-in-list.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/intro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

In this chapter, we look at two advanced 5 | programming techniques, recursion and linked data structures, and some of their 6 | applications. Both of these techniques are related to the seemingly paradoxical 7 | idea of defining something in terms of itself. This turns out to be a 8 | remarkably powerful idea.

9 | 10 |

A subroutine is said to be recursive if it calls itself, either directly or 11 | indirectly. What this means is that the subroutine is used in its own definition. Recursion 12 | can often be used to solve complex problems by reducing them to simpler 13 | problems of the same type.

14 | 15 |

A reference to one object can be stored in an instance variable of another 16 | object. The objects are then said to be "linked." Complex data structures can 17 | be built by linking objects together. An especially interesting case occurs 18 | when an object contains a link to another object that belongs to the same 19 | class. In that case, the class is used in its own definition. Several important 20 | types of data structures are built using classes of this kind.

21 |
-------------------------------------------------------------------------------- /javanotes9/c9-recursion/linked-data-structures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/linked-data-structures.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/list-with-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/list-with-head.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/looped-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/looped-list.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/queue.png -------------------------------------------------------------------------------- /javanotes9/c9-recursion/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/c9-recursion/stack.png -------------------------------------------------------------------------------- /javanotes9/convert-check-sourcerefs.xsl: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | source/ 24 | source/chapter/ 25 | 26 | 27 | 28 | Cannot find . 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 | -------------------------------------------------------------------------------- /javanotes9/convert-exercise-progs.xsl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | exercise-programs/chapter/.java 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /javanotes9/epub-files/META-INF/container.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /javanotes9/epub-files/OEBPS/cover.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Javanotes 9 Cover 6 | 7 | 8 |
Javanotes 9 cover image
9 | 10 | 11 | -------------------------------------------------------------------------------- /javanotes9/epub-files/OEBPS/exercise-answers-intro.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Answers to End-of-Chapter Exercises 6 | 7 | 8 |
9 |

Answers to End-Of-Chapter Exercises

10 |

This section contains sample solutions to the exercises that occur at the end of each chapter, 11 | starting with Chapter 2. 12 | The solution includes a discussion of the problem, as well as the code for a solution. 13 | The discussion is meant to be read, and in many cases will supplement the reading from the 14 | chapter itself.

15 |

Remember that there are many ways to solve a programming problem!

16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /javanotes9/epub-files/OEBPS/quiz-answers-intro.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Answers to End-of-Chapter Quizzes 6 | 7 | 8 |
9 |

Answers to End-Of-Chapter Quizzes

10 |

This section contains sample answer to the quizzes that occur at the end of each chapter.

11 |

Remember that, in many cases, many answers are possible. This is especially true for 12 | questions that ask you to write code!

13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /javanotes9/epub-files/mimetype: -------------------------------------------------------------------------------- 1 | application/epub+zip -------------------------------------------------------------------------------- /javanotes9/javafx-src-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/javafx-src-setup.png -------------------------------------------------------------------------------- /javanotes9/javanotes9-cover-180x235.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/javanotes9-cover-180x235.png -------------------------------------------------------------------------------- /javanotes9/javanotes9-cover-518x675.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/javanotes9-cover-518x675.jpg -------------------------------------------------------------------------------- /javanotes9/javanotes9-epub.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | ]> 5 | 6 | 7 | &includes; 8 | -------------------------------------------------------------------------------- /javanotes9/javanotes9-tex.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ]> 14 | 15 | 16 | &includes; 17 | -------------------------------------------------------------------------------- /javanotes9/javanotes9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | &includes; 5 | 6 | -------------------------------------------------------------------------------- /javanotes9/news.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Javanotes Version 8.0 -- News 4 | 5 | 6 | 7 |
8 |
9 |

Introduction to Programming Using Java, Version 9.0

10 |

News and Errata

11 | 12 |
13 | 14 |

News and Errata for Introduction to Programming Using Java
15 | can be found in the on-line version of this page, at
16 | http://math.hws.edu/javanotes/news.html

17 | 18 |
19 |
David Eck
20 | 21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /javanotes9/src-c11/DirectoryList.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.util.Scanner; 3 | 4 | /** 5 | * This program lists the files in a directory specified by 6 | * the user. The user is asked to type in a directory name. 7 | * If the name entered by the user is not a directory, a 8 | * message is printed and the program ends. 9 | */ 10 | public class DirectoryList { 11 | 12 | 13 | public static void main(String[] args) { 14 | 15 | String directoryName; // Directory name entered by the user. 16 | File directory; // File object referring to the directory. 17 | String[] files; // Array of file names in the directory. 18 | Scanner scanner; // For reading a line of input from the user. 19 | 20 | scanner = new Scanner(System.in); // scanner reads from standard input. 21 | 22 | System.out.print("Enter a directory name: "); 23 | directoryName = scanner.nextLine().trim(); 24 | directory = new File(directoryName); 25 | 26 | if (directory.isDirectory() == false) { 27 | if (directory.exists() == false) 28 | System.out.println("There is no such directory!"); 29 | else 30 | System.out.println("That file is not a directory."); 31 | } 32 | else { 33 | files = directory.list(); 34 | System.out.println("Files in directory \"" + directory + "\":"); 35 | for (int i = 0; i < files.length; i++) 36 | System.out.println(" " + files[i]); 37 | } 38 | 39 | } // end main() 40 | 41 | } // end class DirectoryList 42 | -------------------------------------------------------------------------------- /javanotes9/src-c11/ReverseFileWithResources.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * Reads numbers from a file named data.dat and writes them to a file 7 | * named result.dat in reverse order. The input file should contain 8 | * exactly one real number per line. 9 | * This version of the ReverseFile program uses try-with-resource 10 | * statements to safely open and close the Scanner that is used to 11 | * read the data and the PrintWriter that is used to 12 | * write the data. 13 | */ 14 | public class ReverseFileWithResources { 15 | 16 | public static void main(String[] args) { 17 | 18 | ArrayList numbers; // An ArrayList for holding the data. 19 | 20 | numbers = new ArrayList(); 21 | 22 | // Read the data from the input file. 23 | 24 | try( Scanner data = new Scanner(new File("data.dat")) ) { 25 | // Read numbers, adding them to the ArrayList. 26 | while ( data.hasNextDouble() ) { // Read until end-of-file. 27 | double inputNumber = data.nextDouble(); 28 | numbers.add( inputNumber ); 29 | } 30 | } 31 | catch (FileNotFoundException e) { 32 | // Can be caused if file does not exist or can't be read. 33 | System.out.println("Can't open input file data.dat!"); 34 | System.out.println("Error: " + e); 35 | return; // Return from main(), since an error has occurred. 36 | } 37 | 38 | // Write the data to the output file. 39 | 40 | try( PrintWriter result = new PrintWriter("result.dat") ) { 41 | // Output the numbers in reverse order. 42 | for (int i = numbers.size()-1; i >= 0; i--) 43 | result.println(numbers.get(i)); 44 | result.flush(); // Make sure data is actually sent to the file. 45 | if (result.checkError()) 46 | System.out.println("Some error occurred while writing the file."); 47 | else 48 | System.out.println("Done!"); 49 | } 50 | catch (FileNotFoundException e) { 51 | // Can only be caused by the PrintWriter constructor 52 | System.out.println("Can't open file result.dat!"); 53 | System.out.println("Error: " + e); 54 | } 55 | 56 | } // end of main() 57 | 58 | } // end class ReverseFileWithTextReader 59 | -------------------------------------------------------------------------------- /javanotes9/src-c11/ReverseFileWithScanner.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * Reads numbers from a file named data.dat and writes them to a file 7 | * named result.dat in reverse order. The input file should contain 8 | * only real numbers. 9 | */ 10 | public class ReverseFileWithScanner { 11 | 12 | public static void main(String[] args) { 13 | 14 | Scanner data; // For reading the data. 15 | PrintWriter result; // Character output stream for writing data. 16 | 17 | ArrayList numbers; // An ArrayList for holding the data. 18 | 19 | numbers = new ArrayList(); 20 | 21 | try { // Create the input stream. 22 | data = new Scanner(new File("data.dat")); 23 | } 24 | catch (FileNotFoundException e) { 25 | System.out.println("Can't find file data.dat!"); 26 | return; // End the program by returning from main(). 27 | } 28 | 29 | try { // Create the output stream. 30 | result = new PrintWriter("result.dat"); 31 | } 32 | catch (FileNotFoundException e) { 33 | System.out.println("Can't open file result.dat!"); 34 | System.out.println("Error: " + e); 35 | data.close(); // Close the input file. 36 | return; // End the program. 37 | } 38 | 39 | while ( data.hasNextDouble() ) { // Read until end-of-file. 40 | double inputNumber = data.nextDouble(); 41 | numbers.add( inputNumber ); 42 | } 43 | 44 | // Output the numbers in reverse order. 45 | 46 | for (int i = numbers.size()-1; i >= 0; i--) 47 | result.println(numbers.get(i)); 48 | 49 | System.out.println("Done!"); 50 | 51 | data.close(); 52 | result.close(); 53 | 54 | } // end of main() 55 | 56 | } // end class ReverseFileWithScanner -------------------------------------------------------------------------------- /javanotes9/src-c11/ShowMyNetwork.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.util.Enumeration; 3 | 4 | /** 5 | * This short program lists information about available network interfaces 6 | * on the computer on which it is run. The name of each interface is 7 | * output along with a list of one or more IP addresses for that 8 | * interface. The names are arbitrary names assigned by the operating 9 | * system to the interfaces. The addresses can include both IPv4 and 10 | * IPv6 addresses. The list should include the local loopback interface 11 | * (usually referred to as "localhost") as well as the interface 12 | * corresponding to any network card that has been installed and configured. 13 | */ 14 | public class ShowMyNetwork { 15 | 16 | public static void main(String[] args) { 17 | 18 | Enumeration netInterfaces; 19 | 20 | System.out.println(); 21 | 22 | try { 23 | netInterfaces = NetworkInterface.getNetworkInterfaces(); 24 | } 25 | catch (Exception e){ 26 | System.out.println(); 27 | System.out.println("Sorry, an error occurred while looking for network"); 28 | System.out.println("interfaces. The error was:"); 29 | System.out.println(e); 30 | return; 31 | } 32 | 33 | if (! netInterfaces.hasMoreElements() ) { 34 | System.out.println("No network interfaces found."); 35 | return; 36 | } 37 | 38 | System.out.println("Network interfaces found on this computer:"); 39 | 40 | while (netInterfaces.hasMoreElements()) { 41 | NetworkInterface net = netInterfaces.nextElement(); 42 | String name = net.getName(); 43 | System.out.print(" " + name + " : "); 44 | Enumeration inetAddresses = net.getInetAddresses(); 45 | while (inetAddresses.hasMoreElements()) { 46 | InetAddress address = inetAddresses.nextElement(); 47 | System.out.print(address + " "); 48 | } 49 | System.out.println(); 50 | } 51 | 52 | System.out.println(); 53 | 54 | } // end main() 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /javanotes9/src-c12/MyLinkedBlockingQueue.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | 3 | /** 4 | * As a simple example of using wait() and notify(), this class 5 | * implements the three methods of a LinkedBlockingQueue that 6 | * are used in the sample program MultiprocessingDemo3. This class 7 | * could be used as a replacement for the standard LinkedBlockingQueue 8 | * in that program. 9 | */ 10 | public class MyLinkedBlockingQueue { 11 | 12 | private LinkedList taskList = new LinkedList(); 13 | 14 | public void clear() { 15 | synchronized(taskList) { 16 | taskList.clear(); 17 | } 18 | } 19 | 20 | public void add(Runnable task) { 21 | synchronized(taskList) { 22 | taskList.addLast(task); 23 | taskList.notify(); 24 | } 25 | } 26 | 27 | public Runnable take() throws InterruptedException { 28 | synchronized(taskList) { 29 | while (taskList.isEmpty()) 30 | taskList.wait(); 31 | return taskList.removeFirst(); 32 | } 33 | } 34 | 35 | } // end MyLinkedBlockingQueue 36 | -------------------------------------------------------------------------------- /javanotes9/src-c12/netgame/chat/ChatRoomServer.java: -------------------------------------------------------------------------------- 1 | package netgame.chat; 2 | 3 | import java.io.IOException; 4 | import netgame.common.Hub; 5 | 6 | /** 7 | * This class contains just a small main class that creates a Hub 8 | * and starts it listening on port 37829. This port is used 9 | * by the ChatRoomWindow application. This program should be run 10 | * on the computer that "hosts" the chat room. See the ChatRoomWindow 11 | * class for more details. Once the server starts listening, it 12 | * will listen for connection requests from clients until the 13 | * ChatRoomServer program is terminated (for example by a 14 | * Control-C). 15 | *

Note that the ChatRoom application uses a basic, generic 16 | * Hub, which simply forwards any message that it receives from 17 | * a client to all connected clients (including the one that 18 | * sent it), wrapped in an object of type ForwardedMessage. 19 | */ 20 | public class ChatRoomServer { 21 | 22 | private final static int PORT = 37829; 23 | 24 | public static void main(String[] args) { 25 | try { 26 | new Hub(PORT); 27 | } 28 | catch (IOException e) { 29 | System.out.println("Can't create listening socket. Shutting down."); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /javanotes9/src-c12/netgame/common/DisconnectMessage.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * A DisconnectMesaage is sent from a Client to the Hub when that 7 | * client wants to disconnect. A DisconnectMessage is also sent from 8 | * the Hub to each client just before it shuts down normally. DisconnectMessages 9 | * are for internal use in the netgame.common package and are not used 10 | * directly by users of the package. 11 | */ 12 | final class DisconnectMessage implements Serializable { 13 | 14 | /** 15 | * The message associated with the disconnect. When the Hub 16 | * sends disconnects because it is shutting down, the message 17 | * is "*shutdown*". 18 | */ 19 | final public String message; 20 | 21 | /** 22 | * Creates a DisconnectMessage containing a given String, which 23 | * is meant to describe the reason for the disconnection. 24 | */ 25 | public DisconnectMessage(String message) { 26 | this.message = message; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javanotes9/src-c12/netgame/common/ForwardedMessage.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Represents a message that was received by the Hub from 7 | * one clients and that is being forwarded to all clients. 8 | * A ForwardedMessage includes the message that was sent 9 | * by a client to the Hub and the ID number of the client 10 | * who sent it. The default action of a Hub -- defined 11 | * in the messageReceived(playerID,message) method of 12 | * that class -- is to wrap the message in a ForwardedMessage 13 | * and send the ForwardedMessage to all connected client, 14 | * including the client who sent the original message. 15 | * When an application uses a subclass of Hub, it is 16 | * likely to override that behavior. 17 | */ 18 | public class ForwardedMessage implements Serializable { 19 | 20 | public final Object message; // Original message from a client. 21 | public final int senderID; // The ID of the client who sent that message. 22 | 23 | /** 24 | * Create a ForwadedMessage to wrap a message sent by a client. 25 | * @param senderID the ID number of the original sender. 26 | * @param message the original message. 27 | */ 28 | public ForwardedMessage(int senderID, Object message) { 29 | this.senderID = senderID; 30 | this.message = message; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /javanotes9/src-c12/netgame/common/ResetSignal.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | /** 4 | * This package private class is used internally in Hub and Client 5 | * to send a signal to the message output thread that the output 6 | * stream should be reset. A ResetSignal has no data. 7 | */ 8 | class ResetSignal { 9 | } 10 | -------------------------------------------------------------------------------- /javanotes9/src-c12/netgame/common/StatusMessage.java: -------------------------------------------------------------------------------- 1 | package netgame.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * The Hub sends a StatusMessage to all connected clients when 7 | * a player connects or disconnects. When a player connects, 8 | * that player receives the status message caused by their 9 | * connecting. When a player disconnects, that player does 10 | * not receive a copy of the status message that is sent. 11 | * StatusMessages are from internal use in the netgame.common 12 | * package and users of this package do not have to deal with 13 | * them. This package private class is only used internally 14 | * in the netgame.common package. Users of the package will 15 | * not see these messages; instead, the Client's playerConnected() 16 | * or playerDisconnected() method will be called. 17 | */ 18 | final class StatusMessage implements Serializable { 19 | 20 | /** 21 | * The ID number of the player who has connected or disconnected. 22 | */ 23 | public final int playerID; 24 | 25 | /** 26 | * True if the player has just connected; false if the player 27 | * has just disconnected. 28 | */ 29 | public final boolean connecting; 30 | 31 | /** 32 | * The list of players after the change has been made. 33 | */ 34 | public final int[] players; 35 | 36 | public StatusMessage(int playerID, boolean connecting, int[] players) { 37 | this.playerID = playerID; 38 | this.connecting = connecting; 39 | this.players = players; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /javanotes9/src-c12/netgame/fivecarddraw/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c12/netgame/fivecarddraw/cards.png -------------------------------------------------------------------------------- /javanotes9/src-c13/StopWatchLabel.java: -------------------------------------------------------------------------------- 1 | 2 | import javafx.scene.control.Label; 3 | 4 | /** 5 | * A custom component that acts as a simple stop-watch. When the user clicks 6 | * on it, this component starts timing. When the user clicks again, 7 | * it displays the time between the two clicks. Clicking a third time 8 | * starts another timer, etc. While it is timing, the label just 9 | * displays the message "Timing....". 10 | */ 11 | public class StopWatchLabel extends Label { 12 | 13 | private long startTime; // Start time of timer. 14 | // (Time is measured in milliseconds.) 15 | 16 | private boolean running; // True when the timer is running. 17 | 18 | /** 19 | * Constructor sets initial text on the label to 20 | * "Click to start timer." and sets up a mouse event 21 | * handler so the label can respond to clicks. 22 | */ 23 | public StopWatchLabel() { 24 | super(" Click to start timer. "); 25 | setOnMousePressed( e -> setRunning( !running ) ); 26 | } 27 | 28 | 29 | /** 30 | * Tells whether the timer is currently running. 31 | */ 32 | public boolean isRunning() { 33 | return running; 34 | } 35 | 36 | 37 | /** 38 | * Sets the timer to be running or stopped, and changes the text that 39 | * is shown on the label. (This method should be called on the JavaFX 40 | * application thread.) 41 | * @param running says whether the timer should be running; if this 42 | * is equal to the current state, nothing is done. 43 | */ 44 | public void setRunning( boolean running ) { 45 | if (this.running == running) 46 | return; 47 | this.running = running; 48 | if (running == true) { 49 | // Record the time and start the timer. 50 | startTime = System.currentTimeMillis(); 51 | setText("Timing...."); 52 | } 53 | else { 54 | // Stop the timer. Compute the elapsed time since the 55 | // timer was started and display it. 56 | long endTime = System.currentTimeMillis(); 57 | double seconds = (endTime - startTime) / 1000.0; 58 | setText( String.format("Time: %1.3f seconds", seconds) ); 59 | } 60 | } 61 | 62 | } // end StopWatchLabel 63 | -------------------------------------------------------------------------------- /javanotes9/src-c13/TestStopWatch.java: -------------------------------------------------------------------------------- 1 | 2 | import javafx.application.Application; 3 | import javafx.scene.Scene; 4 | import javafx.stage.Stage; 5 | import javafx.scene.layout.StackPane; 6 | import javafx.geometry.Pos; 7 | 8 | /** 9 | * Shows a StopWatchLabel. The user can click to start a timer 10 | * and click again to stop it. The elapsed time is displayed. 11 | */ 12 | public class TestStopWatch extends Application { 13 | 14 | public static void main(String[] args) { 15 | launch(args); 16 | } 17 | //------------------------------------------------------------ 18 | 19 | public void start(Stage stage) { 20 | 21 | StopWatchLabel stopWatch = new StopWatchLabel(); 22 | stopWatch.setStyle("-fx-font: bold 30pt serif; -fx-background-color:#ffffee;" 23 | + "-fx-border-color:#008; -fx-border-width:3px; -fx-padding:20px;" 24 | + "-fx-text-fill: #008"); 25 | stopWatch.setMaxSize(Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY); 26 | stopWatch.setAlignment(Pos.CENTER); 27 | 28 | stage.setScene( new Scene(new StackPane(stopWatch)) ); 29 | stage.setTitle("StopWatchLabel Demo"); 30 | stage.show(); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /javanotes9/src-c13/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/cards.png -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/README.txt: -------------------------------------------------------------------------------- 1 | 2 | The files in this "examples" directory are used in the applet 3 | version of the Mandelbrot Viewer program , which is defined in 4 | the file MandelbrotApplet.java. They are NOT needed by any 5 | other part of the program. 6 | 7 | Note that these are "Params" files that can also be loaded by 8 | hand into the stand-alone application version of the program 9 | using its Open Params command. 10 | 11 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings1.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings10.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings11.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings12.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings2.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings3.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings4.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings5.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings6.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings7.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings8.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/edu/hws/eck/mdbfx/examples/settings9.mdb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /javanotes9/src-c13/face-smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/face-smile.png -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/.DS_Store -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/README.txt: -------------------------------------------------------------------------------- 1 | The files in this directory are public domain 2 | images downloaed from WikiMedia. 3 | -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/bluejay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/bluejay.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/chipmunk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/chipmunk.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/collie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/collie.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/elephants.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/elephants.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/faun.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/faun.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/lion.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/lion.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/polar-bear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/polar-bear.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/nature-images/stork.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/nature-images/stork.jpg -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/README.txt: -------------------------------------------------------------------------------- 1 | The icons in this folder are for the sample program 2 | SillyStamper.java. They were taken from the KDE desktop 3 | icon collection. 4 | 5 | -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon10.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon11.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon24.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon25.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon26.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon31.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon33.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon34.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon5.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon7.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon8.png -------------------------------------------------------------------------------- /javanotes9/src-c13/stamper_icons/icon9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/stamper_icons/icon9.png -------------------------------------------------------------------------------- /javanotes9/src-c13/tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c13/tile.png -------------------------------------------------------------------------------- /javanotes9/src-c2/CreateProfile.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * Creates a file named "profile.txt" containing four lines of information 5 | * about the user. The user is prompted to enter the required information. 6 | * 7 | */ 8 | public class CreateProfile { 9 | 10 | public static void main(String[] args) { 11 | 12 | String name; // The user's name. 13 | String email; // The user's email address. 14 | double salary; // the user's yearly salary. 15 | String favColor; // The user's favorite color. 16 | 17 | TextIO.putln("Good Afternoon! This program will create"); 18 | TextIO.putln("your profile file, if you will just answer"); 19 | TextIO.putln("a few simple questions."); 20 | TextIO.putln(); 21 | 22 | /* Gather responses from the user. */ 23 | 24 | TextIO.put("What is your name? "); 25 | name = TextIO.getln(); 26 | TextIO.put("What is your email address? "); 27 | email = TextIO.getln(); 28 | TextIO.put("What is your yearly income? "); 29 | salary = TextIO.getlnDouble(); 30 | TextIO.put("What is your favorite color? "); 31 | favColor = TextIO.getln(); 32 | 33 | /* Write the user's information to the file named profile.txt. */ 34 | 35 | TextIO.writeFile("profile.txt"); // subsequent output goes to file 36 | TextIO.putln("Name: " + name); 37 | TextIO.putln("Email: " + email); 38 | TextIO.putln("Favorite Color: " + favColor); 39 | TextIO.putf( "Yearly Income: $%,1.2f%n", salary); 40 | 41 | /* Print a final message to standard output. */ 42 | 43 | TextIO.writeStandardOutput(); 44 | TextIO.putln("Thank you. Your profile has been written to profile.txt."); 45 | 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /javanotes9/src-c2/Day.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file defines an enum representing the days of the week. 3 | */ 4 | public enum Day { 5 | SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY 6 | } 7 | -------------------------------------------------------------------------------- /javanotes9/src-c2/EnumDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program demonstrates the use of enum types. 3 | * The enum types Day and Month are defined in this file. 4 | */ 5 | public class EnumDemo { 6 | 7 | // Define two enum types. (In Java 17, these definitions could also be 8 | // inside main(), but earlier versions of Java require them to be outside 9 | // main(), or in a separate .java file.) 10 | 11 | enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } 12 | 13 | enum Month { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC } 14 | 15 | public static void main(String[] args) { 16 | 17 | Day tgif; // Declare a variable of type Day. 18 | Month libra; // Declare a variable of type Month. 19 | 20 | tgif = Day.FRIDAY; // Assign a value of type Day to tgif. 21 | libra = Month.OCT; // Assign a value of type Month to libra. 22 | 23 | System.out.print("My sign is libra, since I was born in "); 24 | System.out.println(libra); // Output value will be: OCT 25 | System.out.print("That's the "); 26 | System.out.print( libra.ordinal() ); 27 | System.out.println("-th month of the year."); 28 | System.out.println(" (Counting from 0, of course!)"); 29 | 30 | System.out.print("Isn't it nice to get to "); 31 | System.out.println(tgif); // Output value will be: FRIDAY 32 | 33 | System.out.println( tgif + " is the " + tgif.ordinal() 34 | + "-th day of the week."); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /javanotes9/src-c2/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /** A program to display the message 2 | * "Hello World!" on standard output. 3 | */ 4 | public class HelloWorld { 5 | 6 | public static void main(String[] args) { 7 | System.out.println("Hello World!"); 8 | } 9 | 10 | } // end of class HelloWorld 11 | -------------------------------------------------------------------------------- /javanotes9/src-c2/Interest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This class implements a simple program that 3 | * will compute the amount of interest that is 4 | * earned on $17,000 invested at an interest 5 | * rate of 0.027 for one year. The interest and 6 | * the value of the investment after one year are 7 | * printed to standard output. 8 | */ 9 | public class Interest { 10 | 11 | public static void main(String[] args) { 12 | 13 | /* Declare the variables. */ 14 | 15 | double principal; // The value of the investment. 16 | double rate; // The annual interest rate. 17 | double interest; // Interest earned in one year. 18 | 19 | /* Do the computations. */ 20 | 21 | principal = 17000; 22 | rate = 0.027; 23 | interest = principal * rate; // Compute the interest. 24 | 25 | principal = principal + interest; 26 | // Compute value of investment after one year, with interest. 27 | // (Note: The new value replaces the old value of principal.) 28 | 29 | /* Output the results. */ 30 | 31 | System.out.print("The interest earned is $"); 32 | System.out.println(interest); 33 | System.out.print("The value of the investment after one year is $"); 34 | System.out.println(principal); 35 | 36 | } // end of main() 37 | 38 | } // end of class Interest 39 | -------------------------------------------------------------------------------- /javanotes9/src-c2/Interest2.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * This class implements a simple program that will compute 5 | * the amount of interest that is earned on an investment over 6 | * a period of one year. The initial amount of the investment 7 | * and the interest rate are input by the user. The value of 8 | * the investment at the end of the year is output. The 9 | * rate must be input as a decimal, not a percentage (for 10 | * example, 0.05 rather than 5). 11 | * 12 | * This program requires TextIO for input. TextIO is not a 13 | * standard part of Java, so it must be made available when 14 | * the program is compiled or run. 15 | */ 16 | public class Interest2 { 17 | 18 | public static void main(String[] args) { 19 | 20 | double principal; // The value of the investment. 21 | double rate; // The annual interest rate. 22 | double interest; // The interest earned during the year. 23 | 24 | System.out.print("Enter the initial investment: "); 25 | principal = TextIO.getlnDouble(); 26 | 27 | System.out.print("Enter the annual interest rate (as a decimal): "); 28 | rate = TextIO.getlnDouble(); 29 | 30 | interest = principal * rate; // Compute this year's interest. 31 | principal = principal + interest; // Add it to principal. 32 | 33 | System.out.printf("The amount of interest is $%1.2f%n", interest); 34 | System.out.printf("The value after one year is $%1.2f%n", principal); 35 | 36 | } // end of main() 37 | 38 | } // end of class Interest2 39 | -------------------------------------------------------------------------------- /javanotes9/src-c2/Interest2WithScanner.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; // Make the Scanner class available. 2 | 3 | /** 4 | * This class implements a simple program that will compute 5 | * the amount of interest that is earned on an investment over 6 | * a period of one year. The initial amount of the investment 7 | * and the interest rate are input by the user. The value of 8 | * the investment at the end of the year is output. The 9 | * rate must be input as a decimal, not a percentage (for 10 | * example, 0.05 rather than 5). 11 | * 12 | * This program uses the standard Scanner class for input. 13 | */ 14 | public class Interest2WithScanner { 15 | 16 | public static void main(String[] args) { 17 | 18 | Scanner stdin = new Scanner( System.in ); // Create the Scanner. 19 | 20 | double principal; // The value of the investment. 21 | double rate; // The annual interest rate. 22 | double interest; // The interest earned during the year. 23 | 24 | System.out.print("Enter the initial investment: "); 25 | principal = stdin.nextDouble(); 26 | 27 | System.out.print("Enter the annual interest rate (as a decimal): "); 28 | rate = stdin.nextDouble(); 29 | 30 | interest = principal * rate; // Compute this year's interest. 31 | principal = principal + interest; // Add it to principal. 32 | 33 | System.out.printf("The amount of interest is $%1.2f%n", interest); 34 | System.out.printf("The value after one year is $%1.2f%n", principal); 35 | 36 | } // end of main() 37 | 38 | } // end of class Interest2WithScanner -------------------------------------------------------------------------------- /javanotes9/src-c2/Month.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file defines an enum representing the months of the year. 3 | */ 4 | public enum Month { 5 | JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC 6 | } 7 | -------------------------------------------------------------------------------- /javanotes9/src-c2/PrintSquare.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * A program that reads an integer that is typed in by the 5 | * user and computes and prints the square of that integer. 6 | */ 7 | public class PrintSquare { 8 | 9 | public static void main(String[] args) { 10 | 11 | int userInput; // The number input by the user. 12 | int square; // The userInput, multiplied by itself. 13 | 14 | System.out.print("Please type a number: "); 15 | userInput = TextIO.getlnInt(); 16 | square = userInput * userInput; 17 | 18 | System.out.println(); 19 | System.out.println("The number that you entered was " + userInput); 20 | System.out.println("The square of that number is " + square); 21 | System.out.println(); 22 | 23 | } // end of main() 24 | 25 | } //end of class PrintSquare 26 | -------------------------------------------------------------------------------- /javanotes9/src-c2/SeparateEnumDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program demonstrates the use of enum types. 3 | * 4 | * For this version of the program, the enum types are defined in 5 | * separate files, Day.java and Month.java. The version named 6 | * EnumDemo.java defines the enums in the same file. 7 | */ 8 | public class SeparateEnumDemo { 9 | 10 | public static void main(String[] args) { 11 | 12 | Day tgif; // Declare a variable of type Day. 13 | Month libra; // Declare a variable of type Month. 14 | 15 | tgif = Day.FRIDAY; // Assign a value of type Day to tgif. 16 | libra = Month.OCT; // Assign a value of type Month to libra. 17 | 18 | System.out.print("My sign is libra, since I was born in "); 19 | System.out.println(libra); // Output value will be: OCT 20 | System.out.print("That's the "); 21 | System.out.print( libra.ordinal() ); 22 | System.out.println("-th month of the year."); 23 | System.out.println(" (Counting from 0, of course!)"); 24 | 25 | System.out.print("Isn't it nice to get to "); 26 | System.out.println(tgif); // Output value will be: FRIDAY 27 | 28 | System.out.println( tgif + " is the " + tgif.ordinal() 29 | + "-th day of the week."); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /javanotes9/src-c2/TextBlockDemo.java: -------------------------------------------------------------------------------- 1 | /* This program demonstrates text blocks. A text block 2 | * is a string literal that extends over several lines. It begins 3 | * and ends with a triple double-quote ("""). The opening triple 4 | * quote must be followed (except for whitespace) by a newline, which 5 | * is not part of the string represented by the literal. Text blocks 6 | * make it easier to use multiline strings in a Java program. 7 | */ 8 | 9 | public class TextBlockDemo { 10 | 11 | public static void main(String[] args) { 12 | 13 | /* Define a multiline string. Note that extra whitespace 14 | * is stripped from the start of each line -- essentially 15 | * enough is stripped to shove the string over to the 16 | * left margin. */ 17 | 18 | String poem = """ 19 | As I was walking down the stair, 20 | I met a man who wasn't there. 21 | He wasn't there again today. 22 | I wish, I wish he'd go away!"""; 23 | 24 | System.out.println(poem); 25 | System.out.println(); 26 | 27 | /* A text block can include escaped characters such as \t, \n, 28 | * and \\. Characters other than '\' are not special in textblocks. 29 | * For example, something that looks like a Java comment inside 30 | * a text block is not a comment; it is part of the string. 31 | * Also note that when the closing """ is on a line by itself, 32 | * then the newline that precedes the """ is part of the string. */ 33 | 34 | String program = """ 35 | /** 36 | * The standard HelloWorld program. 37 | */ 38 | public class HelloWorld {\n 39 | public static void main(String[] args) { 40 | System.out.println("Hello World"); // greet the world!! 41 | }\n 42 | } 43 | """; 44 | 45 | System.out.println(program); 46 | 47 | /* A text block can be used anywhere a string literal could be used, 48 | * such as in a formatted print statement (See Section 2.4.1). */ 49 | 50 | int miles = 17; 51 | System.out.printf(""" 52 | The equivalent of %d miles is: 53 | %,d yards 54 | %,d feet 55 | %,d inches 56 | """, miles, 1760*miles, 5280*miles, 12*5280*miles); 57 | 58 | } 59 | 60 | } // end TextBlockDemo 61 | 62 | -------------------------------------------------------------------------------- /javanotes9/src-c2/TimedComputation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program performs some mathematical computations and displays the 3 | * results. It also displays the value of the constant Math.PI. It then 4 | * reports the number of seconds that the computer spent on this task. 5 | */ 6 | public class TimedComputation { 7 | 8 | public static void main(String[] args) { 9 | 10 | long startTime; // Starting time of program, in nanoseconds. 11 | long endTime; // Time when computations are done, in nanoseconds. 12 | long compTime; // Run time in nanoseconds. 13 | double seconds; // Time difference, in seconds. 14 | 15 | startTime = System.nanoTime(); 16 | 17 | double width, height, hypotenuse; // sides of a triangle 18 | width = 42.0; 19 | height = 17.0; 20 | hypotenuse = Math.sqrt( width*width + height*height ); 21 | System.out.print("A triangle with sides 42 and 17 has hypotenuse "); 22 | System.out.println(hypotenuse); 23 | 24 | System.out.println("\nMathematically, sin(x)*sin(x) + " 25 | + "cos(x)*cos(x) - 1 should be 0."); 26 | System.out.println("Let's check this for x = 100:"); 27 | System.out.print(" sin(100)*sin(100) + cos(100)*cos(100) - 1 is: "); 28 | System.out.println( Math.sin(100)*Math.sin(100) 29 | + Math.cos(100)*Math.cos(100) - 1 ); 30 | System.out.println("(There can be round-off errors when" 31 | + " computing with real numbers!)"); 32 | 33 | System.out.print("\nHere is a random number: "); 34 | System.out.println( Math.random() ); 35 | 36 | System.out.print("\nThe value of Math.PI is "); 37 | System.out.println( Math.PI ); 38 | 39 | endTime = System.nanoTime(); 40 | compTime = endTime - startTime; 41 | seconds = compTime / 1000000000.0; 42 | 43 | System.out.print("\nRun time in nanoseconds was: "); 44 | System.out.println(compTime); 45 | System.out.println("(This is probably not perfectly accurate!"); 46 | System.out.print("\nRun time in seconds was: "); 47 | System.out.println(seconds); 48 | 49 | } // end main() 50 | 51 | } // end class TimedComputation 52 | 53 | -------------------------------------------------------------------------------- /javanotes9/src-c3/BirthdayProblem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Simulate choosing people at random and checking the day of the year they 3 | * were born on. If the birthday is the same as one that was seen previously, 4 | * stop, and output the number of people who were checked. 5 | */ 6 | public class BirthdayProblem { 7 | 8 | public static void main(String[] args) { 9 | 10 | boolean[] used; // For recording the possible birthdays 11 | // that have been seen so far. A value 12 | // of true in used[i] means that a person 13 | // whose birthday is the i-th day of the 14 | // year has been found. 15 | 16 | int count; // The number of people who have been checked. 17 | 18 | used = new boolean[365]; // Initially, all entries are false. 19 | 20 | count = 0; 21 | 22 | while (true) { 23 | // Select a birthday at random, from 0 to 364. 24 | // If the birthday has already been used, quit. 25 | // Otherwise, record the birthday as used. 26 | 27 | int birthday; // The selected birthday. 28 | birthday = (int)(Math.random()*365); 29 | count++; 30 | 31 | System.out.printf("Person %d has birthday number %d%n", count, birthday); 32 | 33 | if ( used[birthday] ) { 34 | // This day was found before; It's a duplicate. We are done. 35 | break; 36 | } 37 | 38 | used[birthday] = true; 39 | 40 | } // end while 41 | 42 | System.out.println(); 43 | System.out.println("A duplicate birthday was found after " 44 | + count + " tries."); 45 | } 46 | 47 | } // end class BirthdayProblem -------------------------------------------------------------------------------- /javanotes9/src-c3/ComputeAverage.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * This program reads a sequence of positive integers input 5 | * by the user, and it will print out the average of those 6 | * integers. The user is prompted to enter one integer at a 7 | * time. The user must enter a 0 to mark the end of the 8 | * data. (The zero is not counted as part of the data to 9 | * be averaged.) The program does not check whether the 10 | * user's input is positive, so it will actually add up 11 | * both positive and negative input values. 12 | */ 13 | 14 | public class ComputeAverage { 15 | 16 | public static void main(String[] args) { 17 | 18 | int inputNumber; // One of the integers input by the user. 19 | int sum; // The sum of the positive integers. 20 | int count; // The number of positive integers. 21 | double average; // The average of the positive integers. 22 | 23 | /* Initialize the summation and counting variables. */ 24 | 25 | sum = 0; 26 | count = 0; 27 | 28 | /* Read and process the user's input. */ 29 | 30 | System.out.print("Enter your first positive integer: "); 31 | inputNumber = TextIO.getlnInt(); 32 | 33 | while (inputNumber != 0) { 34 | sum += inputNumber; // Add inputNumber to running sum. 35 | count++; // Count the input by adding 1 to count. 36 | System.out.print("Enter your next positive integer, or 0 to end: "); 37 | inputNumber = TextIO.getlnInt(); 38 | } 39 | 40 | /* Display the result. */ 41 | 42 | if (count == 0) { 43 | System.out.println("You didn't enter any data!"); 44 | } 45 | else { 46 | average = ((double)sum) / count; 47 | System.out.println(); 48 | System.out.println("You entered " + count + " positive integers."); 49 | System.out.printf("Their average is %1.3f.\n", average); 50 | } 51 | 52 | } // end main() 53 | 54 | } // end class ComputeAverage -------------------------------------------------------------------------------- /javanotes9/src-c3/ComputeAverage2.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * Computes the average of a sequence of real numbers entered by the 5 | * user. The numbers must be entered one per line. A blank input 6 | * line marks the end of the input. 7 | */ 8 | public class ComputeAverage2 { 9 | 10 | public static void main(String[] args) { 11 | String str; // The user's input. 12 | double number; // The input converted into a number. 13 | double total; // The total of all numbers entered. 14 | double avg; // The average of the numbers. 15 | int count; // The number of numbers entered. 16 | total = 0; 17 | count = 0; 18 | System.out.println("Enter your numbers, press return to end."); 19 | while (true) { 20 | System.out.print("? "); 21 | str = TextIO.getln(); 22 | if (str.equals("")) { 23 | break; // Exit the loop, since the input line was blank. 24 | } 25 | try { 26 | number = Double.parseDouble(str); 27 | // If an error occurs, the next 2 lines are skipped! 28 | total = total + number; 29 | count = count + 1; 30 | } 31 | catch (NumberFormatException e) { 32 | System.out.println("Not a legal number! Try again."); 33 | } 34 | } 35 | avg = total/count; 36 | System.out.printf("The average of %d numbers is %1.6g%n", count, avg); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /javanotes9/src-c3/Interest3.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * This class implements a simple program that will compute the amount of 5 | * interest that is earned on an investment over a period of 5 years. The 6 | * initial amount of the investment and the interest rate are input by the 7 | * user. The value of the investment at the end of each year is output. 8 | */ 9 | 10 | public class Interest3 { 11 | 12 | 13 | public static void main(String[] args) { 14 | 15 | double principal; // The value of the investment. 16 | double rate; // The annual interest rate. 17 | 18 | /* Get the initial investment and interest rate from the user. */ 19 | 20 | System.out.print("Enter the initial investment: "); 21 | principal = TextIO.getlnDouble(); 22 | 23 | System.out.println(); 24 | System.out.println("Enter the annual interest rate."); 25 | System.out.print("Enter a decimal, not a percentage: "); 26 | rate = TextIO.getlnDouble(); 27 | System.out.println(); 28 | 29 | /* Simulate the investment for 5 years. */ 30 | 31 | int years; // Counts the number of years that have passed. 32 | 33 | years = 0; 34 | while (years < 5) { 35 | double interest; // Interest for this year. 36 | interest = principal * rate; 37 | principal = principal + interest; // Add it to principal. 38 | years = years + 1; // Count the current year. 39 | System.out.print("The value of the investment after "); 40 | System.out.print(years); 41 | System.out.print(" years is $"); 42 | System.out.printf("%1.2f", principal); 43 | System.out.println(); 44 | } // end of while loop 45 | 46 | } // end of main() 47 | 48 | } // end of class Interest3 49 | -------------------------------------------------------------------------------- /javanotes9/src-c3/ListLetters.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * This program reads a line of text entered by the user. 5 | * It prints a list of the letters that occur in the text, 6 | * and it reports how many different letters were found. 7 | */ 8 | 9 | public class ListLetters { 10 | 11 | public static void main(String[] args) { 12 | 13 | String str; // Line of text entered by the user. 14 | int count; // Number of different letters found in str. 15 | char letter; // A letter of the alphabet. 16 | 17 | System.out.println("Please type in a line of text."); 18 | str = TextIO.getln(); 19 | 20 | str = str.toUpperCase(); 21 | 22 | count = 0; 23 | System.out.println("Your input contains the following letters:"); 24 | System.out.println(); 25 | System.out.print(" "); 26 | for ( letter = 'A'; letter <= 'Z'; letter++ ) { 27 | int i; // Position of a character in str. 28 | for ( i = 0; i < str.length(); i++ ) { 29 | if ( letter == str.charAt(i) ) { 30 | System.out.print(letter); 31 | System.out.print(' '); 32 | count++; 33 | break; 34 | } 35 | } 36 | } 37 | 38 | System.out.println(); 39 | System.out.println(); 40 | System.out.println("There were " + count + " different letters."); 41 | 42 | } // end main() 43 | 44 | } // end class ListLetters 45 | -------------------------------------------------------------------------------- /javanotes9/src-c3/ReverseInputNumbers.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * Reads up to 100 integers from the user, then prints them 5 | * in reverse order. An input of zero marks the end of input. 6 | */ 7 | public class ReverseInputNumbers { 8 | 9 | public static void main(String[] args) { 10 | 11 | int[] numbers; // An array for storing the input values. 12 | int count; // The number of numbers saved in the array. 13 | int num; // One of the numbers input by the user. 14 | int i; // for-loop variable. 15 | 16 | numbers = new int[100]; // Space for 100 ints. 17 | count = 0; // No numbers have been saved yet. 18 | 19 | System.out.println("Enter up to 100 positive integers; enter 0 to end."); 20 | 21 | while (true) { // Get the numbers and put them in the array. 22 | System.out.print("? "); 23 | num = TextIO.getlnInt(); 24 | if (num <= 0) { 25 | // Zero marks the end of input; we have all the numbers. 26 | break; 27 | } 28 | numbers[count] = num; // Put num in position count. 29 | count++; // Count the number 30 | } 31 | 32 | System.out.println("\nYour numbers in reverse order are:\n"); 33 | 34 | for ( i = count - 1; i >= 0; i-- ) { 35 | System.out.println( numbers[i] ); 36 | } 37 | 38 | } // end main(); 39 | 40 | } // end class ReverseInputNumbers 41 | -------------------------------------------------------------------------------- /javanotes9/src-c3/ThreeN1.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * This program prints out a 3N+1 sequence starting from a positive 5 | * integer specified by the user. It also counts the number of 6 | * terms in the sequence, and prints out that number. 7 | */ 8 | public class ThreeN1 { 9 | 10 | public static void main(String[] args) { 11 | 12 | int N; // for computing terms in the sequence 13 | int counter; // for counting the terms 14 | 15 | System.out.print("Starting point for sequence: "); 16 | N = TextIO.getlnInt(); 17 | while (N <= 0) { 18 | System.out.print("The starting point must be positive. Please try again: "); 19 | N = TextIO.getlnInt(); 20 | } 21 | // At this point, we know that N > 0 22 | 23 | counter = 0; 24 | while (N != 1) { 25 | if (N % 2 == 0) 26 | N = N / 2; 27 | else 28 | N = 3 * N + 1; 29 | System.out.println(N); 30 | counter = counter + 1; 31 | } 32 | 33 | System.out.println(); 34 | System.out.print("There were "); 35 | System.out.print(counter); 36 | System.out.println(" terms in the sequence."); 37 | 38 | } // end of main() 39 | 40 | } // end of class ThreeN1 41 | -------------------------------------------------------------------------------- /javanotes9/src-c4/ArrayProcessor.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * A functional interface that defines a function 4 | * that has one parameter of type double[] and that 5 | * returns a value of type double. 6 | */ 7 | public interface ArrayProcessor { 8 | 9 | double apply( double[] array ); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /javanotes9/src-c4/CopyTextFile.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * Requires two command line arguments, which must be file names. The 5 | * the first must be the name of an existing file. The second is the name 6 | * of a file to be created by the program. The contents of the first file 7 | * are copied into the second. WARNING: If the second file already 8 | * exists when the program is run, its previous contents will be lost! 9 | * This program only works for plain text files. 10 | */ 11 | public class CopyTextFile { 12 | 13 | public static void main( String[] args ) { 14 | if (args.length < 2 ) { 15 | System.out.println("Two command-line arguments are required!"); 16 | System.exit(1); 17 | } 18 | TextIO.readFile( args[0] ); // Open the original file for reading. 19 | TextIO.writeFile( args[1] ); // Open the copy file for writing. 20 | int lineCount; // Number of lines copied 21 | lineCount = 0; 22 | while ( TextIO.eof() == false ) { 23 | // Read one line from the original file and write it to the copy. 24 | String line; 25 | line = TextIO.getln(); 26 | TextIO.putln(line); 27 | lineCount++; 28 | } 29 | System.out.printf( "%d lines copied from %s to %s%n", 30 | lineCount, args[0], args[1] ); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /javanotes9/src-c4/RowsOfChars.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * This program will get a line of input from the user. It will 5 | * then output one line for each character in the user's input. That 6 | * line will contain 25 copies of the character. 7 | * 8 | * This simple program is meant to demonstrate the use of subroutines, 9 | * and especially the case where one routine calls a subroutine 10 | * which then calls another subroutine. It is not a useful program. 11 | * 12 | * (Note: It doesn't matter in what order the subroutines are 13 | * listed in the class. A subroutine can always be used anywhere 14 | * in the class that defines it, even if the definition occurs 15 | * physically after the point where it is called.) 16 | */ 17 | public class RowsOfChars { 18 | 19 | public static void main(String[] args) { 20 | String inputLine; // Line of text input by user. 21 | TextIO.put("Enter a line of text: "); 22 | inputLine = TextIO.getln(); 23 | TextIO.putln(); 24 | printRowsFromString( inputLine ); 25 | } 26 | 27 | 28 | /** 29 | * For each character in str, write a line of output 30 | * containing 25 copies of that character. 31 | */ 32 | private static void printRowsFromString( String str ) { 33 | int i; // Loop-control variable for counting off the chars. 34 | for ( i = 0; i < str.length(); i++ ) { 35 | printRow( str.charAt(i), 25 ); 36 | } 37 | } 38 | 39 | 40 | /** 41 | * Write one line of output containing N copies of the 42 | * character ch. If N is less than or equal to 0, an empty line is output. 43 | */ 44 | private static void printRow( char ch, int N ) { 45 | int i; // Loop-control variable for counting off the copies. 46 | for ( i = 1; i <= N; i++ ) { 47 | System.out.print( ch ); 48 | } 49 | System.out.println(); 50 | } 51 | 52 | 53 | } //end of class RowsOfChars 54 | -------------------------------------------------------------------------------- /javanotes9/src-c5/BlackjackHand.java: -------------------------------------------------------------------------------- 1 | public class BlackjackHand extends Hand { 2 | 3 | /** 4 | * Computes and returns the value of this hand in the game 5 | * of Blackjack. 6 | */ 7 | public int getBlackjackValue() { 8 | 9 | int val; // The value computed for the hand. 10 | boolean ace; // This will be set to true if the 11 | // hand contains an ace. 12 | int cards; // Number of cards in the hand. 13 | 14 | val = 0; 15 | ace = false; 16 | cards = getCardCount(); // (method defined in class Hand.) 17 | 18 | for ( int i = 0; i < cards; i++ ) { 19 | // Add the value of the i-th card in the hand. 20 | Card card; // The i-th card; 21 | int cardVal; // The blackjack value of the i-th card. 22 | card = getCard(i); 23 | cardVal = card.getValue(); // The normal value, 1 to 13. 24 | if (cardVal > 10) { 25 | cardVal = 10; // For a Jack, Queen, or King. 26 | } 27 | if (cardVal == 1) { 28 | ace = true; // There is at least one ace. 29 | } 30 | val = val + cardVal; 31 | } 32 | 33 | // Now, val is the value of the hand, counting any ace as 1. 34 | // If there is an ace, and if changing its value from 1 to 35 | // 11 would leave the score less than or equal to 21, 36 | // then do so by adding the extra 10 points to val. 37 | 38 | if ( ace == true && val + 10 <= 21 ) 39 | val = val + 10; 40 | 41 | return val; 42 | 43 | } // end getBlackjackValue() 44 | 45 | } // end class BlackjackHand 46 | -------------------------------------------------------------------------------- /javanotes9/src-c5/CircleInfo.java: -------------------------------------------------------------------------------- 1 | import javafx.scene.paint.Color; 2 | import javafx.scene.canvas.GraphicsContext; 3 | 4 | /** 5 | * A simple class that holds the size, color, and location of a colored disk, 6 | * with a method for drawing the circle in a graphics context. The circle 7 | * is drawn as a filled oval, with a black outline. 8 | */ 9 | public class CircleInfo { 10 | 11 | public int radius; // The radius of the circle. 12 | public int x,y; // The location of the center of the circle. 13 | public Color color; // The color of the circle. 14 | 15 | /** 16 | * Create a CircleInfo with a given location and radius and with a 17 | * randomly selected, semi-transparent color. 18 | * @param centerX The x coordinate of the center. 19 | * @param centerY The y coordinate of the center. 20 | * @param rad The radius of the circle. 21 | */ 22 | public CircleInfo( int centerX, int centerY, int rad ) { 23 | x = centerX; 24 | y = centerY; 25 | radius = rad; 26 | double red = Math.random(); 27 | double green = Math.random(); 28 | double blue = Math.random(); 29 | color = new Color(red,green,blue, 0.4); 30 | } 31 | 32 | /** 33 | * Draw the disk in graphics context g, with a black outline. 34 | */ 35 | public void draw( GraphicsContext g ) { 36 | g.setFill( color ); 37 | g.fillOval( x - radius, y - radius, 2*radius, 2*radius ); 38 | g.setStroke( Color.BLACK ); 39 | g.strokeOval( x - radius, y - radius, 2*radius, 2*radius ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /javanotes9/src-c5/PairOfDice.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A PairOfDice object represents an ordinary pair of six-sided dice. 3 | */ 4 | public class PairOfDice { 5 | 6 | public int die1; // Number showing on the first die. 7 | public int die2; // Number showing on the second die. 8 | 9 | public PairOfDice() { 10 | // Constructor. Rolls the dice, so that they initially 11 | // show some random values. 12 | roll(); // Call the roll() method to roll the dice. 13 | } 14 | 15 | public PairOfDice(int val1, int val2) { 16 | // Constructor. Creates a pair of dice that 17 | // are initially showing the values val1 and val2. 18 | die1 = val1; // Assign specified values 19 | die2 = val2; // to the instance variables. 20 | } 21 | 22 | public void roll() { 23 | // Roll the dice by setting each of the dice to be 24 | // a random number between 1 and 6. 25 | die1 = (int)(Math.random()*6) + 1; 26 | die2 = (int)(Math.random()*6) + 1; 27 | } 28 | 29 | } // end class PairOfDice 30 | -------------------------------------------------------------------------------- /javanotes9/src-c5/RollTwoPairs.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * This program creates two PairOfDice objects and rolls them over and over 4 | * until the totals on the two pairs are the same. It reports how many 5 | * times the dice were rolled. 6 | */ 7 | public class RollTwoPairs { 8 | 9 | public static void main(String[] args) { 10 | 11 | PairOfDice firstDice; // Refers to the first pair of dice. 12 | firstDice = new PairOfDice(); 13 | 14 | PairOfDice secondDice; // Refers to the second pair of dice. 15 | secondDice = new PairOfDice(); 16 | 17 | int countRolls; // Counts how many times the two pairs of 18 | // dice have been rolled. 19 | 20 | int total1; // Total showing on first pair of dice. 21 | int total2; // Total showing on second pair of dice. 22 | 23 | countRolls = 0; 24 | 25 | do { // Roll the two pairs of dice until totals are the same. 26 | 27 | firstDice.roll(); // Roll the first pair of dice. 28 | total1 = firstDice.die1 + firstDice.die2; // Get total. 29 | System.out.println("First pair comes up " + total1); 30 | 31 | secondDice.roll(); // Roll the second pair of dice. 32 | total2 = secondDice.die1 + secondDice.die2; // Get total. 33 | System.out.println("Second pair comes up " + total2); 34 | 35 | countRolls++; // Count this roll. 36 | 37 | System.out.println(); // Blank line. 38 | 39 | } while (total1 != total2); 40 | 41 | System.out.println("It took " + countRolls 42 | + " rolls until the totals were the same."); 43 | 44 | } // end main() 45 | 46 | } // end class RollTwoPairs 47 | -------------------------------------------------------------------------------- /javanotes9/src-c5/StatCalc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * An object of class StatCalc can be used to compute several simple statistics 3 | * for a set of numbers. Numbers are entered into the dataset using 4 | * the enter(double) method. Methods are provided to return the following 5 | * statistics for the set of numbers that have been entered: The number 6 | * of items, the sum of the items, the average, and the standard deviation 7 | */ 8 | 9 | public class StatCalc { 10 | 11 | private int count; // Number of numbers that have been entered. 12 | private double sum; // The sum of all the items that have been entered. 13 | private double squareSum; // The sum of the squares of all the items. 14 | 15 | /** 16 | * Add a number to the dataset. The statistics will be computed for all 17 | * the numbers that have been added to the dataset using this method. 18 | */ 19 | public void enter(double num) { 20 | count++; 21 | sum += num; 22 | squareSum += num*num; 23 | } 24 | 25 | /** 26 | * Return the number of items that have been entered into the dataset. 27 | */ 28 | public int getCount() { 29 | return count; 30 | } 31 | 32 | /** 33 | * Return the sum of all the numbers that have been entered. 34 | */ 35 | public double getSum() { 36 | return sum; 37 | } 38 | 39 | /** 40 | * Return the average of all the items that have been entered. 41 | * The return value is Double.NaN if no numbers have been entered. 42 | */ 43 | public double getMean() { 44 | return sum / count; 45 | } 46 | 47 | /** 48 | * Return the standard deviation of all the items that have been entered. 49 | * The return value is Double.NaN if no numbers have been entered. 50 | */ 51 | public double getStandardDeviation() { 52 | double mean = getMean(); 53 | return Math.sqrt( squareSum/count - mean*mean ); 54 | } 55 | 56 | } // end class StatCalc 57 | -------------------------------------------------------------------------------- /javanotes9/src-c6/HelloWorldFX.java: -------------------------------------------------------------------------------- 1 | import javafx.application.Application; 2 | import javafx.scene.Scene; 3 | import javafx.stage.Stage; 4 | import javafx.application.Platform; 5 | import javafx.scene.layout.BorderPane; 6 | import javafx.scene.layout.HBox; 7 | import javafx.geometry.Pos; 8 | import javafx.scene.control.Label; 9 | import javafx.scene.control.Button; 10 | import javafx.scene.text.Font; 11 | 12 | public class HelloWorldFX extends Application { 13 | 14 | public void start(Stage stage) { 15 | 16 | Label message = new Label("First FX Application!"); 17 | message.setFont( new Font(40) ); 18 | 19 | Button helloButton = new Button("Say Hello"); 20 | helloButton.setOnAction( evt -> message.setText("Hello World!") ); 21 | Button goodbyeButton = new Button("Say Goodbye"); 22 | goodbyeButton.setOnAction( evt -> message.setText("Goodbye!!") ); 23 | Button quitButton = new Button("Quit"); 24 | quitButton.setOnAction( evt -> Platform.exit() ); 25 | 26 | HBox buttonBar = new HBox( 20, helloButton, goodbyeButton, quitButton ); 27 | buttonBar.setAlignment(Pos.CENTER); 28 | BorderPane root = new BorderPane(); 29 | root.setCenter(message); 30 | root.setBottom(buttonBar); 31 | 32 | Scene scene = new Scene(root, 450, 200); 33 | stage.setScene(scene); 34 | stage.setTitle("JavaFX Test"); 35 | stage.show(); 36 | 37 | } // end start(); 38 | 39 | public static void main(String[] args) { 40 | launch(); // Run this Application. 41 | } 42 | 43 | } // end class HelloWorldFX -------------------------------------------------------------------------------- /javanotes9/src-c6/cards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidjeck/javanotes9/6a36faf886c5ffa32a06fb0d416946801ac9b225/javanotes9/src-c6/cards.png -------------------------------------------------------------------------------- /javanotes9/src-c7/Complex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A record type for representing complex numbers, where 3 | * a complex number consists of two real numbers called its 4 | * real and imaginary parts. The class includes methods for 5 | * doing arithmetic with complex numbers. 6 | */ 7 | public record Complex(double re, double im) { 8 | 9 | // Some named constants for common complex numbers. 10 | 11 | public final static Complex ONE = new Complex(1,0); 12 | public final static Complex ZERO = new Complex(0,0); 13 | public final static Complex I = new Complex(0,1); 14 | 15 | /** 16 | * This constructor creates a complex number with a given 17 | * real part and with imaginary part zero. 18 | */ 19 | public Complex(double re) { 20 | this(re,0); 21 | } 22 | 23 | /** 24 | * Creates string representations of complex number such 25 | * as: 3.0 + I*5.0, -I*3.14, 2.7 - I*8.6, 3.14 26 | */ 27 | public String toString() { 28 | if (im == 0) 29 | return String.valueOf(re); 30 | else if (re == 0) { 31 | if (im < 0) 32 | return "-I*" + (-im); 33 | else 34 | return "I*" + im; 35 | } 36 | else if (im < 0) 37 | return re + " - " + "I*" + (-im); 38 | else 39 | return re + " + " + "I*" + im; 40 | } 41 | 42 | // Some methods for doing arithmetic on two complex numbers 43 | 44 | public Complex plus(Complex c) { 45 | return new Complex(re + c.re, im + c.im); 46 | } 47 | public Complex minus(Complex c) { 48 | return new Complex(re - c.re, im - c.im); 49 | } 50 | public Complex times(Complex c) { 51 | return new Complex(re*c.re - im*c.im, 52 | re*c.im + im*c.re); 53 | } 54 | public Complex dividedBy(Complex c) { 55 | double denom = c.re*c.re + c.im*c.im; 56 | double real = (re*c.re + im*c.im)/denom; 57 | double imaginary = (im*c.re - re*c.im)/denom; 58 | return new Complex(real,imaginary); 59 | } 60 | 61 | } // end record Complex 62 | 63 | -------------------------------------------------------------------------------- /javanotes9/src-c7/DynamicArrayOfInt.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | /** 4 | * Represents a list of int values that can grow and shrink. 5 | */ 6 | public class DynamicArrayOfInt { 7 | 8 | private int[] items = new int[8]; // partially full array holding the ints 9 | private int itemCt; 10 | 11 | /** 12 | * Return the item at a given index in the array. 13 | * Throws ArrayIndexOutOfBoundsException if the index is not valid. 14 | */ 15 | public int get( int index ) { 16 | if ( index < 0 || index >= itemCt ) 17 | throw new ArrayIndexOutOfBoundsException("Illegal index, " + index); 18 | return items[index]; 19 | } 20 | 21 | /** 22 | * Set the value of the array element at a given index. 23 | * Throws ArrayIndexOutOfBoundsException if the index is not valid. 24 | */ 25 | public void set( int index, int item ) { 26 | if ( index < 0 || index >= itemCt ) 27 | throw new ArrayIndexOutOfBoundsException("Illegal index, " + index); 28 | items[index] = item; 29 | } 30 | 31 | /** 32 | * Returns the number of items currently in the array. 33 | */ 34 | public int size() { 35 | return itemCt; 36 | } 37 | 38 | /** 39 | * Adds a new item to the end of the array. The size increases by one. 40 | */ 41 | public void add(int item) { 42 | if (itemCt == items.length) 43 | items = Arrays.copyOf( items, 2*items.length ); 44 | items[itemCt] = item; 45 | itemCt++; 46 | } 47 | 48 | /** 49 | * Removes the item at a given index in the array. The size of the array 50 | * decreases by one. Items following the removed item are moved down 51 | * one space in the array. 52 | * Throws ArrayIndexOutOfBoundsException if the index is not valid. 53 | */ 54 | public void remove(int index) { 55 | if ( index < 0 || index >= itemCt ) 56 | throw new ArrayIndexOutOfBoundsException("Illegal index, " + index); 57 | for (int j = index+1; j < itemCt; j++) 58 | items[j-1] = items[j]; 59 | itemCt--; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /javanotes9/src-c7/FullName.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * A record class for representing names. A name consists of a 4 | * first name and a last name. However, to accommodate people 5 | * who use only one name, the last name can be null. 6 | */ 7 | public record FullName(String firstName, String lastName) { 8 | 9 | /** 10 | * Canonical constructor takes two parameters representing 11 | * the first name and the last name. The last name can be 12 | * null, but if the first name is null an IllegalArgumentException 13 | * will be thrown. 14 | */ 15 | public FullName { 16 | if (firstName == null) { 17 | throw new IllegalArgumentException("First name can't be null."); 18 | } 19 | } 20 | 21 | /** 22 | * Constructor for creating a FullName for a person who uses 23 | * only one name. The parameter represents that name, which 24 | * becomes the firstName field of the FullName. The lastName 25 | * field is null. 26 | */ 27 | public FullName(String name) { 28 | this(name,null); 29 | } 30 | 31 | /** 32 | * For a person who uses only one name, returns that name. 33 | * Otherwise, returns a string containing the first name 34 | * and the last name, separated by a space. 35 | */ 36 | public String toString() { 37 | if (lastName == null) 38 | return firstName; 39 | else 40 | return firstName + " " + lastName; 41 | } 42 | 43 | /** 44 | * Returns true if this FullName is the name of a person 45 | * who uses only one name. 46 | */ 47 | public boolean oneNameOnly() { 48 | return lastName == null; 49 | } 50 | 51 | } // end record FullName 52 | 53 | -------------------------------------------------------------------------------- /javanotes9/src-c7/ReverseWithArrayList.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | import java.util.ArrayList; 3 | 4 | /** 5 | * Reads a list of non-zero numbers for the user, then prints 6 | * out the input numbers in the reverse of the order in which 7 | * they were entered. there is no limit on the number of inputs. 8 | */ 9 | public class ReverseWithArrayList { 10 | 11 | public static void main(String[] args) { 12 | ArrayList list; 13 | list = new ArrayList(); 14 | System.out.println("Enter some non-zero integers. Enter 0 to end."); 15 | while (true) { 16 | System.out.print("? "); 17 | int number = TextIO.getlnInt(); 18 | if (number == 0) 19 | break; 20 | list.add(number); 21 | } 22 | System.out.println(); 23 | System.out.println("Your numbers in reverse are:"); 24 | for (int i = list.size() - 1; i >= 0; i--) { 25 | System.out.printf("%10d%n", list.get(i)); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /javanotes9/src-c7/ReverseWithDynamicArray.java: -------------------------------------------------------------------------------- 1 | import textio.TextIO; 2 | 3 | /** 4 | * Reads a list of non-zero numbers from the user, then prints 5 | * out the input numbers in the reverse of the order in which 6 | * they were entered. There is no limit on the number of inputs. 7 | */ 8 | public class ReverseWithDynamicArray { 9 | 10 | public static void main(String[] args) { 11 | DynamicArrayOfInt list; 12 | list = new DynamicArrayOfInt(); 13 | System.out.println("Enter some non-zero integers. Enter 0 to end."); 14 | while (true) { 15 | System.out.print("? "); 16 | int number = TextIO.getlnInt(); 17 | if (number == 0) 18 | break; 19 | list.add(number); 20 | } 21 | System.out.println(); 22 | System.out.println("Your numbers in reverse are:"); 23 | for (int i = list.size() - 1; i >= 0; i--) { 24 | System.out.printf("%10d%n", list.get(i)); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /javanotes9/src-c7/SymmetricMatrix.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Represents symmetric n-by-n matrices of real numbers. 4 | */ 5 | public class SymmetricMatrix { 6 | 7 | private double[][] matrix; // A triangular matrix to hold the data. 8 | 9 | /** 10 | * Creates an n-by-n symmetric matrix in which all entries are 0. 11 | */ 12 | public SymmetricMatrix(int n) { 13 | matrix = new double[n][]; 14 | for (int i = 0; i < n; i++) 15 | matrix[i] = new double[i+1]; 16 | } 17 | 18 | /** 19 | * Returns the matrix entry at position (row,col). (If row < col, 20 | * the value is actually stored at position (col,row).) 21 | */ 22 | public double get( int row, int col ) { 23 | if (row >= col) 24 | return matrix[row][col]; 25 | else 26 | return matrix[col][row]; 27 | } 28 | 29 | /** 30 | * Sets the value of the matrix entry at (row,col). (If row < col, 31 | * the value is actually stored at position (col,row).) 32 | */ 33 | public void set( int row, int col, double value ) { 34 | if (row >= col) 35 | matrix[row][col] = value; 36 | else 37 | matrix[col][row] = value; 38 | } 39 | 40 | /** 41 | * Returns the number of rows and columns in the matrix. 42 | */ 43 | public int size() { 44 | return matrix.length; // The size is the number of rows. 45 | } 46 | 47 | } // end class SymmetricMatrix 48 | -------------------------------------------------------------------------------- /javanotes9/src-c9/StackOfDouble.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * An object of type StackOfDouble is a stack of real numbers, with the 4 | * standard stack operations push(double N), pop(), and isEmpty(). 5 | * Internally, the stack is implemented as a linked list. 6 | */ 7 | public class StackOfDouble { 8 | 9 | 10 | /** 11 | * An object of type Node holds one of the items on the stack. 12 | */ 13 | private static class Node { 14 | double item; // One of the items in the list 15 | Node next; // Pointer to the node that holds the next item. 16 | } 17 | 18 | 19 | private Node top; // Pointer to the Node that is at the top of the stack. 20 | // If top == null, then the stack is empty. 21 | 22 | /** 23 | * Add N to the top of the stack. 24 | */ 25 | public void push( double N ) { 26 | Node newTop = new Node(); 27 | newTop.item = N; 28 | newTop.next = top; 29 | top = newTop; 30 | } 31 | 32 | /** 33 | * Remove the top item from the stack, and return it. 34 | * @return the item that was removed from the top of the stack 35 | * @throws IllegalStateException if the stack is empty when method is called. 36 | */ 37 | public double pop() { 38 | if ( top == null ) 39 | throw new IllegalStateException(); 40 | double topItem = top.item; 41 | top = top.next; 42 | return topItem; 43 | } 44 | 45 | 46 | /** 47 | * Returns true if the stack is empty. Returns false 48 | * if there are one or more items on the stack. 49 | */ 50 | public boolean isEmpty() { 51 | return top == null; 52 | } 53 | 54 | 55 | } // end class StackOfDouble 56 | 57 | -------------------------------------------------------------------------------- /javanotes9/src-c9/StackOfInt.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * An object of type StackOfInt is a stack of integerss, with the 4 | * standard stack operations push(int N), pop(), and isEmpty(). 5 | * Internally, the stack is implemented as a linked list. 6 | */ 7 | public class StackOfInt { 8 | 9 | 10 | /** 11 | * An object of type Node holds one of the items on the stack. 12 | */ 13 | private record Node ( 14 | int item, // One of the items in the list 15 | Node next // Pointer to the node that holds the next item. 16 | ) { } 17 | 18 | 19 | private Node top; // Pointer to the Node that is at the top of the stack. 20 | // If top == null, then the stack is empty. 21 | 22 | /** 23 | * Add N to the top of the stack. 24 | */ 25 | public void push( int N ) { 26 | Node newTop = new Node( N, top ); 27 | top = newTop; 28 | } 29 | 30 | /** 31 | * Remove the top item from the stack, and return it. 32 | * @return the item that was removed from the top of the stack 33 | * @throws IllegalStateException if the stack is empty when method is called. 34 | */ 35 | public int pop() { 36 | if ( top == null ) 37 | throw new IllegalStateException(); 38 | int topItem = top.item; 39 | top = top.next; 40 | return topItem; 41 | } 42 | 43 | 44 | /** 45 | * Returns true if the stack is empty. Returns false 46 | * if there are one or more items on the stack. 47 | */ 48 | public boolean isEmpty() { 49 | return top == null; 50 | } 51 | 52 | 53 | } // end class StackOfInt 54 | 55 | -------------------------------------------------------------------------------- /javanotes9/src-c9/TowersOfHanoi.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * This program lists the steps in the solution of the TowersOfHanoi 5 | * problem. The number of disks to be moved is specified by the user. 6 | * Warning: The number of moves grows very quickly with the number of 7 | * disks! 8 | */ 9 | public class TowersOfHanoi { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner in = new Scanner(System.in); 14 | 15 | int N; // The number of disks in the original stack, 16 | // as specified by the user. 17 | 18 | System.out.println("This program will list the steps in the solution of"); 19 | System.out.println("the Towers of Hanoi problem. You can specify the"); 20 | System.out.println("number of disks to be moved. Try it for small numbers"); 21 | System.out.println("of disks, like 1, 2, 3, and 4."); 22 | System.out.println(); 23 | System.out.println("How many disks are to be moved from Stack 0 to Stack 1?"); 24 | System.out.println(); 25 | System.out.print("? "); 26 | 27 | N = in.nextInt(); 28 | 29 | System.out.println(); 30 | System.out.println(); 31 | 32 | towersOfHanoi(N, 0, 1, 2); // Print the solution. 33 | 34 | } 35 | 36 | /** 37 | * Solve the problem of moving the number of disks specified 38 | * by the first parameter from the stack specified by the 39 | * second parameter to the stack specified by the third 40 | * parameter. The stack specified by the fourth parameter 41 | * is available for use as a spare. Stacks are specified by 42 | * number: 0, 1, or 2. 43 | */ 44 | static void towersOfHanoi(int disks, int from, int to, int spare) { 45 | if (disks == 1) { 46 | // There is only one disk to be moved. Just move it. 47 | System.out.printf("Move disk 1 from stack %d to stack %d%n", 48 | from, to); 49 | } 50 | else { 51 | // Move all but one disk to the spare stack, then 52 | // move the bottom disk, then put all the other 53 | // disks on top of it. 54 | towersOfHanoi(disks-1, from, spare, to); 55 | System.out.printf("Move disk %d from stack %d to stack %d%n", 56 | disks, from, to); 57 | towersOfHanoi(disks-1, spare, to, from); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /javanotes9/src-textio/textiogui/System.java: -------------------------------------------------------------------------------- 1 | package textiogui; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.BufferedReader; 5 | 6 | /** 7 | * This is a "fake" System class, for use with the GUI version of 8 | * TextIO. It provides only a few of the capabilities of 9 | * java.lang.System. Note that for this class, System.out 10 | * and System.err are PrintWriters, and System.in is a BufferedReader. 11 | * A few subroutines are provided as simple wrappers for the 12 | * real System class. 13 | */ 14 | public class System { 15 | 16 | public static PrintWriter err = TextIO.getOut(); 17 | public static PrintWriter out = err; 18 | public static BufferedReader in = TextIO.getIn(); 19 | 20 | public static long currentTimeMillis() { 21 | return java.lang.System.currentTimeMillis(); 22 | } 23 | 24 | public static long nanoTime() { 25 | return java.lang.System.nanoTime(); 26 | } 27 | 28 | public static void exit(int code) { 29 | java.lang.System.exit(code); 30 | } 31 | 32 | public static String getProperty(String name) { 33 | return java.lang.System.getProperty(name); 34 | } 35 | 36 | public static String getProperty(String name, String def) { 37 | return java.lang.System.getProperty(name, def); 38 | } 39 | 40 | public static String lineSeparator() { 41 | return java.lang.System.lineSeparator(); 42 | } 43 | 44 | // Returns null, which will cause a NullPointerException if 45 | // an attempt is made to use the console. This is actually 46 | // correct behavior since the GUI version of TextIO is not 47 | // a proper console. 48 | public static java.io.Console console() { 49 | return null; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /javanotes9/textio-for-windows-jar-files/README.txt: -------------------------------------------------------------------------------- 1 | This folder contains the versions of System.java and TextIO.java 2 | that are used in the Windows script make-jar-files.sh for building 3 | jar files for all of the example programs. These are the same 4 | files that are found in textiogui, but modified to be in package 5 | textio instead of in package textiogui. They should not be used 6 | for any purpose other than with make-jar-files.sh on a Windows 7 | platform. 8 | -------------------------------------------------------------------------------- /javanotes9/textio-for-windows-jar-files/System.java: -------------------------------------------------------------------------------- 1 | package textio; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.BufferedReader; 5 | 6 | /** 7 | * This is a "fake" System class, for use with the GUI version of 8 | * TextIO. It provides only a few of the capabilities of 9 | * java.lang.System. Note that for this class, System.out 10 | * and System.err are PrintWriters, and System.in is a BufferedReader. 11 | * A few subroutines are provided as simple wrappers for the 12 | * real System class. 13 | */ 14 | public class System { 15 | 16 | public static PrintWriter err = TextIO.getOut(); 17 | public static PrintWriter out = err; 18 | public static BufferedReader in = TextIO.getIn(); 19 | 20 | public static long currentTimeMillis() { 21 | return java.lang.System.currentTimeMillis(); 22 | } 23 | 24 | public static long nanoTime() { 25 | return java.lang.System.nanoTime(); 26 | } 27 | 28 | public static void exit(int code) { 29 | java.lang.System.exit(code); 30 | } 31 | 32 | public static String getProperty(String name) { 33 | return java.lang.System.getProperty(name); 34 | } 35 | 36 | public static String getProperty(String name, String def) { 37 | return java.lang.System.getProperty(name, def); 38 | } 39 | 40 | public static String lineSeparator() { 41 | return java.lang.System.lineSeparator(); 42 | } 43 | 44 | // Returns null, which will cause a NullPointerException if 45 | // an attempt is made to use the console. This is actually 46 | // correct behavior since the GUI version of TextIO is not 47 | // a proper console. 48 | public static java.io.Console console() { 49 | return null; 50 | } 51 | 52 | } 53 | --------------------------------------------------------------------------------