本文整理汇总了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");
}
示例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){}
}
}
示例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);
}
});
}
示例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);
}
});
}
示例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);
}
}
});
}
示例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");
}
示例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"
+ "}");
}
示例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();
}
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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());
}
});
}
}
示例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);
}
}
示例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() {
}
};
}
}
示例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();
}
}
}
);
}