⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultapplet.java

📁 学生选课 用java和sql server 2000用asp完成的学生选课管理系统-Students to use java classes and sql server 2000 with asp
💻 JAVA
字号:
/*
 * ResultApplet.java
 *
 * 
 */

package sample;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ResultApplet extends Applet implements  ActionListener{
	private TextField d1, d2, result;  //member variable
	private MathApplet mapplet;        //member variable

	public void init(){
		d1 = new TextField(10);
		d2 = new TextField(10);
		result = new TextField(10);

		add(new Label("arg0"));
		add(d1);

		add(new Label("arg1"));
		add(d2);

		add(new Label("result"));
		add(result);

		Button cal = new Button("Calculate");
		add(cal);

		cal.addActionListener(this); // ActionListener: this-> ResultApplet 

		setVisible(false);		
	}

	private void getApp(){  // get object of another applet
            
              //mapplet = (MathApplet)getAppletContext().getApplet("math");

               AppletContext acontext=getAppletContext();  // returns an object of AppletContext
               mapplet= (MathApplet) acontext.getApplet("math"); //  returns an Applet Obejct whose name is math
                  //如何在一个Applet中,获得同网页上的另一个Applet。大家都在一个IE的小程序查看器中运行。
	}

	public void start(){
            getApp();  // call getApp() method
        }

	public void actionPerformed(ActionEvent evt){
		double arg0 = 0;
		double arg1 = 0;

		try{
			arg0 = new Double(d1.getText()).doubleValue();
		}catch(Exception e){e.printStackTrace();}

		try{
			arg1 = new Double(d2.getText()).doubleValue();
		}catch(Exception e){e.printStackTrace();}
                
               if(mapplet == null) getApp();

 		// call add method of MathApplet 
                //  and set text on its  textField		
 
               double dd=mapplet.add(arg0, arg1); // call method of mapplet   ---调用另一个MapthApplet对象,执行其中的.add()方法。
               result.setText("" + dd);

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -