{"id":10299,"date":"2015-08-26T07:15:17","date_gmt":"2015-08-26T11:15:17","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10299"},"modified":"2015-08-24T08:54:52","modified_gmt":"2015-08-24T12:54:52","slug":"adds-typing-to-the-freehand-drawing","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10299","title":{"rendered":"Adds typing to the freehand drawing."},"content":{"rendered":"<pre>import java.applet.Applet;\r\nimport java.awt.*;\r\nimport java.awt.event.*;\r\n\r\n\/** A better whiteboard that lets you enter\r\n\u00a0*\u00a0 text in addition to freehand drawing.\r\n\u00a0* \u00a0\r\n\r\n\r\n\u00a0******************\r\n\r\npublic class Whiteboard extends SimpleWhiteboard {\r\n\u00a0 protected FontMetrics fm;\r\n\r\n\u00a0 public void init() {\r\n\u00a0\u00a0\u00a0 super.init();\r\n\u00a0\u00a0\u00a0 Font font = new Font(\"Serif\", Font.BOLD, 20);\r\n\u00a0\u00a0\u00a0 setFont(font);\r\n\u00a0\u00a0\u00a0 fm = getFontMetrics(font);\r\n\u00a0\u00a0\u00a0 addKeyListener(new CharDrawer());\r\n\u00a0 }\r\n\r\n\u00a0 private class CharDrawer extends KeyAdapter {\r\n\u00a0\u00a0\u00a0 \/\/ When user types a printable character,\r\n\u00a0\u00a0\u00a0 \/\/ draw it and shift position rightwards.\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 public void keyTyped(KeyEvent event) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 String s = String.valueOf(event.getKeyChar());\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 getGraphics().drawString(s, lastX, lastY);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 record(lastX + fm.stringWidth(s), lastY);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** A better whiteboard that lets you enter \u00a0*\u00a0 text in addition to freehand drawing. \u00a0* \u00a0 \u00a0****************** public class Whiteboard extends SimpleWhiteboard { \u00a0 protected FontMetrics fm; \u00a0 public void init() { \u00a0\u00a0\u00a0 super.init(); \u00a0\u00a0\u00a0 Font font = new Font(&#8220;Serif&#8221;, Font.BOLD, 20); \u00a0\u00a0\u00a0 setFont(font); \u00a0\u00a0\u00a0 fm = getFontMetrics(font); &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10299\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,285],"class_list":["post-10299","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":27241,"url":"http:\/\/bangla.sitestree.com\/?p=27241","url_meta":{"origin":10299,"position":0},"title":"Adds typing to the freehand drawing. #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** A better whiteboard that lets you enter * text in addition to freehand drawing. * ****************** public class Whiteboard extends SimpleWhiteboard { protected FontMetrics fm; public void init() { super.init(); Font font = new Font(\"Serif\", Font.BOLD, 20); setFont(font); fm = getFontMetrics(font); addKeyListener(new CharDrawer());\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10395,"url":"http:\/\/bangla.sitestree.com\/?p=10395","url_meta":{"origin":10299,"position":1},"title":"An applet that permits freehand drawing","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** An applet that lets you perform freehand drawing. \u00a0* \u00a0 \u00a0**************** public class SimpleWhiteboard extends Applet { \u00a0 protected int lastX=0, lastY=0; \u00a0 public void init() { \u00a0\u00a0\u00a0 setBackground(Color.white); \u00a0\u00a0\u00a0 setForeground(Color.blue); \u00a0\u00a0\u00a0 addMouseListener(new PositionRecorder()); \u00a0\u00a0\u00a0 addMouseMotionListener(new LineDrawer()); \u00a0 } \u00a0 protected void record(int\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26777,"url":"http:\/\/bangla.sitestree.com\/?p=26777","url_meta":{"origin":10299,"position":2},"title":"An applet that permits freehand drawing #Programming Code Examples #Java\/J2EE\/J2ME #Mouse and Keyboard Events","author":"Author-Check- Article-or-Video","date":"May 1, 2021","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** An applet that lets you perform freehand drawing. * **************** public class SimpleWhiteboard extends Applet { protected int lastX=0, lastY=0; public void init() { setBackground(Color.white); setForeground(Color.blue); addMouseListener(new PositionRecorder()); addMouseMotionListener(new LineDrawer()); } protected void record(int x, int y) { lastX = x; lastY =\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26860,"url":"http:\/\/bangla.sitestree.com\/?p=26860","url_meta":{"origin":10299,"position":3},"title":"Multithreaded Graphics and Double Buffering #Programming Code Examples #Java\/J2EE\/J2ME #Java Threads","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"ShipSimulation.java Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { ... public void run() { Ship s; for(int\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10408,"url":"http:\/\/bangla.sitestree.com\/?p=10408","url_meta":{"origin":10299,"position":4},"title":"Illustrates using a local font (Goudy Handtooled BT) to perform drawing in Java 2D","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.awt.*; \/** An example of using local fonts to perform drawing in \u00a0*\u00a0 Java 2D. \u00a0* \u00a0********************** public class FontExample extends GradientPaintExample { \u00a0 public FontExample() { \u00a0\u00a0\u00a0 GraphicsEnvironment env = \u00a0\u00a0\u00a0\u00a0\u00a0 GraphicsEnvironment.getLocalGraphicsEnvironment(); \u00a0\u00a0\u00a0 env.getAvailableFontFamilyNames(); \u00a0\u00a0\u00a0 setFont(new Font(\"Goudy Handtooled BT\", Font.PLAIN, 100)); \u00a0 } \u00a0 protected void drawBigString(Graphics2D g2d)\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26886,"url":"http:\/\/bangla.sitestree.com\/?p=26886","url_meta":{"origin":10299,"position":5},"title":"Illustrates using a local font (Goudy Handtooled BT) to perform drawing in Java 2D #Programming Code Examples #Java\/J2EE\/J2ME #Drawing","author":"Author-Check- Article-or-Video","date":"May 4, 2021","format":false,"excerpt":"import java.awt.*; \/** An example of using local fonts to perform drawing in * Java 2D. * ********************** public class FontExample extends GradientPaintExample { public FontExample() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); env.getAvailableFontFamilyNames(); setFont(new Font(\"Goudy Handtooled BT\", Font.PLAIN, 100)); } protected void drawBigString(Graphics2D g2d) { g2d.setPaint(Color.black); g2d.drawString(\"Java 2D\", 25, 215); }\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10299"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10299\/revisions"}],"predecessor-version":[{"id":10300,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10299\/revisions\/10300"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10299"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}