簡體   English   中英

Java Processing 2.0(使用Eclipse):從窗口切換到全屏和后退

[英]Java Processing 2.0 (Using Eclipse) : Switching from window to fullscreen and back

我在Eclipse中使用Processing 2.0並且對於正在運行的應用程序的窗口模式和全屏幕之間的轉換有疑問(在啟動時不選擇窗口或全屏,這很容易解決)。

此問題解決了從Java Processing中的全屏模式進入窗口模式的問題。

但是,我還想知道如何使用Processing從窗口模式轉換回全屏模式。 有沒有人有這個問題的解決方案?

有點hacky,但你可以嘗試創建一個單獨的AWT框架,它是全屏幕,並將Processing的applet放入其中。 通常對於全屏,你應該只需要一個屏幕尺寸的框架,沒有裝飾(標題欄,關閉按鈕等)。抓住你不能“設計”java.awt.Frame后設置為可見(甚至如果你將可見性設置為false,則嘗試進行不裝飾,然后再次使框架可見),所以要解決這個問題只需要一個單獨的Frame實例,它已經未修飾,並且具有正確的尺寸,我們將處理框架的內容放入其中。 我們還需要告訴處理邊界是否更新。

這是一個快速草圖來說明這個想法(按'f'表示全屏):

import java.awt.Frame;
Frame fullScreenFrame;
void setup(){
  fullScreenFrame = new  Frame();
  fullScreenFrame.setUndecorated(true);//prepare an undecorated fullscreen frame since java won't allow you to 'undecorate' a frame after it's been set visible 
  fullScreenFrame.setBounds(0,0,displayWidth,displayHeight);
  fullScreenFrame.addKeyListener(getKeyListeners()[0]);//pass key events from this applet to the fullScreen Frame
}
void draw(){
  background((float)mouseX/width * 255,(float)mouseY/height * 255,0);
}
void keyReleased(){
  if(key == 'f') {
      setBounds(0,0,displayWidth,displayHeight);//resize the skech
      fullScreenFrame.add(frame.getComponent(0));//add the applet to the fullscreen frame from Processing's frame
      fullScreenFrame.setVisible(true);//make our fullscreen frame visible
      frame.setVisible(false );//and hide Processing's frame
   }
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM