import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class testFullWindow {
JButton bt = new JButton("全屏");
JFrame f = new JFrame();
public testFullWindow(){
f.setUndecorated(true);
f.setSize(400, 300);
f.setLayout(new FlowLayout());
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
GraphicsDevice myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice();
//不显示任务栏
myDevice.setFullScreenWindow(f);
//f.setUndecorated(true);
//下面可以显示任务栏
//DisplayMode dm=myDevice.getDisplayMode();
//
//f.setBounds(0,0,dm.getWidth(),dm.getHeight());
//f.show();
}
});
f.add(bt);
f.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new testFullWindow();
}
}

该程序可以直接运行。关键代码是:

JFrame f = new JFrame();
GraphicsDevice myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice();      //不显示任务栏     myDevice.setFullScreenWindow(f);