java applet 一个简单的例子(applet+html)

java applet是一个类,其层次结构如下图:  
类 JApplet 
java.lang.Object 
  java.awt.Component 
      java.awt.Container 
          java.awt.Panel 
              java.applet.Applet 
                  javax.swing.JApplet
 

编写applet类,继承Applet或是JApplet,然后完成init方法,在创建一个加载applet的html页面

package ch10;

/**
   @version 1.21 2004-05-07
   @author Cay Horstmann
*/

/*
  The following HTML tags are required to display this applet in a browser:
  <applet code="NotHelloWorldApplet.class" width="300" height="100">
  </applet>
*/

import javax.swing.*;

public class NotHelloWorldApplet extends JApplet
{
   public void init()
   {
      JLabel label = new JLabel("Not a Hello, World applet", SwingConstants.CENTER);
      add(label);
   }
}

<applet code="ch10.NotHelloWorldApplet.class"
   width="300" height="100">
</applet>

编译applet:

javac NotHelloWorldApplet.java

而后用applet查看器appletviewer查看html:

appletviewer NotHelloWorldApplet.class

或者是直接打开html文件(需浏览器支持JAVA(TM)插件)。


编写一个Applet,在途中加入标签“旋转角度”和文本框,安排两个按钮“顺时针旋转”和“逆时针旋转”,在文本框中填写旋转角度,通过按钮实现旋转.

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

public class g2DRotate2 extends Applet implements ActionListener{
 Label label;
 TextField angle;
 Button b1,b2;
 int flag=1;
 
 public void init(){
  setLayout(null);
  label=new Label("旋转角度:");
  label.setBounds(250,100,65,20);
  
  angle=new TextField("0.0",10);
  angle.setBounds(330,100,65,20);
  
  b1=new Button("顺时针旋转");
  b2=new Button("逆时针旋转");
  b1.setBounds(250,130,65,20);
  b2.setBounds(330,130,65,20);
  b1.addActionListener(this);
  b2.addActionListener(this);
  
  add(label);
  add(angle);
  add(b1);
  add(b2);
  
  show();
 }
 
 public void paint(Graphics g){
  int x=130,y=100;
  int i=0;
  Graphics2D g2=(Graphics2D)g;
  g.setColor(Color.blue);
  g2.draw(new Ellipse2D.Double(x,y,20,90));
  
  g.setColor(Color.black);
  g.drawRect(x,y,20,90);
  
  g2.translate(150,100);//平移到(150,100),作为下面旋转的起点
  if(flag==1)
   g2.rotate(Double.parseDouble(angle.getText()));//将角度转换成弧度
  else
   g2.rotate(-Double.parseDouble(angle.getText()));
  g.setColor(Color.blue);
  g2.draw(new Ellipse2D.Double(-20,0,20,90));
  
  g.setColor(Color.black);
  g.drawRect(-20,0,20,90); 
 }
 public void actionPerformed(ActionEvent e) {
  if(e.getSource()==b1){
   flag=1;
   repaint();
  }else{
   flag=-1;
   repaint();
  }
 }
}


javacard applet 开发实例 正常运行 带jar包 package mifare; import com.ibm.jz.JZSystem; import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException; import javacard.framework.Util; public class AmbiqApplet extends Applet { byte[] mifarePassDefault={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass8={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass9={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] adminPass={(byte)0x40,(byte)0x41,(byte)0x42,(byte)0x43,(byte)0x44,(byte)0x45,(byte)0x46,(byte)0x47,(byte)0x48,(byte)0x49,(byte)0x4a,(byte)0x4b,(byte)0x4c,(byte)0x4d,(byte)0x4e,(byte)0x4f}; public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration new AmbiqApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); } public void process(APDU apdu) { short i; byte[] send=new byte[52]; byte[] send2=new byte[24]; // Good practice: Return 9000 on SELECT if (selectingApplet()) { return; } byte[] buf = apdu.getBuffer(); if(buf[ISO7816.OFFSET_CLA]==AmbiqConstant.CLS_AMBIQ) { switch (buf[ISO7816.OFFSET_INS]) { case AmbiqConstant.INS_GET_MIFARE: if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } /*Get Entire Mifare Ticket data * Returns back the content of the entire sector 8 (3 block 8.0, 8.1, 8.2) and the first 4 bytes of block 9.0; total 52bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x20 Read entire data P1 1 0x00 Sector number P2 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值