<applet code="ProvApplet1.class" width="300" height="200"> </applet>
import java.applet.Applet; import java.awt.Graphics; public class ProvApplet1 extends Applet{ public void paint(Graphics g){ g.drawString("Applet",getWidth()/2,getHeight()/2); } }
import java.applet.Applet; import java.awt.Graphics; public class ProvApplet2 extends Applet{ public void paint(Graphics g){ String msg=getParameter("msg"); int x=Integer.parseInt(getParameter("x")); int y=Integer.parseInt(getParameter("y")); g.drawString(msg,x,y); } }
<applet code="ProvApplet2.class" width="300" height="200"> <param name="msg" value="Applet"> <param name="x" value="10"> <param name="y" value="150"> </applet>
import java.applet.Applet; import java.awt.Graphics; public class ProvApplet4 extends Applet{ public void paint(Graphics g){ String msg=getParameter("msg"); int x=Integer.parseInt(getParameter("x")); int y=Integer.parseInt(getParameter("y")); g.setFont(new Font("Serif",Font.BOLD,24)); g.setColor(Color.red); g.drawString(msg,x,y); g.setColor(Color.blue); g.drawLine(x,0,x,getHeight()); g.drawLine(0,y,getWidth(),y); } }
import java.applet.Applet; import java.awt.Graphics; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; public class ProvApplet5 extends Applet{ public ProvApplet5(){ // aggiunge gestore (listener) dell'evento 'pressione sul mouse' class GestoreMousePress implements MouseListener{ public void mousePressed(MouseEvent event){ x = event.getX(); y = event.getY(); } // altri metodi lasciati inerti public void mouseReleased(MouseEvent event) {} public void mouseClicked(MouseEvent event) {} public void mouseEntered(MouseEvent event) {} public void mouseExited(MouseEvent event) {} } MouseListener gestore = new GestoreMousePress(); addMouseListener(gestore); } public void paint(Graphics g){ g.drawString("Applet",x,y); } private int x=100; private int y=100; }