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

The following examples show how to use javax.swing.JFrame#getFrames() . 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
Source File: ScreenUtils.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Frame findActiveFrame() {
  Frame[] frames = JFrame.getFrames();
  for (Frame frame : frames) {
    if (frame.isVisible())
      return frame;
  }
  return null;
}
 
Example 2
Source File: ExceptionDialog.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: Startup.java    From open-ig with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}