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

📄 bouncingpanel.java

📁 多线程活动球java 程序,便于理解Multi-Threaded 的功能.
💻 JAVA
字号:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Iterator;
import java.util.Random;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JPanel;

/*
 * Created on 22/07/2007
 */

public class BouncingPanel extends JPanel implements ActionListener 
{         
   
     /**
     * 
     */
    private static final long serialVersionUID = 1L;
     
    
    int
    	nDeltaR = 2,
    	nCurrentTrial;
     
     
    DrawingPanel
    	canvas = null;
    
    JButton
         drawButton = null;
    
    Parameter
        expProps = null;
    
    Vector<BouncingTrial> 
    	expTrials= null;
    BouncingTrial
        oTrial = null;
    
    LogFile
        outputFile = null;
    
    public BouncingPanel(	
    						LogFile outputFile,					// Output FileName String 
    						Vector<BouncingTrial> expTrials, 	// A Set of Trials
    						int width,							// Canvas Width
    						int height,							// Canvas Height
    						Color bgColor)						// Canvas Background Color	
    {   
      
       this.expTrials = expTrials;
       this.outputFile = outputFile;
       nCurrentTrial = 0;
        
        //setup GUI
        createGUI(width, height, bgColor,nDeltaR);
        // setup trials
       
        
    }//End Constructor
    
    private void createGUI(int width,int height,Color bgColor, int nDeltaR)
    {
               
        
        drawButton = new JButton("Draw");     
        drawButton.addActionListener(this);
        
        canvas = new DrawingPanel(drawButton,
                outputFile,
                expTrials, 
                width,
                height,
                bgColor,
                nDeltaR);    // Incremental Radius
        
        this.setLayout(new BorderLayout());
        this.add(canvas,BorderLayout.CENTER);
        this.add(drawButton,BorderLayout.PAGE_END);
        
        
        return;
    }//End createGUI
    
        /**
         * Write Previous Trial Result to the File
         Move to the next Trial
         */ 
       public void actionPerformed(ActionEvent arg0)
       {
    	   // run trials continuously 
    	   canvas.start();
          
        }// End actionPerformed
            
       
       public void writeTrialOutput()
       {
    	   //Write to File
    	   
           this.outputFile.write( (nCurrentTrial+1) +"\t");
           this.outputFile.write(oTrial.getReponse()+"\t");
           this.outputFile.write(oTrial.getResponseTime());
           this.outputFile.write("\n");
           
           return;
           
       }//End writeTrialOutput
    
    
   
    
}//End BouncingPanel Class Definition

⌨️ 快捷键说明

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