Small Code Validation Java applet

Source: Internet
Author: User
Tags gettext gety

/**************************************************  wz   asust  2016  Note:  the necessary configuration to run the Java file after the  class file is generated the last browser needs to delete the original class file   and the browser has memory function   need to close again   Wait 3 seconds to load the Applet java console after the basic page loads   then click Run if necessary. /import java.applet.*;import java.awt.*;import  java.net.*;import java.awt.event.*;import java.applet.applet;import java.awt.*;import  java.awt.Graphics;import java.applet.Applet;import java.util.Calendar;import  java.awt.graphics;import java.applet.applet;import java.util.calendar;import java.awt.graphics; Import java.applet.applet;public class wz extends applet{/*********  10  ********************public void paint (graphics g) {   int x=10, y =10;   g.drawstring ("1:x=" +x+ ",  y=" +y,30,30);     ff1 (x, y,g);} //STATIC&NBSP;VOID&NBSP;FF1 (INT&NBSP;PASSX,&NBSP;INT&NBSP;PASSY,GRAPHICS&NBSP;G)  { void ff1 (int &NBSP;PASSX,&NBSP;INT&NBSP;PASSY,GRAPHICS&NBSP;G)  {   passX=passX*passX;    Passy=passy*passy;g.drawstring (" 2: passx=" +passx+ ",  passy=" +passy,30,60);  }}/*********   9 ***********  no error no output*********public class wz  extends applet{graphics g;public void paint () {   int x=10,  Y=10;   g.drawstring ("1:x=" +x+ ",  y=" +y,30,30);    //ff1 (x, y);} STATIC&NBSP;VOID&NBSP;FF1 (Int passx, int passy)  { void ff1 (Int passX,  int passy)  {   passX=passX*passX;   passY=passY*passY; g.DrawString (" 2: passx=" +passx+ ",  passy=" +passy,30,60); }}/*********************   8 ***************class sTaticdemo {static int x;int y;public static int getx ()  {return x;} Public static void setx (INT&NBSP;NEWX)  {x = newx;} Public int gety ()  {return y;} Public void sety (Int newy)  {y = newy;}} Public class wz extends applet{public void paint (Graphics g)  { g.DrawString ("1:  static variable x=" +staticdemo.getx (), 30,30);// g.drawstring ("2:  instance variable y=" +staticdemo.gety () , 30,30); //  illegal, compile error staticdemo a= new staticdemo (); Staticdemo b= new staticdemo (); A.setx (1); a.sety (2); B.setx (3); b.sety (4); g.DrawString ("3: Static variable a.x= "+a.getx (), 30,60); g.DrawString (" 3: Instance variable a.y= "+a.gety (), 30,90); g.DrawString (" 3: Static variable b.x= "+b.getx (), 30,120); g.DrawString ("3: Instance variable b.y=" +b.gety (), 30,150);}}  *********************  7  **** error ************class RunDemo  Extends applet{private string username, password; Rundemo ()  {system.out.println ("All Empty!");} Rundemo (String name)  {username=name;} Rundemo (STRING&NBSP;NAME,&NBSP;STRING&NBSP;PWD)  {this (name);p Assword=pwd;check (); Void check ()  {String s=null;if  (username!=null) s= "User name: +username;elses=" username cannot be empty! ";if  (password!=" 12345678 ") s=s+"   Password is invalid! "; elses=s+"   Password: ******** "; System.out.println (s);} Public void paint (graphics g)  {g.drawstring ("1:" +new rundemo (), 30,30); G.drawString (" 2: "+new rundemo (" Liu Xinyu "), 30,60), g.DrawString (" 3: "+new rundemo (null," Shaoliping "), 30,90); g.DrawString (" 3: "+new  rundemo ("Zhang Chi", "12345678"), 30,120);}} Public class wz { rundemo wz1=new rundemo ();   // wz.paint ();  error need  logo}/******************* 6 ***************************class rundemo { private string username, password; Rundemo ()  {system.out.println ("All Empty!");} Rundemo (String&nbsP;name)  {username=name;} Rundemo (STRING&NBSP;NAME,&NBSP;STRING&NBSP;PWD)  {this (name);p Assword=pwd;check (); Void check ()  {String s=null;if  (username!=null) s= "User name: +username;elses=" username cannot be empty! ";if  (password!=" 12345678 ") s=s+"   Password is invalid! "; elses=s+"   Password: ******** "; System.out.println (s);}} Public class wz extends applet{public void paint (Graphics g)  { g.DrawString ("1:" +new rundemo (), 30,30) g.drawstring ("2:" +new rundemo ("Liu Xinyu"), 30,60); g.DrawString ("3:" +new rundemo (NULL, "Shaoliping"), 30,90) g.drawstring ("3:" +new rundemo ("Zhang Chi", "12345678"), 30,120);}  }  ******************* 5 ***************************         public class wz extends applet implements actionlistener {             label label1=new label ("+");              label label2=new label ("=");             textfield field1=new textfield (6);             textfield field2=new textfield (6);             textfield field3=new textfield (6);             button button1=new button ("Add");             public void init ()  { //  Initialize             add (field1);             add (Label1);             add (Field2);             Add (Label2);   &nbSp;         add (field3);             add (button1);             button1.addactionlistener (this);           }           public void actionperformed (ActionEvent &NBSP;E)  { //  Handle button event             int  x=integer.parseint (Field1.gettext ()) +integer.parseint (Field2.gettext ());             field3.settext (integer.tostring (x)); //  value converted to string              }           }  *************** 4 *********     public  Class wz extends&nbSp Applet {         mybox b1=new mybox ();//Create Object   B1         mybox b2=new mybox (170,20,60,60);  // Create Object  b2         public void paint (GRAPHICS&NBSP;G)  {           b1.setposition (20,20);            b1.setsize (60,60);            b1.draw (g);            g.DrawString ("Rectangle  1   X  position: " +b1.getx (),  20, 100);            g.drawstring ("Rectangle  1   Y  position: " +b1.gety (), &NBSP;20,&NBSP;120);            b2.draw (g);       &Nbsp;    g.drawstring ("Rectangle  2   X  position: " +b2.getx (),  b2.getx (),  b2.gety () +80);            g.drawstring ("Rectangle  2    Y  Location:  "+b2.gety (),  b2.getx (),  b2.gety () +100);          }       }     class  Mybox {       private int x, y, width, height ;        mybox ()  {          x=0;         y=0;          width=0;         height=0;        }       mybox (Int xpos, int ypos, int  w, int h)  {         x=xPos;          y=yPos;         width=w;          height=h;       }       public void setPosition  (Int xpos, int ypos)  {          x=xpos;         y =ypos;       }       public void  setSize  (int w, int h)  {          width=w;         height=h;        }       public int getx ()  {          return&nBsp;x;        }        public  int gety ()  {          return y;         }        public void  draw (graphics g)  {          g.drawrect (x,  y, width, height);        }      } /********** 3 **********class intsort  {public string sort (int &NBSP;A,&NBSP;INT&NBSP;B)  {if  (a>b) return a+ " " +b;elsereturn b+ " " +A;} Public string sort (int a, int b, int c)  {int swap;if  (a<b )  {swap=a;a=b;b=swap;} if  (A<c)  {swap=a;a=c;c=swap;} if  (B<c)  {swap=b;b=c;c=swap;} return a+ " " +b+ "&NBSP; " +c;} Public string sort (int arr[])  {string s= " ";int swap;for  (int i=0 ;  i<arr.length; i++) for  (int j=0; j<arr.length-1; j++) if  (arr[j]> ARR[J+1])  {swap=arr[j];arr[j]=arr[j+1];arr[j+1]=swap;} for  (int i=0; i<arr.length; i++) s=s+arr[i]+ " "; return s;}} Public class wz extends applet {intsort s=new intsort ();p ublic void  paint (graphics g)  {int a=30, b=12, c=40;int arr[]={ 34,8,12,67,44,98,52,23,16,16};g.drawstring ("Two-digit sort results:" +s.sort (A, B), 30,30); g.DrawString ("three-digit result:" +s.sort (A, B, c), 30,60); g.DrawString ("Sorted result of array:" +s.sort (arr), 30,90);}}  ********** 2 **********class time {private calendar t;private int  y, m, d, hh, mm, ss; time  () {t=calendar.getinstance (); Y=t.get (t.year); M=t.get (T.month) +1;d=t.get (t.date); Hh=t.get (T.HOUR_OF_day); Mm=t.get (T.minute); Ss=t.get (T.second);} Public string getdate ()  {return y+ "  Year" +m+ "month" +d+ "Day";} Public string gettime ()  {string s=hh+ " " +mm+ "+ss+" seconds "; return s;}     }public class wz extends applet {time t=new time (); Public void paint (graphics g)  {g.drawstring ("Current date:" +t.getdate (), 50,40); G.drawString ("Current time: "+t.gettime (), 50,80);}}  1 **********public void paint (graphics g)  {g.drawrect (0,0,250,100); G.setcolor (Color.Blue); g.DrawString ("Look at me, i ' m a java applet!", 10,50);} /     html     

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7F/F5/wKioL1cy50XBoJ7HAAR4rotZQsk478.png "title=" Java.png "alt=" Wkiol1cy50xboj7haar4rotzqsk478.png "/>

Small Code Validation Java applet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.