//************************************************************* // Java application // 「FullScreenTest2」 // //          作 成 者:ルート高菜    //          作成開始月:2007/1 //          最終更新月:2007/1 [TN097/J87] //************************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreenTest2 extends JPanel implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; public static void main(String[] args) { JFrame frame=new JFrame("FullScreenTest2"); //メインクラスであるパネルを、フレームに載せる //フレーム自身をパネルに渡して保持させる frame.getContentPane().add(new FullScreenTest2(frame)); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //右上×印で終了 frame.setSize(700,300); frame.setVisible(true); frame.setLocationRelativeTo(null); //画面の真ん中に表示 } // JButton fullSizeButton=new JButton("サイズ指定でFullScreen実行・解除"); JButton fullSysGoButton=new JButton("システムでFullScreen実行"); JButton fullSysBackButton=new JButton("システムでFullScreen解除"); // JFrame frame; //通常のフレーム表示で使用する JWindow window; //フルスクリーンで使用する // public FullScreenTest2(JFrame frame){ this.frame=frame; // setLayout(new FlowLayout()); add(fullSizeButton); add(fullSysGoButton); add(fullSysBackButton); // fullSysBackButton.setEnabled(false); // fullSizeButton.addActionListener(this); fullSysGoButton.addActionListener(this); fullSysBackButton.addActionListener(this); //コントロールの動作確認(JWindow上ではJTextFieldなどが、なぜか編集不可になる) add(new JLabel("  以下は各Controlの動作テスト")); add(new JCheckBox("test")); add(new JRadioButton("test")); add(new JComboBox(new String[]{"one","two","three"})); add(new JList(new String[]{"one","two","three"})); add(new JTextField("test",5)); add(new JPasswordField("test",5)); add(new JTextArea("test",3,3)); } //真ん中に、現在のパネルのサイズを表示 public void paintComponent(Graphics g){ Dimension dim=getSize(); g.drawString("Width="+dim.width,(int)dim.width/2,(int)dim.height/2); g.drawString("Height="+dim.height,(int)dim.width/2,(int)dim.height/2+15); } // public void actionPerformed(ActionEvent e) { if(e.getSource()==fullSizeButton){ //***サイズを求めてフルスクリーンにする if(frame.isVisible()){ //パネルがJFrameに載っている(フルスクリーンではない)場合 //スクリーンのサイズを取得 Dimension dim=frame.getToolkit().getScreenSize(); // //JFrameを非表示にして、パネルをJFrameから外す frame.setVisible(false); frame.getContentPane().remove(this); //JWindowを新しく作り、パネルを載せて、フルスクリーンで表示する window=new JWindow(); window.setBounds(0,0,dim.width,dim.height); window.getContentPane().add(this); window.setVisible(true); // window.toFront(); //これをしないとタスクバーが消えない // fullSysGoButton.setEnabled(false); }else{ //パネルがJWindow載っている(フルスクリーンになっている)場合 //JWindowからパネルを外して、JWindowを破棄する window.getContentPane().remove(this); window.dispose(); //非表示にしていたJFrameにパネルを載せて、表示させる frame.getContentPane().add(this); frame.setVisible(true); // fullSysGoButton.setEnabled(true); } }else if(e.getSource()==fullSysGoButton){ //***GraphicsDeviceを使ってフルスクリーンにする //その環境で利用可能なグラフィックデバイスを取得 GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // if(device.isFullScreenSupported()){ //JFrameを非表示にして、パネルをJFrameから外す frame.setVisible(false); frame.getContentPane().remove(this); //JWindowを新しく作り、パネルを載せて、フルスクリーンで表示する window=new JWindow(); window.getContentPane().add(this); device.setFullScreenWindow(window); //このフレームをフルスクリーンに /*これでは上手くいかない try{ device.setFullScreenWindow(window); //このフレームをフルスクリーンに }finally{ device.setFullScreenWindow(null); //不正終了したら元に戻るように } */ window.setVisible(true); // fullSizeButton.setEnabled(false); fullSysGoButton.setEnabled(false); fullSysBackButton.setEnabled(true); }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } }else if(e.getSource()==fullSysBackButton){ //***GraphicsDeviceを使ったフルスクリーンを解除する //その環境で利用可能なグラフィックデバイスを取得 GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // if(device.isFullScreenSupported()){ device.setFullScreenWindow(null); //フルスクリーンを解除 //JWindowからパネルを外して、JWindowを破棄する window.getContentPane().remove(this); window.dispose(); //非表示にしていたJFrameにパネルを載せて、表示させる frame.getContentPane().add(this); frame.setVisible(true); // fullSizeButton.setEnabled(true); fullSysGoButton.setEnabled(true); fullSysBackButton.setEnabled(false); }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } } } }