//************************************************************* // Java application // 「FullScreenTest」 // //          作 成 者:ルート高菜    //          作成開始月:2007/1 //          最終更新月:2007/1 [TN095/J85] //************************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreenTest extends JFrame implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; public static void main(String[] args) { FullScreenTest frame=new FullScreenTest(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //右上×印で終了 frame.setVisible(true); frame.setLocationRelativeTo(null); //画面の真ん中に表示 } // //その環境で利用可能なグラフィックデバイス GraphicsDevice device; // JButton changeButton=new JButton("切り替え"); // public FullScreenTest(){ setTitle("FullScreenTest"); setSize(300,200); //グラフィックデバイスを取得 device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // JPanel panel=new JPanel(); panel.setLayout(new FlowLayout()); panel.add(changeButton); //コンテナ枠 Container cp=getContentPane(); cp.add(panel,BorderLayout.CENTER); // changeButton.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==changeButton){ if(device.isFullScreenSupported()){ if(device.getFullScreenWindow()==this){ //既にフルスクリーン device.setFullScreenWindow(null); //フルスクリーンを解除 validate(); //ボタン配置しなおすのに必要(フルスクリーン解除では必要になるらしい) }else{ device.setFullScreenWindow(this); //このフレームをフルスクリーンに /*これでは上手くいかない try{ device.setFullScreenWindow(this); //このフレームをフルスクリーンに }finally{ device.setFullScreenWindow(null); //不正終了したら元に戻るように } */ } }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } } } }