当前位置: 首页>>代码示例>>Java>>正文


Java Runnable类代码示例

本文整理汇总了Java中java.lang.Runnable的典型用法代码示例。如果您正苦于以下问题:Java Runnable类的具体用法?Java Runnable怎么用?Java Runnable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Runnable类属于java.lang包,在下文中一共展示了Runnable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.lang.Runnable; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            try {
                JTextField textField = new JTextField(15);
                textField.setText("ม12345");
                float noSpaceMin = textField.getUI().getRootView(textField)
                        .getMinimumSpan(0);
                textField.getDocument().insertString(3, " ", null);
                if (noSpaceMin > textField.getUI().getRootView(textField)
                        .getMinimumSpan(0)) {
                    throw new RuntimeException(
                            "Minimum span is calculated for wrapped text");
                }
            } catch (BadLocationException e) {
                throw new RuntimeException(e);
            }
        }
    });
    System.out.println("ok");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:23,代码来源:I18NViewNoWrapMinSpan.java

示例2: begin

import java.lang.Runnable; //导入依赖的package包/类
public void begin()
{
	while (running)
	{
		synchronized (tasks)
		{
			int count = tasks.size();
			while (count < 10)
			{
				count++;

				Runnable task = taskMaster.buildNextTask();

				if (task == null)
					break;

				tasks.add(task);
			}
		}

		try { Thread.sleep(1);
		}catch(Exception exception){}
	}
}
 
开发者ID:TheDudeFromCI,项目名称:Project-Sarica-v3,代码行数:25,代码来源:ThreadOwner.java

示例3: manualTurnScreenOff

