Java Code Examples for javax.swing.JFrame#getFrames()

The following examples show how to use javax.swing.JFrame#getFrames() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static Frame findActiveFrame() {
  Frame[] frames = JFrame.getFrames();
  for (Frame frame : frames) {
    if (frame.isVisible())
      return frame;
  }
  return null;
}
 
Example 2
private Frame findActiveFrame() {
  Frame[] frames = JFrame.getFrames();
  for (int i = 0; i < frames.length; i++) {
    if (frames[i].isVisible()) {
      return frames[i];
    }
  }
  return null;
}
 
Example 3
/**
 * The main entry point.
 * @param args arguments
 */
public static void main(String[] args) {
	Set<String> argset = new LinkedHashSet<>(Arrays.asList(args));
	long maxMem = Runtime.getRuntime().maxMemory();
	if (maxMem < MINIMUM_MEMORY * 1024 * 1024 * 95 / 100) {
		if (!argset.contains("-memonce")) {
			if (!doLowMemory(argset)) {
				doWarnLowMemory(maxMem);
			}
			return;
		}
	}
	final Configuration config = new Configuration("open-ig-config.xml");
	Func0<String> languageFn = new Func0<String>() {
		@Override
		public String invoke() {
			return config.language;
		}
	};
	Func0<String> onCrash = new Func0<String>() {
		@Override
		public String invoke() {
			for (Frame f : JFrame.getFrames()) {
				if (f instanceof GameWindow) {
					GameWindow gw = (GameWindow)f;
					if (gw.commons != null && gw.commons.world() != null && gw.isVisible()) {
						try {
							File file = ((GameWindow)f).saveWorld("Crash", SaveMode.MANUAL).get();
							String wd = new File(".").getAbsolutePath();
							String fp = file.getAbsolutePath();
							if (fp.startsWith(wd)) {
								return wd.substring(fp.length());
							}
							return fp;
						} catch (ExecutionException | InterruptedException ex) {
							// ignored
						}
					}
				}
			}
			return null;
		}
	};
	@SuppressWarnings("resource")
	final ConsoleWatcher cw = new ConsoleWatcher(args, 
			Configuration.VERSION,
			languageFn, 
			onCrash);
	config.watcherWindow = cw;
	config.crashLog = new Func0<String>() {
		@Override
		public String invoke() {
			return cw.getCrashLog();
		}
	};
	config.load();

	Set<String> langCodes = U.newSet(
			"hu", "en", "de", "fr", "ru", "es");

	for (String lc : langCodes) {
		if (argset.contains("-" + lc)) {
			config.language = lc;
			break;
		}
	}
	if (argset.contains("-maximized")) {
		config.maximized = true;
	}
	if (argset.contains("-fullscreen")) {
		config.fullScreen = true;
	}
	if (argset.contains("-fullscreenvideos")) {
		config.movieScale = true;
	}
	if (argset.contains("-clickskip")) {
		config.movieClickSkip = true;
	}
	if (argset.contains("-noclickskip")) {
		config.movieClickSkip = false;
	}
	if (argset.contains("-continue")) {
		config.continueLastGame = true;
	}

	doStartGame(config);
}