⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bouncingtrial.java

📁 多线程活动球java 程序,便于理解Multi-Threaded 的功能.
💻 JAVA
字号:
import java.awt.Color;
import java.awt.Point;


public class BouncingTrial
{
    public static final int LEFT_SHIFT_RESP = 1;		// Left Shift Response
    public static final int RIGHT_SHIFT_RESP = 2;		// Right Shift Response
    public static final int LEFT_TRIAL = 1;				// Left Trial Type
    public static final int RIGHT_TRIAL = 2;			// Right Trial Type
    public static final int STRAIGHT_TRIAL = 3;			// Straight Trial Type 
    
    int
    	nWidth,			// Canvas Width
    	nHeight,		// Canvas Height
        nBottomEdgeY = 0,		// Y Boundary for Ball to Disappear
        nDx =0,                 // X Incremental
        nDy =0 ,                // Y Incremental
        inRadius,				// Initial Radius
        endRadius,				// End Radius
        frameDuration,			// Frame Duration in milliseconds
        nDeltaDis,				// Incremental Distance
        nDev =0 ,               // Deviation in Degree
        nTrialType = -1,        //  left or right or straight
        nResponse = -1;              // Key Response 
    
    Color 
    	ballColor,				// Ball Color
    	bgColor;				// Background Color
    long
        lResponseTime=0;          // Response Time
    
    Point
        p1,                     // Starting Point
        p2;                     // Middle Point
  
    /*
     * TrialType	Deviation IniRadius	EndRadius	BallColor	BgColor 	FrameDuration 	DeltaDistance Width Height
     */
     public BouncingTrial(   int nTrialType,     // Left or Right Trial
                            int nDev,           // Deviation in Angle
                            int inRadius,		// Initial Radius
                            int endRadius,		// End Radius
                            Color ballColor,	// Ball Color
                            Color bgColor,		// Background Color
                            int frameDuration,	// Frame Duration in milliseconds
                            int nDeltaDis,		// Incremental Distance
                            int nWidth,			// Canvas Width
                            int nHeight,		// Canvas Height
                            Point p1,           // Starting Point
                            Point p2,           // Middle Point
                            int bottomEdgeY)    // Y Boundary at Bottom
    {
    	
    	// Initialize varaibles
        this.nTrialType = nTrialType;
        this.nDev = nDev;
        
        
        this.inRadius = inRadius;		
        this.endRadius = endRadius; 	
        this.ballColor = ballColor;
        this.bgColor = bgColor;
        this.frameDuration = frameDuration ;
        this.nDeltaDis = nDeltaDis;
        
        this.nWidth = nWidth;
        this.nHeight = nHeight;
        
        this.p1 = new Point(p1);
        this.p2 = new Point(p2);
        this.nBottomEdgeY = bottomEdgeY;
        
        // calculate Dx and Dy
        calDxAndDy();
    }// End BouncingTrial Construtor
    
    public int getWidth()
    {
    	return this.nWidth;
    }
    
    public int getHeight()
    {
    	return this.nHeight;
    }
    
    public int getIniRadius()
    {
    	return this.inRadius;
    }
    
    public int getEndRadius()
    {
    	return endRadius;
    }
    
    public Color getBallColor()
    {
    	return ballColor;
    }
    
    public Color getBgColor()
    {
    	return bgColor;
    }
    
    public int getFrameDuration()
    {
    	return frameDuration;
    }
    
    
    
    public int getTrialType()
    {
    	return this.nTrialType;
    }
    
        
    public int getBottomY()
    {
        return this.nBottomEdgeY;
    }
    
    public void setResponse(int nKeyResp)
    {
        if(nKeyResp == LEFT_SHIFT_RESP ) 
        {
            nResponse = LEFT_SHIFT_RESP;
        }
        else if(nKeyResp == RIGHT_SHIFT_RESP ) 
        {
            nResponse = RIGHT_SHIFT_RESP;
        }
        else
        {
            nResponse = -1;
        }
        return;
    }
    
    public int getReponse()
    {
       return nResponse;
    }
    
    public void setResponseTime(long lTime)
    {
        lResponseTime = lTime;
    }
    
    public long getResponseTime()
    {
       return lResponseTime;
    }
        
      
    public Point getP1()
    {
        return p1;
    }
    
    public Point getP2()
    {
        return p2;
    }
            
    public int getDev()
    {
        return nDev;
    }
    
    public int getIncrementDis()
    {
        return nDeltaDis;
    }
          
    //  calculate incrmentals
    public void calDxAndDy()
    {
        double
            angleInRadian = Math.toRadians(nDev);
        
        nDx =   (int) ( Math.sin(angleInRadian)* nDeltaDis);
        nDy =   (int) ( Math.cos(angleInRadian)* nDeltaDis);
                       
        if(nTrialType == LEFT_TRIAL)       //  ball landing on the left side 
        {
            nDx = -nDx;
        }
            
        return;
    }// End calIncrementals
    
    public int getDx()
    {
        return nDx;
    }
    
    public int getDy()
    {
        return nDy;
    }
    
    public String toString()
    {
    	String
    		str = "";
    	
    	str = str + "Trial Type: " + nTrialType +"\n";
    	str = str + "Deviation: " + nDev + "\n";
    	str = str + "Initial Radius: " + inRadius +"\n";
    	str = str + "End Radius: " + endRadius + "\n";
    	str = str + "Ball Color in R G B: " + ballColor.getRed() + " "  + ballColor.getGreen() + " " + ballColor.getBlue()+ "\n";
    	str = str + "Background Color in R G B: " + bgColor.getRed() + " "  + bgColor.getGreen() + " " + bgColor.getBlue()+ "\n";
        str = str + "Frame Duration: " + frameDuration + "\n";
        str = str + "Incremental Distance: " + nDeltaDis;
    	    
    	
    	return str;
    }
    
}//End BouncingTrial Class Definition

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -