{"id":2746,"date":"2017-12-03T07:00:07","date_gmt":"2017-12-03T07:00:07","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2746"},"modified":"2018-06-27T15:11:42","modified_gmt":"2018-06-27T15:11:42","slug":"applet-life-cycle-and-how-to-handle-event-in-applet-in-core-java","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/applet-life-cycle-and-how-to-handle-event-in-applet-in-core-java\/","title":{"rendered":"Applet Life cycle and How to Handle Event in Applet in Core Java"},"content":{"rendered":"<p>In this tutorial Applet Life cycle is explained and how to handle event in Applet in Core Java is shown.<\/p>\n<p>Code:<\/p>\n<p>MyApplet.java<\/p>\n<p>\/*&lt;applet code=&#8221;MyApplet&#8221; height=&#8221;400&#8243; width=&#8221;400&#8243;&gt; &lt;\/applet&gt;*\/<\/p>\n<p>import java.awt.*;<br \/>\nimport java.awt.event.*;<br \/>\nimport java.applet.*;<br \/>\nimport javax.swing.*;<\/p>\n<p>public class MyApplet extends Applet<br \/>\n{<br \/>\nButton b;<br \/>\nLabel l;<br \/>\nTextField t;<\/p>\n<p>public void init()<br \/>\n{<br \/>\nb = new Button(&#8220;OK&#8221;);<br \/>\nl = new Label(&#8220;Enter your name:&#8221;);<br \/>\nt = new TextField(30);<\/p>\n<p>add(l);<br \/>\nadd(t);<br \/>\nadd(b);<\/p>\n<p>b.addActionListener(new ActionListener()<br \/>\n{<br \/>\npublic void actionPerformed(ActionEvent e)<br \/>\n{<br \/>\nJOptionPane.showMessageDialog(null,&#8221;Hello &#8220;+t.getText(),&#8221;MESSAGE&#8221;,JOptionPane.INFORMATION_MESSAGE);<br \/>\n}<\/p>\n<p>});<\/p>\n<p>System.out.println(&#8220;Inside init&#8221;);<br \/>\n}<\/p>\n<p>public void start()<br \/>\n{<br \/>\nSystem.out.println(&#8220;Inside start&#8221;);<br \/>\n}<\/p>\n<p>public void stop()<br \/>\n{<br \/>\nSystem.out.println(&#8220;Inside stop&#8221;);<br \/>\n}<\/p>\n<p>public void destroy()<br \/>\n{<br \/>\nSystem.out.println(&#8220;Inside destroy&#8221;);<br \/>\n}<\/p>\n<p>public void paint(Graphics g)<br \/>\n{}<\/p>\n<p>}<\/p>\n<p><a href=\"https:\/\/youtu.be\/PY4iO9_b5AI\">https:\/\/youtu.be\/PY4iO9_b5AI<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial Applet Life cycle is explained and how to handle event in Applet in Core Java is shown. Code: MyApplet.java \/*&lt;applet code=&#8221;MyApplet&#8221; height=&#8221;400&#8243; width=&#8221;400&#8243;&gt; &lt;\/applet&gt;*\/ import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class MyApplet extends Applet { Button b; Label l; TextField t; public void init() { b = new Button(&#8220;OK&#8221;); l = new Label(&#8220;Enter your name:&#8221;); t = new TextField(30); add(l); add(t); add(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null,&#8221;Hello &#8220;+t.getText(),&#8221;MESSAGE&#8221;,JOptionPane.INFORMATION_MESSAGE); } }); System.out.println(&#8220;Inside init&#8221;); } public void start() { System.out.println(&#8220;Inside start&#8221;); } public void stop() { System.out.println(&#8220;Inside stop&#8221;); } public void destroy() { System.out.println(&#8220;Inside destroy&#8221;); } public void paint(Graphics g) {} }<!-- AddThis Advanced Settings generic via filter on get_the_excerpt -->","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156],"tags":[209,221,157,222],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2746"}],"collection":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/comments?post=2746"}],"version-history":[{"count":4,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2746\/revisions"}],"predecessor-version":[{"id":3176,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2746\/revisions\/3176"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}