java full screen help

i was reading in sun webpage about java full screen api...i dont think its clear enough and i think it have good examples...

so i tried to practice a bit and tried something wich didnt work

import javax.swing.*;

import java.awt.*;

publicclass FullScreenextends JFrame{

static GraphicsDevice gd;

public FullScreen(){

}

publicstaticvoid main(String[] args){

FullScreen fc =new FullScreen();

try{

gd.setFullScreenWindow(fc);

fc.setVisible(true);

fc.setResizable(false);

fc.setUndecorated(true);

}finally{

gd.setFullScreenWindow(null);

}

}

}

iy gives nullpointer exception , can someone help me, im new in programming, is there is any more info on the web coz as i said before i dont think sun's tutorials are good

[1667 byte] By [fouadka] at [2007-10-3 4:09:58]
# 1

You don't assign to gd anywhere, so it's null. Add GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();

gd=ge.getDefaultScreenDevice();

The next problem is that you set fc undecorated after setting it visible, which won't work. So you want import javax.swing.*;

import java.awt.*;

public class FullScreen extends JFrame {

static GraphicsDevice gd;

public FullScreen() {

}

public static void main(String[] args) {

FullScreen fc = new FullScreen();

try{

GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();

gd=ge.getDefaultScreenDevice();

fc.setUndecorated(true);

gd.setFullScreenWindow(fc);

fc.setVisible(true);

fc.setResizable(false);

}finally{

gd.setFullScreenWindow(null);

}

}

}

Of course, it will flicker into full screen and then out again because the finally block will be executed. You'll want to remove the finally block and provide some way for the user to leave full screen mode or exit the program entirely.

YAT_Archivista at 2007-7-14 22:10:08 > top of Java-index,Java Essentials,Java Programming...
# 2
thnx for the help...thats all i needed...thanks again
fouadka at 2007-7-14 22:10:08 > top of Java-index,Java Essentials,Java Programming...
# 3

i tries the code but i still have some minor problems, i still cant get into full screen and the button doesnt show

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class FullScreen extends JFrame implements ActionListener {

static GraphicsDevice gDevice;

public void setUpFullScreenMode() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

setBounds(10, 10, 500, 400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel p = new JPanel();

p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

JButton b1 = new JButton("exit");

b1.addActionListener(this);

getContentPane().add(p);

p.add(b1);

}

public static void main(String[] args) {

FullScreen fc = new FullScreen();

GraphicsEnvironment gEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();

gDevice = gEnvironment.getDefaultScreenDevice();

fc.setUndecorated(false);

gDevice.setFullScreenWindow(fc);

fc.setVisible(true);

fc.setResizable(false);

}

/**

* Invoked when an action occurs.

*/

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equalsIgnoreCase("exit")) {

System.exit(0);

}

}

}

fouadka at 2007-7-14 22:10:08 > top of Java-index,Java Essentials,Java Programming...
# 4
Maybe you should call setUpFullScreenMode() before setFullScreenWindow. In my box, it's ok.
itsafeia at 2007-7-14 22:10:08 > top of Java-index,Java Essentials,Java Programming...
# 5
If you need help then search the forums before posting questions.And search the Swing forum, which is where this posting should have been made to begin with.
camickra at 2007-7-14 22:10:08 > top of Java-index,Java Essentials,Java Programming...