//************************************************************* // Java application // 「FullScreenTest4」 // //          作 成 者:ルート高菜    //          作成開始月:2007/12 //          最終更新月:2007/12 [TN117/J107] //************************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreenTest4 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("FullScreenTest4"); // //メインクラスであるパネルを、フレームに載せる //フレーム自身をパネルに渡して保持させる frame.getContentPane().add(new FullScreenTest4(frame,frameFull)); // 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; //通常用フレーム JFrame frameFull; //フルスクリーン用フレーム // public FullScreenTest4(JFrame frame,JFrame frameFull){ this.frame=frame; this.frameFull=frameFull; // setLayout(new FlowLayout()); add(fullSizeButton); add(fullSysGoButton); add(fullSysBackButton); // fullSysBackButton.setEnabled(false); // fullSizeButton.addActionListener(this); fullSysGoButton.addActionListener(this); fullSysBackButton.addActionListener(this); //コントロールの動作確認(JFrame上では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()){ //通常用フレームが表示されている場合 //スクリーンのサイズを取得 Dimension dim=frame.getToolkit().getScreenSize(); // //通常用フレームを非表示にして、パネルを外す frame.setVisible(false); frame.getContentPane().remove(this); //フルスクリーン用フレームにパネルを載せて、画面いっぱいに表示 frameFull.setBounds(0,0,dim.width,dim.height); frameFull.getContentPane().add(this); frameFull.setVisible(true); // //frameFull.toFront(); //なくてもタスクバーは消える // fullSysGoButton.setEnabled(false); }else{ //フルスクリーン用フレームが表示されている場合 //JWindowからパネルを外して、JWindowを破棄する frameFull.getContentPane().remove(this); frameFull.setVisible(false); //非表示にしていた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()){ //通常用フレームを非表示にして、パネルを外す frame.setVisible(false); frame.getContentPane().remove(this); //フルスクリーン用フレームにパネルを載せて、フルスクリーンで表示する frameFull.getContentPane().add(this); device.setFullScreenWindow(frameFull); //このフレームをフルスクリーンに frameFull.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); //フルスクリーンを解除 //フルスクリーン用フレームを非表示にして、パネルを外す frameFull.setVisible(false); frameFull.getContentPane().remove(this); //通常用フレームにパネルを載せて、表示させる frame.getContentPane().add(this); frame.setVisible(true); // fullSizeButton.setEnabled(true); fullSysGoButton.setEnabled(true); fullSysBackButton.setEnabled(false); }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } } } }