{"id":10592,"date":"2014-11-14T05:04:20","date_gmt":"2014-11-13T18:04:20","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10592"},"modified":"2014-11-14T05:04:20","modified_gmt":"2014-11-13T18:04:20","slug":"java-swing-line-graph-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/java-swing-line-graph-primer-tutorial\/","title":{"rendered":"Java Swing Line Graph Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/LineGraph\/LineGraph.jpg\"><img decoding=\"async\" id='xmximgjoptionpane'  style=\"float:left; border: 15px solid pink;\" alt=\"Java Swing Line Graph Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/LineGraph\/LineGraph.jpg\" title=\"Java Swing Line Graph Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Java Swing Line Graph Primer Tutorial<\/p><\/div>\n<p>Sort of miss Java Applets, myself, as they were once <i>&#8220;the thing&#8221;<\/i> for some people writing code for the web.  You got used to <i>paint()<\/i> and <i>repaint()<\/i> methods because you could imagine, word for word, codewise, what was happening.<\/p>\n<p>So here is another tutorial that uses <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Swing<\/a> functionality in Java to create a GUI (Graphical User Interface) desktop program on a Mac laptop (but same code may well work, compiled on a Windows laptop (the same way)) that harkens back to those Java Applet ideas drawing graphics (we even use <i>&#8220;repaint()&#8221;<\/i> &#8230; yay) that is a simple Java <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html'>JFrame<\/a> object, graphics for a Line Graph, accepting co-ordinate input from the (Linux) command line arguments or taking this interactively via the <a target=_blank title='Java Swing JOptionPane information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JOptionPane.html'>JOptionPane<\/a> showInputDialog() method, and then, optionally, later you can add to your Line Graph via mouse clicks understood as vertices of the one continuous line you are creating &#8230; in other words, not scribble, that would require different logic, but not that much more difficult or involved logic actually &#8230; would just involve some intervention with the <i>onmousemove<\/i> event function.<\/p>\n<p>Some of the points of interest, and you may want to see our previous relevant <a target=_blank href='#jsjptx' title='Java Swing JTree Primer Tutorial'>Java Swing JTree Primer Tutorial<\/a> as shown below, as well, are:<\/p>\n<ul>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html'>JFrame<\/a> GUI framework<\/li>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JPanel information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JPanel.html'>JPanel<\/a> GUI object<\/li>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JOptionPane information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JOptionPane.html'>JOptionPane<\/a> showInputDialog() method to obtain the interactive input required<\/li>\n<li>It <i>implements<\/i> Mouse event functionality via MouseListener<\/li>\n<li>It uses a kludgy-feeling approach to drawLine() work by drawing the one line with five drawLine() calls to give the impression of a thicker line<\/li>\n<\/ul>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/LineGraph\/LineChart.java_GETME' title='LineChart.java'>LineChart.java<\/a> that has the very simple command line compilation procedure:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javac LineChart.java<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java LineChart<\/p>\n<p>Of great help was this <a target=_blank href='http:\/\/stackoverflow.com\/questions\/21347758\/how-to-draw-vertical-line-in-swing' title='Of great help ... thanks'>link<\/a> and this <a target=_blank title='MouseListener useful code ... thanks' href='https:\/\/docs.oracle.com\/javase\/tutorial\/displayCode.html?code=https:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/examples\/events\/MouseEventDemoProject\/src\/events\/MouseEventDemo.java'>link<\/a> &#8230; and the general idea and code ideas also came from <i>Developing Java Entertainment Applets<\/i> by <i>John Withers<\/i> &#8230; thanks <a target=_blank title='heaps' href='https:\/\/www.google.com.au\/search?q=heaps&#038;client=firefox-a&#038;hs=f2V&#038;rls=org.mozilla:en-US:official&#038;channel=sb&#038;source=lnms&#038;tbm=isch&#038;sa=X&#038;ei=hZssVNHZGsieoQSvjIGoCw&#038;ved=0CAgQ_AUoAQ&#038;biw=1280&#038;bih=657#facrc=_&#038;imgdii=_&#038;imgrc=7I9wlk4AuzNoKM%253A%3BBIAUc_imBfLspM%3Bhttp%253A%252F%252Fwww.travelling-australia.info%252FJournal2009%252FGraphics%252FP096060052Bz-500.jpg%3Bhttp%253A%252F%252Fwww.travelling-australia.info%252FJournal2009%252F06JunA.html%3B500%3B334'>heaps<\/a>.<\/p>\n<hr \/>\n<p id='jsjptx'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10209' title='Java Swing JTree Primer Tutorial'>Java Swing JTree Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/TreeUsage.jpg\"><img decoding=\"async\" id='xmximgjoptionpane'  style=\"float:left; border: 15px solid pink;\" alt=\"Java Swing JTree Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/TreeUsage.jpg\" title=\"Java Swing Desktop Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Java Swing JTree Primer Tutorial<\/p><\/div>\n<p>Here is another tutorial that uses <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Swing<\/a> functionality in Java to create a GUI (Graphical User Interface) desktop program on a Mac laptop (but same code may well work, compiled on a Windows laptop (the same way)) that tests the use of a simple Java <a target=_blank title='Java Swing JTree object information from Oracle' href='http:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/components\/tree.html'>JTree<\/a> object, adding to the thought processes, perhaps, of the previous <a target=_blank href='#jsspt' title='Java Swing Sound Primer Tutorial'>Java Swing Sound Primer Tutorial<\/a> as shown below.<\/p>\n<p>Some of the points of interest, and you may want to see our previous relevant <a target=_blank href='#jsdpt' title='Java Swing Desktop Primer Tutorial'>Java Swing Desktop Primer Tutorial<\/a> as shown below, as well, are:<\/p>\n<ul>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html'>JFrame<\/a> GUI framework<\/li>\n<p><script type='text\/javascript'>\nfunction inten() {\nvar myo=document.getElementById(\"myodiv\");\nvar mydd=new Date();\nif (myo.innerHTML.indexOf('myifis2') == -1) {\nmyo.innerHTML=myo.innerHTML + '<iframe id=myifis2 height=450 src=http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/Nala_Catch.mov?x=x><\/iframe>';\n} else {\nmyo=document.getElementById(\"myifis2\");\nmyo.src=myo.src.replace(\"=\", \"=\" + mydd);\n}\n}\n<\/script><\/p>\n<li>It uses a private JTree object in which to store the hierarchical data &#8230; in our case the lineage (up to 5 generations) of <a target=_blank title=\"Falleur's Nelson\" href=\"http:\/\/www.k9data.com\/fivegen.asp?ID=255293\">Falleur&#8217;s Nelson<\/a> the Golden Retriever &#8230; yes, <a id=myais target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/Nala_HideAndSeek.m4v\" title='Dog field events: 1) hide and seek, 2) catch' onclick='  window.open( \"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/Nala_Catch.m4v\",\"_blank\");   ' onmouseover=' setTimeout(inten,10000);  var myd=new Date(); document.getElementById(\"myodiv\").style.display=\"block\";   document.getElementById(\"myifis1\").src=document.getElementById(\"myifis1\").src.replace(\"=\", \"=\" + myd);  '>dog<\/a>\n<div id='myodiv' style='display:none;margin-top:12px;'><iframe id=myifis1 height=450 src=http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/Nala_HideAndSeek.mov?x=x><\/iframe>&nbsp;<\/div>\n<\/li>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JOptionPane information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JOptionPane.html'>JOptionPane<\/a> showInputDialog() method to obtain the interactive input required<\/li>\n<\/ul>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JTree\/TreeUsage.java_GETME' title='TreeUsage.java'>TreeUsage.java<\/a> that has the very simple command line compilation procedure:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javac TreeUsage.java<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java TreeUsage<\/p>\n<p>Of great help was this <a target=_blank href='http:\/\/www.codejava.net\/java-se\/swing\/jtree-basic-tutorial-and-examples' title='Of great help ... thanks'>link<\/a> &#8230; thanks <a target=_blank title='heaps' href='https:\/\/www.google.com.au\/search?q=heaps&#038;client=firefox-a&#038;hs=f2V&#038;rls=org.mozilla:en-US:official&#038;channel=sb&#038;source=lnms&#038;tbm=isch&#038;sa=X&#038;ei=hZssVNHZGsieoQSvjIGoCw&#038;ved=0CAgQ_AUoAQ&#038;biw=1280&#038;bih=657#facrc=_&#038;imgdii=_&#038;imgrc=7I9wlk4AuzNoKM%253A%3BBIAUc_imBfLspM%3Bhttp%253A%252F%252Fwww.travelling-australia.info%252FJournal2009%252FGraphics%252FP096060052Bz-500.jpg%3Bhttp%253A%252F%252Fwww.travelling-australia.info%252FJournal2009%252F06JunA.html%3B500%3B334'>heaps<\/a>.<\/p>\n<hr \/>\n<p id=\"jsdpt\">Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9924' title='Java Swing Desktop Primer Tutorial'>Java Swing Desktop Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JDeskTop\/JDeskTop.jpg\"><img decoding=\"async\" id='xmximgjoptionpane'  style=\"float:left; border: 15px solid pink;\" alt=\"Java Swing Desktop Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JDeskTop\/JDeskTop.jpg\" title=\"Java Swing Desktop Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Java Swing Desktop Primer Tutorial<\/p><\/div>\n<p>Here is another tutorial that uses <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Swing<\/a> functionality in Java to create a GUI (Graphical User Interface) desktop program on a Mac laptop (but same code may well work, compiled on a Windows laptop (the same way)) that tests the use of a Java programmatical desktop environment allowing a button <a target=_blank href='http:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/events\/actionlistener.html'><i>ActionListener<\/i><\/a> event to control when it adds another internal frame to its programmatic desktop environment, adding to the thought processes, perhaps, of the previous <a target=_blank href='#jsspt' title='Java Swing Sound Primer Tutorial'>Java Swing Sound Primer Tutorial<\/a> as shown below.<\/p>\n<p>Some of the points of interest, and you may want to see our previous relevant <a target=_blank href='#jsakpt' title='Java Swing ActionListener KeyListener Primer Tutorial'>Java Swing ActionListener KeyListener Primer Tutorial<\/a> as shown below, as well, are:<\/p>\n<ul>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html'>JFrame<\/a> GUI framework, with original ideas coming from <i>Introduction to Java 2<\/i> Training Manual for WEA Sydney by Phil Cogar <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JDeskTop\/JDeskTop.jpg\" title='Click picture'>today<\/a><\/li>\n<li>It <i>implements<\/i> Mouse event functionality via ActionListener<\/li>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JButton information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JButton.html'>JButton<\/a> and <a target=_blank title='Java Swing JButton information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JDesktopPane.html'>JDesktopPane<\/a> and <a target=_blank title='Java Swing JButton information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JInternalFrame.html'>JInternalFrame<\/a> GUI objects<\/li>\n<\/ul>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JDeskTop\/JDeskTop.java_GETME' title='JDeskTop.java'>JDeskTop.java<\/a> that has the very simple command line compilation procedure:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javac JDeskTop.java<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java JDeskTop<\/p>\n<p>Of great help was this <a target=_blank href='http:\/\/stackoverflow.com\/questions\/7218971\/java-method-works-on-windows-but-not-macintosh' title='Of great help ... thanks'>link<\/a> &#8230; thanks <a target=_blank title='heaps' href='https:\/\/www.google.com.au\/search?q=heaps&#038;client=firefox-a&#038;hs=f2V&#038;rls=org.mozilla:en-US:official&#038;channel=sb&#038;source=lnms&#038;tbm=isch&#038;sa=X&#038;ei=hZssVNHZGsieoQSvjIGoCw&#038;ved=0CAgQ_AUoAQ&#038;biw=1280&#038;bih=657#facrc=_&#038;imgdii=_&#038;imgrc=7I9wlk4AuzNoKM%253A%3BBIAUc_imBfLspM%3Bhttp%253A%252F%252Fwww.travelling-australia.info%252FJournal2009%252FGraphics%252FP096060052Bz-500.jpg%3Bhttp%253A%252F%252Fwww.travelling-australia.info%252FJournal2009%252F06JunA.html%3B500%3B334'>heaps<\/a>.<\/p>\n<hr \/>\n<p id='jsspt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9877' title='Java Swing Sound Primer Tutorial'>Java Swing Sound Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JSound\/Java_JSound.jpg\"><img decoding=\"async\" id='mximgjoptionpane'  style=\"float:left; border: 15px solid pink;\" alt=\"Java Swing Sound Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JSound\/Java_JSound.jpg\" title=\"Java Swing Sound Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Java Swing Sound Primer Tutorial<\/p><\/div>\n<p>Here is a tutorial that uses <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Swing<\/a> functionality in Java to create a GUI (Graphical User Interface) desktop program on a Mac laptop (but same code may well work, compiled on a Windows laptop (the same way)) that tests the use of the Java system sound <a target=_blank href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/awt\/Toolkit.html' title='Java beep() method'>beep()<\/a> method using a button <a target=_blank href='http:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/events\/actionlistener.html'><i>ActionListener<\/i><\/a> event to control when it starts.<\/p>\n<p>Some of the points of interest, and you may want to see our previous relevant <a target=_blank href='#jsakpt' title='Java Swing ActionListener KeyListener Primer Tutorial'>Java Swing ActionListener KeyListener Primer Tutorial<\/a> as shown below, as well, are:<\/p>\n<ul>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html'>JFrame<\/a> GUI framework, even though the original idea came from a JApplet idea in <i>Introduction to Java 2<\/i> Training Manual for WEA Sydney by Phil Cogar (now that JApplets are so out of favour we did a Swing desktop solution, here, <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JSound\/Java_JSound.jpg\" title='Click picture'>today<\/a>)<\/li>\n<li>It <i>implements<\/i> Mouse event functionality via ActionListener<\/li>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JPanel information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JPanel.html'>JPanel<\/a> and <a target=_blank title='Java Swing JButton information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JButton.html'>JButton<\/a> and <a target=_blank title='Java Swing JLabel information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JLabel.html'>JLabel<\/a> GUI objects<\/li>\n<li>Can only handle the song&#8217;s rhythm, because frequency of sound is a more complex problem, so we&#8217;ve gone back to that first piano lesson with our <i>Middle C<\/i> song (believe it or not, this first piano lesson was totally devoted to thumbwork, and this song, if my memory serves me well)<\/li>\n<\/ul>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/JSound\/JSound.java_GETME' title='JSound.java'>JSound.java<\/a> that has the very simple command line compilation procedure:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javac JSound.java<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java JSound<\/p>\n<p>Of great help was this <a target=_blank href='http:\/\/learnjava777.blogspot.com.au\/2013\/12\/to-play.html' title='Of great help ... thanks'>link<\/a> and if you want to look further into playing <i>Happy Birthday<\/i> for instance:<\/p>\n<ul>\n<li><a target=_blank href='http:\/\/www.developer.com\/java\/other\/article.php\/2226701\/Java-Sound-Creating-Playing-and-Saving-Synthetic-Sounds.htm' title='More advanced Java audio functionality'>Java Sound, Creating, Playing, and Saving Synthetic Sounds &#8211; Developer.com<\/a><\/li>\n<li>Thanks to this <a target=_blank href='http:\/\/www.dreamincode.net\/forums\/topic\/64730-c-sound-frequencies\/' title='Useful link ... thanks'>link<\/a> regarding<br \/><code>      String hbstuff[] = {<br \/>\n\"hap\",\"C4\",\"262\",\"0.5\",\"sec\",<br \/>\n\"py\",\"C4\",\"262\",\"0.5\",\"sec\",<br \/>\n\"birth\",\"D4\",\"294\",\"1\",\"sec\",<br \/>\n\"day\",\"C4\",\"262\",\"1\",\"sec\",<br \/>\n\"to\",\"F4\",\"349\",\"1\",\"sec\",<br \/>\n\"you\",\"E4\",\"330\",\"2\",\"sec\",<br \/>\n\"hap\",\"C4\",\"262\",\"0.5\",\"sec\",<br \/>\n\"py\",\"C4\",\"262\",\"0.5\",\"sec\",<br \/>\n\"birth\",\"D4\",\"294\",\"1\",\"sec\",<br \/>\n\"day\",\"C4\",\"262\",\"1\",\"sec\",<br \/>\n\"to\",\"G4\",\"392\",\"1\",\"sec\",<br \/>\n\"you\",\"F4\",\"349\",\"2\",\"sec\",<br \/>\n\"hap\",\"C4\",\"262\",\"0.5\",\"sec\",<br \/>\n\"py\",\"C4\",\"262\",\"0.5\",\"sec\",<br \/>\n\"birth\",\"C5\",\"523\",\"1\",\"sec\",<br \/>\n\"day\",\"A4\",\"440\",\"1\",\"sec\",<br \/>\n\"dear\",\"F4\",\"349\",\"1\",\"sec\",<br \/>\n\"so\",\"E4\",\"330\",\"1\",\"sec\",<br \/>\n\"so\",\"D4\",\"294\",\"3\",\"sec\",<br \/>\n\"hap\",\"B4b\",\"466\",\"1\",\"sec\",<br \/>\n\"py\",\"B4b\",\"466\",\"1\",\"sec\",<br \/>\n\"birth\",\"A4\",\"440\",\"1\",\"sec\",<br \/>\n\"day\",\"F4\",\"349\",\"1\",\"sec\",<br \/>\n\"to\",\"G4\",\"392\",\"1\",\"sec\",<br \/>\n\"you!\",\"F4\",\"349\",\"2\",\"sec\"<br \/>\n};<br \/>\n<\/code><\/li>\n<\/ul>\n<p>Here is some information from Wikipedia regarding the <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Java Swing<\/a> functionality.<\/p>\n<hr \/>\n<p id='jsakpt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=9017' title='Java Swing ActionListener KeyListener Primer Tutorial'>Java Swing ActionListener KeyListener Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/TypingSpeed\/Java_TypingSpeed.jpg\"><img decoding=\"async\" id='ximgjoptionpane' onmouseover=\"this.src=this.src.replace('.gif', '.PNG').replace('.png', '.JPG').replace('.jpg', '.gif').replace('.PNG', '.png').replace('.JPG', '.jpg');  \"  style=\"float:left; border: 15px solid pink;\" alt=\"Java Swing ActionListioner KeyListener Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/TypingSpeed\/Java_TypingSpeed.jpg\" title=\"Java Swing ActionListioner KeyListener Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')\"  \/><\/a><p class=\"wp-caption-text\">Java Swing ActionListener KeyListener Primer Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Here is a tutorial that uses <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Swing<\/a> functionality in Java to create a GUI (Graphical User Interface) desktop program on a Mac laptop (but same code may well work, compiled on a Windows laptop (the same way)) that tests your typing speed skills.  As you can imagine, in order to measure your performance we&#8217;ll need to code for Keyboard events, via <a target=_blank href='http:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/events\/keylistener.html'><i>KeyListener<\/i><\/a> and Mouse events, via <a target=_blank href='http:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/events\/actionlistener.html'><i>ActionListener<\/i><\/a>.<\/p>\n<p>Some of the points of interest, and you may want to see our previous relevant <a target=_blank href='#jsopt' title='Java Swing OptionPane Primer Tutorial'>Java Swing OptionPane Primer Tutorial<\/a> as shown below, as well, are:<\/p>\n<ul>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html'>JFrame<\/a> GUI framework<\/li>\n<li>It <a target=_blank href='http:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/usinginterface.html'><i>implements<\/i><\/a> Keyboard event functionality via <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/TypingSpeed\/Java_TypingSpeed.gif'><i>KeyListener<\/i><\/a><\/li>\n<li>It <i>implements<\/i> Mouse event functionality via  <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/TypingSpeed\/Java_TypingSpeed.gif'><i>ActionListener<\/i><\/a><\/li>\n<li>Is a desktop Java application that uses a Java Swing <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JPanel.html'>JPanel<\/a> and <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JButton.html'>JButton<\/a> and <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JTextArea.html'>JTextArea<\/a> (one with a JFrame parent and one with a JPanel parent) and <a target=_blank title='Java Swing JFrame information' href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JLabel.html'>JLabel<\/a> (with a JFrame parent) GUI objects<\/li>\n<li>Use of Java class <a target=_blank href='http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/math\/BigDecimal.html' title='Java class BigDecimal'>BigDecimal<\/a> for the purposes of presenting a String representation of a <i>double<\/i> rounded to one decimal place<\/li>\n<\/ul>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/TypingSpeed\/TypingSpeed.java_GETME' title='TypingSpeed.java'>TypingSpeed.java<\/a> that has the very simple command line compilation procedure:<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javac TypingSpeed.java<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java TypingSpeed<\/p>\n<p>Here is some information from Wikipedia regarding the <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Java Swing<\/a> functionality, and here are some <a target=_blank href='https:\/\/www.youtube.com\/watch?v=kV_JoQJFzrE' title='Java Swing'>practitioners<\/a> &#8230; <font size=2>chortle &#8230; chortle<\/font>.<\/p>\n<hr \/>\n<p id='jsopt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3088' title='Java Swing OptionPane Primer Tutorial'>Java Swing OptionPane Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/\"><img decoding=\"async\" id='imgjoptionpane' onmouseover=\"var xqw=this.src; if (xqw.indexOf('0') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-1of.jpg'; } else if (xqw.indexOf('1') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-2of.jpg'; } else if (xqw.indexOf('2') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-3of.jpg'; }  else if (xqw.indexOf('3') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-4of.jpg'; }  else if (xqw.indexOf('4') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-5of.jpg'; } else { this.src = 'http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-0of.jpg'; } \"  style=\"float:left; border: 15px solid pink;\" alt=\"Java Swing OptionPane Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Java_OptionPane-0of.jpg\" title=\"Java Swing OptionPane Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')\"  \/><\/a><p class=\"wp-caption-text\">Java Swing OptionPane Primer Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Here is a tutorial that uses Swing functionality in Java to create a GUI (Graphical User Interface) program on a Mac laptop that displays calculator program performing +-*\/^!   Below is some information from Wikipedia regarding the <a target=_blank title='Java Swing' href='http:\/\/en.wikipedia.org\/wiki\/Swing_%28Java%29'>Java Swing<\/a> functionality:<\/p>\n<blockquote><p>Swing is the primary Java GUI widget toolkit. It is part of Oracle&#8217;s Java Foundation Classes (JFC) \u2014 an API for providing a graphical user interface (GUI) for Java programs.<\/p>\n<p>Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). Swing provides a native look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform. It has more powerful and flexible components than AWT. In addition to familiar components such as buttons, check boxes and labels, Swing provides several advanced components such as tabbed panel, scroll panes, trees, tables, and lists.<\/p>\n<p>Unlike AWT components, Swing components are not implemented by platform-specific code. Instead they are written entirely in Java and therefore are platform-independent. The term &#8220;lightweight&#8221; is used to describe such an element.[citation needed]<\/p><\/blockquote>\n<p>This program works a rudimentary calculator for +-*\/^! functionality.<\/p>\n<p>Let&#8217;s see some  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/'>Java Swing<\/a> code for this, and how it works &#8230;\n<\/p>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Java\/Swing\/OptionPane\/Calculator.java_GETME'>Calculator.java<\/a><\/p>\n<p>But of course regarding all the information above <a target=_blank title=\"It Don't Mean a Thing (if it ain't got that swing)\" href='http:\/\/www.youtube.com\/watch?v=lMFIejZgJSM'>It Don&#8217;t Mean A Thing (if it ain&#8217;t got that swing)<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3088' onclick='var dv=document.getElementById(\"d3088\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=52\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3088' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d9017' onclick='var dv=document.getElementById(\"d9017\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Swing\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d9017' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d9877' onclick='var dv=document.getElementById(\"d9877\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Java\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d9877' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d9924' onclick='var dv=document.getElementById(\"d9924\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=GUI\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d9924' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d10209' onclick='var dv=document.getElementById(\"d10209\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=tree\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10209' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d10592' onclick='var dv=document.getElementById(\"d10592\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Applet\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10592' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sort of miss Java Applets, myself, as they were once &#8220;the thing&#8221; for some people writing code for the web. You got used to paint() and repaint() methods because you could imagine, word for word, codewise, what was happening. So &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/java-swing-line-graph-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,17,37],"tags":[95,234,319,484,538,644,657,661,699,700,707,812,814,954,997,1228,1319],"class_list":["post-10592","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-gui","category-tutorials","tag-applet","tag-command-line","tag-desktop","tag-geometry","tag-graph","tag-java","tag-jframe","tag-jpanel","tag-line-chart","tag-line-graph","tag-linux","tag-mouse","tag-mouselistener","tag-plot","tag-programming","tag-swing","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/10592"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=10592"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/10592\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=10592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=10592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=10592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}