swing - How do I make this run as a Java applet instead of a Java application? -


i can't figure out how run applet, please i've been trying bunch of things nothing working. believe have make class extend applet i'm not sure change after doing that

edit: nevermind have solved problem! :d

import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*;  public class howmany {     private jframe mainjframe;    private jlabel headerjlabel;    private jlabel statusjlabel;    private jpanel controljpanel;     public howmany() {       preparegui();    }     public static void main(string[] args){ /* main part of code */       howmany howmany = new howmany();         howmany.showeventdemo();           }     private void preparegui() {       mainjframe = new jframe("click button!"); /*sets applet title */       mainjframe.setsize(400,400); /* sets size of applet */       mainjframe.setlayout(new gridlayout(3, 1));        headerjlabel = new jlabel("",jlabel.center ); //centers header jlabel       statusjlabel = new jlabel("",jlabel.center); //centers status jlabel            statusjlabel.setsize(350,100); //sets size of status jlabel       mainjframe.addwindowlistener(new windowadapter() {          public void windowclosing(windowevent windowevent){             system.exit(0);          }               });           controljpanel = new jpanel();       controljpanel.setlayout(new flowlayout());        mainjframe.add(headerjlabel); //adds stuff applet       mainjframe.add(controljpanel);       mainjframe.add(statusjlabel);       mainjframe.setvisible(true);      }     private void showeventdemo() {       headerjlabel.settext("click button add bottom text!");     /* tells click */       /* click button */       jbutton clickbutton = new jbutton("click me!");        clickbutton.setactioncommand("click me!");        clickbutton.addactionlistener(new buttonclicklistener());        /* adds buttons jframe */       controljpanel.add(clickbutton);             mainjframe.setvisible(true);      }     private class buttonclicklistener implements actionlistener {       int x = 0; //sets starting value of # of times button clicked 0       public void actionperformed(actionevent e) {          string command = e.getactioncommand();            /* displays how many times button clicked */          if( command.equals( "click me!" ))  {              x = x + 1;              string m = integer.tostring(x);             statusjlabel.settext("times clicked: " + m);          }       }         } } 

to make java applet run going need run on web server.

this link shows oracles examples on how make applet should able follow work example:

https://docs.oracle.com/javase/tutorial/deployment/applet/

also can see on page if trying run local applet , have java security set high or high won't work. keep in mind.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -