Advertisement
jcdj1996

final03 class

Feb 7th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. package com.jcdj1996.final03;
  2.  
  3. import javax.swing.JOptionPane;
  4. import lejos.nxt.Sound;
  5. import com.centralnexus.input.*;
  6.  
  7. public class final03 implements JoystickListener{
  8.     Joystick j1;
  9.     Robot r1 = new Robot();
  10.     MyPanel p1 = new MyPanel();
  11.     static Display d1 = new Display();
  12.     MoveSet m1 = new MoveSet();
  13.     static int angle;
  14.     static int speed;
  15.     public static boolean JStickAvail = true;
  16.     public final03(){
  17.         d1.init();
  18.         r1.init();
  19.         try{
  20.              j1 = Joystick.createInstance();    //get first avail JStick
  21.              j1.addJoystickListener(this);
  22.              j1.setPollInterval(200);
  23.              j1.setDeadZone(0.15);
  24.         }catch(Exception e){
  25.             JOptionPane.showMessageDialog(null,"No Joystick Found.");
  26.             JStickAvail = false;
  27.         }
  28.        
  29.        
  30.     }
  31.     public static void main(String[] args) {
  32.         @SuppressWarnings("unused")
  33.         final03 g1 = new final03();
  34.     }
  35.  
  36.     public void joystickAxisChanged(Joystick e) {
  37.        
  38.         if(angle!=(int)(e.getX()*10)&&m1.f8==false)
  39.         {
  40.             angle = (int)(e.getX()*10);
  41.             r1.turn(angle);
  42.             System.out.println(e.getX()*30);
  43.             MyPanel.xpos=(int) (e.getX()*30)+45;
  44.         }
  45.         if(speed!=(int)(e.getY()*720)&&m1.f8==false)
  46.         {
  47.             speed = (int)(e.getY()*900);    //degrees per second
  48.             r1.setSpeed(speed);
  49.             MyPanel.ypos=(int) (e.getY()*30)+45;
  50.         }
  51.     }
  52.  
  53.     public void joystickButtonChanged(Joystick j) {
  54.         if(j.isButtonDown(1))   //trigger
  55.         {
  56.             r1.fire();  //fire
  57.         }
  58.         if(j.isButtonDown(6))   //top middle button
  59.         {
  60.             Sound.playTone(500, 500);   //play horn
  61.             System.out.println("beep");
  62.         }
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement