Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes full-screen gray window problem and event handling problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "full-screen gray window problem and event handling problem" Watch "full-screen gray window problem and event handling problem" New topic
Author

full-screen gray window problem and event handling problem

Peter Karp
Greenhorn

Joined: May 18, 2006
Posts: 6
Hi,

I want to show a fullscreen color and draw some lines. The program should work on Windows _and_ OS X. So I can not just set the window to the screen size. This will work on Windows, but not on OS X where the menu bar and dock will still be visible.

I came up with the following little program which compiles fine, but shows a gray window shortly after the correct blue window is painted. Also the event handling will not work and I don't see an error. Pressing SPACE should exit the program, but doesn't.

Looking forward any pointers.

Here's the sample source:

// ------- source full-screen begin --------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FullScreen implements KeyListener
{

public void keyTyped(KeyEvent event) {}
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_SPACE)
{
System.exit(0);
}
}

public void go() {
JWindow window = new JWindow();
window.setVisible(true);
window.addKeyListener(this);
window.setBackground(Color.BLUE);
window.setForeground(Color.WHITE);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(window);
}

public void paint (Graphics g) {
g.setColor(Color.WHITE);
g.drawString("Hello, World!", 50, 50);
g.drawLine(0, 1000, 500, 0);
}

public static void main(String[] args)
{
FullScreen f = new FullScreen();
f.go();
}
}
//-------- source end -------------

Thanks for your input.
Peter
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Also the event handling will not work and I don't see an error.
> Pressing SPACE should exit the program, but doesn't.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Window.html

scroll down to
isFocusableWindow()

(URL tags won't accept direct link)
Peter Karp
Greenhorn

Joined: May 18, 2006
Posts: 6
Thanks for your hint regarding "isFocusableWindow". That helped me so far that now I have the event handling working and the blue filled full-screen is shown correct. I changed the JWindow to a JPanel in a JFrame.

But one problem still remains. Now the paint() method shows no effect!? I try to write a text and to draw a line on the fullscreen window, but the text and line does not show up. I still don't see the error in my code :-(

Shouldn't paint() automaticly be called (passive rendering) when I override it.

Here's the updated source:

// ------- source full-screen begin --------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FullScreen implements KeyListener
{

public void keyTyped(KeyEvent event) {}
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_SPACE)
{
System.exit(0);
}
}

public void go() {
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setVisible(true);
frame.addKeyListener(this);
System.out.println(frame.isFocusableWindow());
frame.setFocusableWindowState(true);
JPanel panel = new JPanel();
frame.add(panel);
panel.setBackground(Color.BLUE);
panel.setForeground(Color.WHITE);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
}

public void paint (Graphics g) {
g.setColor(Color.WHITE);
g.drawString("Hello, World!", 50, 50);
g.drawLine(0, 1000, 500, 0);
}

public static void main(String[] args)
{
FullScreen f = new FullScreen();
f.go();
}
}
//-------- source end -------------

a second try was also not succesull.

// ------- source full-screen begin --------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FullScreen extends JPanel implements KeyListener
{

public void paintComponent (Graphics g) {
g.setColor(Color.WHITE);
g.drawString("Hello, World!", 50, 50);
g.drawLine(0, 1000, 500, 0);
}
public void keyTyped(KeyEvent event) {}
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_SPACE)
{
System.exit(0);
}
}

public void go() {
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setVisible(true);
frame.addKeyListener(this);
System.out.println(frame.isFocusableWindow());
frame.setFocusableWindowState(true);
JPanel panel = new JPanel();
frame.add(panel);
panel.setBackground(Color.BLUE);
panel.setForeground(Color.WHITE);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
}


public static void main(String[] args)
{
FullScreen f = new FullScreen();
f.go();
}
}
//-------- source end -------------

Best regards
Peter
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
compare your to this, compare the differences

 
 
subject: full-screen gray window problem and event handling problem