import java.awt.*; public class TestWiiApplet extends BufferedApplet { Wii wii; int w = 0, h = 0; public void stop() { wii.stop(); super.stop(); } double roll0 = 0, roll1 = 0, pitch0 = 0, pitch1 = 0; public void render(Graphics g) { if (w == 0) { w = bounds().width; h = bounds().height; wii = new Wii(); } wii.update(); g.setColor(Color.white); g.fillRect(0,0,w,h); g.setColor(Color.black); roll0 = 0.9 * roll0 + 0.1 * wii.getRoll(0); pitch0 = 0.9 * pitch0 + 0.1 * wii.getPitch(0); roll1 = 0.9 * roll1 + 0.1 * wii.getRoll(1); pitch1 = 0.9 * pitch1 + 0.1 * wii.getPitch(1); int wx1 = 100 - (int)(100*roll0), wy1 = 200 - (int)(100*pitch0); int wx2 = 300 - (int)(100*roll1), wy2 = 200 - (int)(100*pitch1); drawWii(g, 0, wx1, wy1); drawWii(g, 1, wx2, wy2); animating = true; } Color color[] = {Color.gray, Color.green, Color.red, Color.blue}; void drawWii(Graphics g, int n, int wx, int wy) { g.drawRoundRect(wx, wy, 50, 200, 20, 20); g.drawRoundRect(wx, wy, 50, 200, 20, 20); drawWiiButton(g, n, wx, wy, Wii.A, "A"); drawWiiButton(g, n, wx, wy, Wii.B, "B"); drawWiiButton(g, n, wx, wy, Wii.D, "Down"); drawWiiButton(g, n, wx, wy, Wii.H, "Home"); drawWiiButton(g, n, wx, wy, Wii.L, "Left"); drawWiiButton(g, n, wx, wy, Wii.M, "Minus"); drawWiiButton(g, n, wx, wy, Wii.O, "One"); drawWiiButton(g, n, wx, wy, Wii.P, "Plus"); drawWiiButton(g, n, wx, wy, Wii.R, "Right"); drawWiiButton(g, n, wx, wy, Wii.T, "Two"); drawWiiButton(g, n, wx, wy, Wii.U, "Up"); } void drawWiiButton(Graphics g, int n, int wx, int wy, int b, String str) { int state = wii.getState(n, b); g.setColor(color[state]); g.drawString(str, wx + 8, wy + 20 + 15 * b); if (state == 2) g.drawString(str, wx + 9, wy + 20 + 15 * b); } }