import java.lang.Runnable; //导入依赖的package包/类
private void manualTurnScreenOff() {
    Log.d(TAG, "manualTurnScreenOff()");
    UiThreadUtil.runOnUiThread(new Runnable() {
        public void run() {
            Activity mCurrentActivity = getCurrentActivity();
            if (mCurrentActivity == null) {
                Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
                return;
            }
            Window window = mCurrentActivity.getWindow();
            WindowManager.LayoutParams params = window.getAttributes();
            lastLayoutParams = params; // --- store last param
            params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF; // --- Dim as dark as possible. see BRIGHTNESS_OVERRIDE_OFF
            window.setAttributes(params);
            window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    });
}
 
开发者ID:zxcpoiu,项目名称:react-native-incall-manager,代码行数:19,代码来源:InCallManagerModule.java

示例4: manualTurnScreenOn

import java.lang.Runnable; //导入依赖的package包/类
private void manualTurnScreenOn() {
    Log.d(TAG, "manualTurnScreenOn()");
    UiThreadUtil.runOnUiThread(new Runnable() {
        public void run() {
            Activity mCurrentActivity = getCurrentActivity();
            if (mCurrentActivity == null) {
                Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
                return;
            }
            Window window = mCurrentActivity.getWindow();
            if (lastLayoutParams != null) {
                window.setAttributes(lastLayoutParams);
            } else {
                WindowManager.LayoutParams params = window.getAttributes();
                params.screenBrightness = -1; // --- Dim to preferable one
                window.setAttributes(params);
            }
            window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    });
}
 
开发者ID:zxcpoiu,项目名称:react-native-incall-manager,代码行数:22,代码来源:InCallManagerModule.java

示例5: setKeepScreenOn

import java.lang.Runnable; //导入依赖的package包/类
@ReactMethod
public void setKeepScreenOn(final boolean enable) {
    Log.d(TAG, "setKeepScreenOn() " + enable);
    UiThreadUtil.runOnUiThread(new Runnable() {
        public void run() {
            Activity mCurrentActivity = getCurrentActivity();
            if (mCurrentActivity == null) {
                Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
                return;
            }
            Window window = mCurrentActivity.getWindow();
            if (enable) {
                window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            } else {
                window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            }
        }
    });
}
 
开发者ID:zxcpoiu,项目名称:react-native-incall-manager,代码行数:20,代码来源:InCallManagerModule.java

示例6: varargs

import java.lang.Runnable; //导入依赖的package包/类
@Test
public void varargs()
        throws Exception
{
    TypeSpec taqueria = TypeSpec.classBuilder("Taqueria")
            .addMethod(MethodSpec.methodBuilder("prepare")
                    .addParameter(int.class, "workers")
                    .addParameter(Runnable[].class, "jobs")
                    .varargs()
                    .build())
            .build();
    assertThat(toString(taqueria)).isEqualTo(""
            + "package com.squareup.tacos;\n"
            + "\n"
            + "import java.lang.Runnable;\n"
            + "\n"
            + "class Taqueria {\n"
            + "  void prepare(int workers, Runnable... jobs) {\n"
            + "  }\n"
            + "}\n");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:22,代码来源:TestTypeSpec.java

示例7: anonymousClassToString

import java.lang.Runnable; //导入依赖的package包/类
@Test
public void anonymousClassToString()
        throws Exception
{
    TypeSpec type = TypeSpec.anonymousClassBuilder("")
            .addSuperinterface(Runnable.class)
            .addMethod(MethodSpec.methodBuilder("run")
                    .addAnnotation(Override.class)
                    .addModifiers(Modifier.PUBLIC)
                    .build())
            .build();
    assertThat(type.toString()).isEqualTo(""
            + "new java.lang.Runnable() {\n"
            + "  @java.lang.Override\n"
            + "  public void run() {\n"
            + "  }\n"
            + "}");
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:19,代码来源:TestTypeSpec.java

示例8: methodWithParcelableParam

import java.lang.Runnable; //导入依赖的package包/类
@Override
public <T extends Runnable & Parcelable> void methodWithParcelableParam(T parcelable) throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(MethodTypeargParcelable$$AidlServerImpl.DESCRIPTOR);

        data.writeParcelable(parcelable, 0);

        delegate.transact(MethodTypeargParcelable$$AidlServerImpl.TRANSACT_methodWithParcelableParam, data, reply, 0);
        reply.readException();
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
开发者ID:chdir,项目名称:aidl2,代码行数:17,代码来源:MethodTypeargParcelable$$AidlClientImpl.java

示例9: test

import java.lang.Runnable; //导入依赖的package包/类
public int test() {
  
  System.out.println("before");

  run(new Runnable() {
    @Override
    public void run() {
      System.out.println("Runnable");
    }
  });

  test2("1");

  if(Math.random() > 0) {
    System.out.println("0");
    return 0;
  } else {
    System.out.println("1");
    return 1;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:TestClassSimpleBytecodeMapping.java

示例10: resetSystemUiVisibility

import java.lang.Runnable; //导入依赖的package包/类
public static void resetSystemUiVisibility(){
	Handler handler = new Handler();
	Runnable runnable = new Runnable(){
		public void run() {
			if(currentMode == null) return;
			if(currentMode.equals("lowProfile")) {
				_setLowProfile();
			} else if(currentMode.equals("immersive")) {
				_setImmersive();
			} else if(currentMode.equals("statusBarColor")) {
				_setStatusBarColor(-1);
			}
		}
	};
	handler.postDelayed(runnable, DELAY_TIME);
}
 
开发者ID:HaxeExtension,项目名称:extension-android-immersive,代码行数:17,代码来源:AndroidImmersive.java

示例11: onOptionsItemSelected

import java.lang.Runnable; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection.
    switch (item.getItemId()) {
        case R.id.stop:
            // Stop the service at the end of the message queue for proper options menu
            // animation. This is only needed when starting a new Activity or stopping a Service
            // that published a LiveCard.
            post(new Runnable() {

                @Override
                public void run() {
                    stopService(new Intent(MenuActivity.this, StopwatchService.class));
                }
            });
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
开发者ID:giantbunny,项目名称:testfile,代码行数:21,代码来源:MenuActivity.java

示例12: scrollListViewToTaggedView

import java.lang.Runnable; //导入依赖的package包/类
private void scrollListViewToTaggedView(String tag) {
    final ListView listview = (ListView) findViewById(R.id.event_listview);
    final Integer index = idToViewIndexMap.get(tag);
    if (index != null) {
        View rowView = listview.getChildAt(index.intValue());
        int h1 = listview.getHeight();
        int h2 = 0;
        if (rowView != null) {
            h2 = rowView.getHeight();
        }
        final int h = h1/2 - h2/2;
        runOnUiThread(new Runnable() {
            public void run() {
                listview.smoothScrollToPositionFromTop(index.intValue(), 0, 300);
                listview.setSelection(index.intValue());
            }
        });
    }
}
 
开发者ID:hkkenneth,项目名称:charity-android,代码行数:20,代码来源:MainActivity.java

示例13: onOptionsItemSelected

import java.lang.Runnable; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection.
    switch (item.getItemId()) {
        case R.id.stop:
            // Stop the service at the end of the message queue for proper options menu
            // animation. This is only needed when starting a new Activity or stopping a Service
            // that published a LiveCard.
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    stopService(new Intent(MenuActivity.this, MapService.class));
                    setResult(RESULT_OK);
                    finish();
                }
            });
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
开发者ID:Esri,项目名称:arcgis-runtime-demos-android,代码行数:23,代码来源:MenuActivity.java

示例14: foo

import java.lang.Runnable; //导入依赖的package包/类
public void foo() {
  Runnable r = new Runnable() {
    @Override
    public void run() {
      Comparable<Integer> c = new Comparable<Integer>() {
        @Override
        public int compareTo(Integer o) {
          return 0;
        }
      };
    }
  };
  
  class FooLocal {
    Runnable r = new Runnable() {
      @Override
      public void run() {
      }
    };
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:ManyClasses.java

示例15: retrievePurchases

import java.lang.Runnable; //导入依赖的package包/类
static public void retrievePurchases()
{
	GameActivity.getInstance().runOnUiThread
	(
		new Runnable()
		{ 
			public void run() 
			{
				try
				{
				singleton.mHelper.queryInventoryAsync(singleton.mGotInventoryListener); 
				}
				catch(IllegalStateException ex){
					singleton.mHelper.flagEndAsync();
				}
			}
		}
	);
}
 
开发者ID:CharcoalStyles,项目名称:GooglePlayServices-OpenFL,代码行数:20,代码来源:GameActivity.java


注:本文中的java.lang.Runnable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。