South Mail Java Programming Experiment 2 applet design for small applications
Experimental Purpose:
Students are required to develop the ability to design web browser-based applets by experimenting with learning and understanding Java applets in classroom learning content, and by fostering students to combine Java applet-related knowledge points, including Java and low-level event processing models.
Experimental content:
Design and write an applet applets and corresponding HTML pages that can be manipulated by the mouse, observe the execution of the applet, and test the effect of the user interaction of the program mouse.
Experiment Code:
Java:
Import Java.applet.*;import java.awt.*;import Java.awt.event.*;class JAVA2 extends applet implements actionlistener{Bu Tton B,c; public void Init () {label label=new label ("press button:"); B=new button ("button 1");//Construction Buttons B.addactionlistener (this);//Monitor C=new button ("button 2"); C.addactionlistener (this); Add (label); Add (b);//Add button to page Add (c); } public void actionperformed (ActionEvent e) {if (E.getsource () ==b) {Frame frame=new frame ("reminders"); Frame.setsize (230,100);//Set size frame.setlocation (100,100);//Set position Frame.add ("You pressed button 1");//Add Label Check frame.setvisible (TRUE);//Set whether Frame.validate () is visible; } else if (E.getsource () ==c) {Frame frame=new frame ("Reminder"); Frame.setsize (230,100); Frame.setlocation (100,100); Frame.add ("You pressed button 2"); Frame.setvisible (TRUE); Frame.validate (); } }}
Html:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
South Mail Java Programming Experiment 2 applet design for small applications