//************************************************************* // Java application // 「FullScreenTest5」 // //          作 成 者:ルート高菜    //          作成開始月:2009/1 //          最終更新月:2009/1 [TN120/J110] //************************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreenTest5 extends JPanel implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; public static void main(String[] args) { //フルスクリーン用フレーム JFrame frameFull=new JFrame(); frameFull.setUndecorated(true); //周囲の枠を消す //通常用フレーム JFrame frame=new JFrame("FullScreenTest5"); // //メインクラスであるパネルを、フレームに載せる //フレーム自身をパネルに渡して保持させる frame.getContentPane().add(new FullScreenTest5(frame,frameFull)); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //右上×印で終了 frame.setSize(700,300); frame.setVisible(true); frame.setLocationRelativeTo(null); //画面の真ん中に表示 } // JMenuBar menuBar=new JMenuBar(); JMenu menuSize=new JMenu("サイズ指定"); JMenuItem menuItemSize=new JMenuItem("FullScreen実行・解除"); JMenu menuSystem=new JMenu("システム"); JMenuItem menuItemSystemOn=new JMenuItem("FullScreen実行"); JMenuItem menuItemSystemOff=new JMenuItem("FullScreen解除"); // JButton fullSizeButton=new JButton("サイズ指定でFullScreen実行・解除"); JButton fullSysGoButton=new JButton("システムでFullScreen実行"); JButton fullSysBackButton=new JButton("システムでFullScreen解除"); // FrontDialog frontDialog; FrontDialog frontDialogFull; JButton dialogOn=new JButton("前面ダイアログ表示"); JButton dialogOff=new JButton("前面ダイアログ消去"); JButton fileDialogOn=new JButton("ファイル選択ダイアログ表示(システムFulScreenでは使用禁)"); // JCheckBox checkMenuBar=new JCheckBox("メニューはフルスクリーンに移さない"); // JFrame frame; //通常用フレーム JFrame frameFull; //フルスクリーン用フレーム // public FullScreenTest5(JFrame frame,JFrame frameFull){ this.frame=frame; this.frameFull=frameFull; // menuSize.add(menuItemSize); menuSystem.add(menuItemSystemOn); menuSystem.add(menuItemSystemOff); menuBar.add(menuSize); menuBar.add(menuSystem); frame.setJMenuBar(menuBar); // menuItemSystemOff.setEnabled(false); // menuItemSize.addActionListener(this); menuItemSystemOn.addActionListener(this); menuItemSystemOff.addActionListener(this); // // setLayout(new FlowLayout()); add(fullSizeButton); add(fullSysGoButton); add(fullSysBackButton); // fullSysBackButton.setEnabled(false); // fullSizeButton.addActionListener(this); fullSysGoButton.addActionListener(this); fullSysBackButton.addActionListener(this); // // frontDialog=new FrontDialog(frame,"前面表示"); frontDialog.setSize(100, 100); frontDialogFull=new FrontDialog(frameFull,"前面表示Full"); frontDialogFull.setSize(200, 200); //frontDialog.setAlwaysOnTop(true); //frontDialog.toFront(); // add(dialogOn); add(dialogOff); add(fileDialogOn); // dialogOn.addActionListener(this); dialogOff.addActionListener(this); fileDialogOn.addActionListener(this); // add(checkMenuBar); } //真ん中に、現在のパネルのサイズを表示 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()==menuItemSize){ //***メニューからサイズを求めてフルスクリーン fullSize(); }else if(e.getSource()==menuItemSystemOn){ //***メニューからGraphicsDeviceを使ってフルスクリーン fullSysGo(); }else if(e.getSource()==menuItemSystemOff){ //***メニューからGraphicsDeviceを使ったフルスクリーンを解除 fullSysBack(); }else if(e.getSource()==fullSizeButton){ //***サイズを求めてフルスクリーンにする fullSize(); }else if(e.getSource()==fullSysGoButton){ //***GraphicsDeviceを使ってフルスクリーンにする fullSysGo(); }else if(e.getSource()==fullSysBackButton){ //***GraphicsDeviceを使ったフルスクリーンを解除する fullSysBack(); }else if(e.getSource()==dialogOn){ //そのフレームのダイアログを表示 if(frame.isVisible()){ frontDialog.setVisible(true); }else{ frontDialogFull.setVisible(true); } }else if(e.getSource()==dialogOff){ //そのフレームのダイアログを消す if(frame.isVisible()){ frontDialog.setVisible(false); }else{ frontDialogFull.setVisible(false); } }else if(e.getSource()==fileDialogOn){ //ファイルダイアログ表示 JFileChooser chooser=new JFileChooser(); //(システム使用のフルスクリーンでは動作が変で使用禁) chooser.setDialogTitle("フルスクリーンでも表示できるかのテスト"); int ret=chooser.showDialog(frame, "選択しても何も起きない"); if(ret==JFileChooser.APPROVE_OPTION){ //何もしない }else{ //何もしない } } } //フルスクリーン private void fullSize(){ if(frame.isVisible()){ //通常用フレームが表示されている場合 //スクリーンのサイズを取得 Dimension dim=frame.getToolkit().getScreenSize(); //---ウィンドウで前面ダイアログが表示されていたか得ておく(ウィンドウを非表示にする前に)--- boolean dialogVisible=frontDialog.isVisible(); //---ウィンドウでのダイアログの状態をフルスクリーンでのダイアログに受け渡す--- frontDialogFull.exchangeProperty(frontDialog); //通常用フレームを非表示にして、パネルを外す frame.setVisible(false); frame.getContentPane().remove(this); //フルスクリーン用フレームにパネルを載せて、画面いっぱいに表示 frameFull.setBounds(0,0,dim.width,dim.height); frameFull.getContentPane().add(this); if(!checkMenuBar.isSelected()){ frameFull.setJMenuBar(menuBar); } frameFull.setVisible(true); //---ウィンドウで前面ダイアログが表示されていたなら、フルスクリーンでも表示--- frontDialogFull.setVisible(dialogVisible); // //frameFull.toFront(); //なくてもタスクバーは消える // menuItemSystemOn.setEnabled(false); fullSysGoButton.setEnabled(false); }else{ //フルスクリーン用フレームが表示されている場合 //---フルスクリーンで前面ダイアログが表示されていたか得ておく(フルスクリーンを非表示にする前に)--- boolean dialogVisible=frontDialogFull.isVisible(); //---フルスクリーンでのダイアログの状態をウィンドウでのダイアログに受け渡す--- frontDialog.exchangeProperty(frontDialogFull); //フルスクリーン用フレームを非表示にして、パネルを外す frameFull.setVisible(false); frameFull.getContentPane().remove(this); //非表示にしていたJFrameにパネルを載せて、表示させる frame.getContentPane().add(this); frame.setJMenuBar(menuBar); frame.setVisible(true); //---フルスクリーンで前面ダイアログが表示されていたなら、ウィンドウでも表示--- frontDialog.setVisible(dialogVisible); // menuItemSystemOn.setEnabled(true); fullSysGoButton.setEnabled(true); } } private void fullSysGo(){ //その環境で利用可能なグラフィックデバイスを取得 GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // if(device.isFullScreenSupported()){ //---ウィンドウで前面ダイアログが表示されていたか得ておく(ウィンドウを非表示にする前に)--- boolean dialogVisible=frontDialog.isVisible(); //---ウィンドウでのダイアログの状態をフルスクリーンでのダイアログに受け渡す--- frontDialogFull.exchangeProperty(frontDialog); //通常用フレームを非表示にして、パネルを外す frame.setVisible(false); frame.getContentPane().remove(this); //フルスクリーン用フレームにパネルを載せて、フルスクリーンで表示する frameFull.getContentPane().add(this); device.setFullScreenWindow(frameFull); //このフレームをフルスクリーンに if(!checkMenuBar.isSelected()){ frameFull.setJMenuBar(menuBar); } frameFull.setVisible(true); //---ウィンドウで前面ダイアログが表示されていたなら、フルスクリーンでも表示--- frontDialogFull.setVisible(dialogVisible); // menuItemSize.setEnabled(false); menuItemSystemOn.setEnabled(false); menuItemSystemOff.setEnabled(true); fullSizeButton.setEnabled(false); fullSysGoButton.setEnabled(false); fullSysBackButton.setEnabled(true); }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } } private void fullSysBack(){ //その環境で利用可能なグラフィックデバイスを取得 GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // if(device.isFullScreenSupported()){ device.setFullScreenWindow(null); //フルスクリーンを解除 //---フルスクリーンで前面ダイアログが表示されていたか得ておく(フルスクリーンを非表示にする前に)--- boolean dialogVisible=frontDialogFull.isVisible(); //---フルスクリーンでのダイアログの状態をウィンドウでのダイアログに受け渡す--- frontDialog.exchangeProperty(frontDialogFull); //フルスクリーン用フレームを非表示にして、パネルを外す frameFull.setVisible(false); frameFull.getContentPane().remove(this); //通常用フレームにパネルを載せて、表示させる frame.getContentPane().add(this); frame.setJMenuBar(menuBar); frame.setVisible(true); //---フルスクリーンで前面ダイアログが表示されていたなら、ウィンドウでも表示--- frontDialog.setVisible(dialogVisible); // menuItemSize.setEnabled(true); menuItemSystemOn.setEnabled(true); menuItemSystemOff.setEnabled(false); fullSizeButton.setEnabled(true); fullSysGoButton.setEnabled(true); fullSysBackButton.setEnabled(false); }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } } }