在eclipse中运行处理applet

时间:2015-12-12 23:02:58

标签: java eclipse applet processing

我已从他们的官方网站下载并安装了处理IDE,然后我按照如何将库导入eclipse的说明进行操作。我将core.jar,gluegen-rt.jar和jogl-all.jar添加到路径中。我有下面的代码,我试图运行,但是当我进入运行菜单时,没有任何运行选项。我只看到'运行配置'。我有什么遗失的吗?

public class myCamera extends MainMenu{

    private ImageView mImageView;
    private Bitmap mImageBitmap;
    static final String BITMAP_STORAGE_KEY = "viewbitmap";
    static final String IMAGEVIEW_VISIBILITY_STORAGE_KEY = "imageviewvisibility";

    public static final int MEDIA_TYPE_IMAGE = 1;
    public static final int MEDIA_TYPE_VIDEO = 2;

    protected static final int ACTION_TAKE_PHOTO_B = 1;
    protected static final int ACTION_TAKE_PHOTO_S = 2;

    protected int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = MEDIA_TYPE_IMAGE;
    protected Uri fileUri;

    protected String mCurrentPhotoPath;

    protected static final String JPEG_FILE_PREFIX = "IMG_";
    protected static final String JPEG_FILE_SUFFIX = ".jpg";

    private static final String CAMERA_DIR = "/dcim/";
    protected String mAlbumName;
    protected AlbumStorageDirFactory mAlbumStorageDirFactory = null;

    protected String getAlbumName() {
        return "test";
    }

    protected String getCurrentPath(){
        return mCurrentPhotoPath;
    }

    protected void setCurrentPath(String mCurrentPhotoPath){
        this.mCurrentPhotoPath=mCurrentPhotoPath;
    }

    public File getAlbumStorageDir(String albumName) {
        return new File (
                Environment.getExternalStorageDirectory()
                + CAMERA_DIR
                + albumName
        );
    }

    private File getAlbumDir() {
        File storageDir = null;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
            mAlbumStorageDirFactory = new FroyoAlbumDirFactory();
        } else {
            mAlbumStorageDirFactory = new BaseAlbumDirFactory();
        }

        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {

            storageDir = getAlbumStorageDir(getAlbumName());

            if (storageDir != null) {
                if (! storageDir.mkdirs()) {
                    if (! storageDir.exists()){
                        Log.d("CameraSample", "failed to create directory");
                        return null;
                    }
                }
            }

        } else {
            Log.v(getString(R.string.app_name), "External storage is not mounted READ/WRITE.");
        }

        return storageDir;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_for_drawer);

        mAlbumName = getIntent().getStringExtra("AlbumName");

    }

    public myCamera(){
    }

    //save full size picture
    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";

        File storageDir = getAlbumDir();
        File image = File.createTempFile(imageFileName,JPEG_FILE_SUFFIX, storageDir);
        return image;
    }

    protected File setUpPhotoFile(String albumName, boolean ExternalStorage, Context context) throws IOException {

        mAlbumName = albumName;
        File f =null;

        if(ExternalStorage){
            f = createImageFile();
        }
        else{
            f = saveToInternalSorage(context);
        }
        // Save a file: path for use with ACTION_VIEW intents
        if(f !=null){
            mCurrentPhotoPath = f.getAbsolutePath();
        }
        return f;
    }

    private File saveToInternalSorage(Context context) throws IOException{
        ContextWrapper cw = new ContextWrapper(context);


        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = JPEG_FILE_PREFIX + "hello";
        // path to /data/data/yourapp/app_data/imageDir
        File directory = context.getDir("imageDir", Context.MODE_PRIVATE);
        File mypath=new File(directory,imageFileName + JPEG_FILE_SUFFIX);


        /*below is a bunch of options that I tried*/
        //File directory =context.getFilesDir();
        //File directory = new File(getFilesDir(),imageFileName,Context.MODE_PRIVATE);

        // Create imageDir
        //File image = File.createTempFile(imageFileName,JPEG_FILE_SUFFIX, storageDir);
        //File mypath = File.createTempFile(imageFileName,JPEG_FILE_SUFFIX, directory);
        //return image;
        return mypath;
    }       
}

1 个答案:

答案 0 :(得分:4)

自处理3起,PApplet不再延长Applet(更多信息here)。换句话说,您不能再将草图作为applet运行。

您必须重新放入main方法并将其作为应用程序运行。

如果您真的想要作为applet运行,则必须创建自己的扩展AppletJApplet的类,然后将Processing组件添加到该组中。这可能是相当复杂的,加上applet现在几乎已经死了,所以你可能会更好地部署为一个应用程序 - 甚至更好,就像使用Processing.js的JavaScript一样。

作为旁注,您不必依赖eclipse自动检测运行配置。您应该能够进入运行配置并自己创建一个。这对于这个特定情况不起作用,但是对于“幕后”的东西更加舒适并不是一个坏主意,所以这样的情况不那么令人困惑。