import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import org.mbed.RPC.*;
/**
* Example Applet for interfacing with mbed over RPC.
* @author Michael Walker
* @license
* Copyright (c) 2010 ARM Ltd
*
*Permission is hereby granted, free of charge, to any person obtaining a copy
*of this software and associated documentation files (the "Software"), to deal
*in the Software without restriction, including without limitation the rights
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*copies of the Software, and to permit persons to whom the Software is
*furnished to do so, subject to the following conditions:
*
*The above copyright notice and this permission notice shall be included in
*all copies or substantial portions of the Software.
*
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*THE SOFTWARE.
*
*/
//Example HTML file to load this applet
//
//
//
// // //
// // public class AppletHelloWorld extends Applet implements mbedRPC, MouseListener { private static final long serialVersionUID = 251864453971673931L; HTTPRPC mbed; DigitalOut led1 = null; DigitalOut led2 = null; DigitalOut led3 = null; DigitalOut led4 = null; boolean led1state = false; boolean led2state = false; boolean led3state = false; boolean led4state = false; public void init() { mbed = new HTTPRPC(this); System.out.println("Set up mbedHTTP object"); led1 = new DigitalOut(mbed, LED1); led2 = new DigitalOut(mbed, LED2); led3 = new DigitalOut(mbed, LED3); led4 = new DigitalOut(mbed, LED4); addMouseListener(this); } public void start(){ } public void stop(){ } public void destroy(){ led1.delete(); led2.delete(); led3.delete(); led4.delete(); mbed.delete(); mbed.delete(); } public void paint(Graphics g) { Font mbedFont = new Font("Arial",Font.BOLD,24); g.setFont(mbedFont); g.drawString("mbed Applet Demo", 90,25); Font smallerFont = new Font("Arial",Font.PLAIN,12); g.setFont(smallerFont); g.drawString("Click on the boxes to turn on and off the mbeds LEDs", 10,45); // g.drawString("mbed connected on: " + mbed.Address , 10, 210); g.setColor(Color.BLUE); g.drawRoundRect(0, 0, 399, 199, 30, 30); g.setColor(Color.blue); if(led1state == true){ g.fillRoundRect(5, 50, 90, 145, 25, 25); }else{ g.drawRoundRect(5, 50, 90, 145, 25, 25); } if(led2state == true){ g.fillRoundRect(105, 50, 90, 145, 25, 25); }else{ g.drawRoundRect(105, 50, 90, 145, 25, 25); } if(led3state == true){ g.fillRoundRect(205, 50, 90, 145, 25, 25); }else{ g.drawRoundRect(205, 50, 90, 145, 25, 25); } if(led4state == true){ g.fillRoundRect(305, 50, 90, 145, 25, 25); }else{ g.drawRoundRect(305, 50, 90, 145, 25, 25); } } public void mouseClicked (MouseEvent me){ int xpos = me.getX(); int ypos = me.getY(); if(ypos > 50 && ypos < 200){ if(xpos > 0 && xpos < 100){ led1state = !led1state; if (led1state == true){ led1.write(1); }else{ led1.write(0); } repaint(); } if(xpos > 100 && xpos < 200){ led2state = !led2state; if (led2state == true){ led2.write(1); }else{ led2.write(0); } repaint(); } if(xpos > 200 && xpos < 300){ led3state = !led3state; if (led3state == true){ led3.write(1); }else{ led3.write(0); } repaint(); } if(xpos > 300 && xpos < 400){ led4state = !led4state; if (led4state == true){ led4.write(1); }else{ led4.write(0); } repaint(); } } } public void mouseEntered (MouseEvent me) {} public void mousePressed (MouseEvent me) {} public void mouseReleased (MouseEvent me) {} public void mouseExited (MouseEvent me) {} }