//************************************************************* // Java applet // 「FullScreenTest3」 // //          作 成 者:ルート高菜    //          作成開始月:2007/2 //          最終更新月:2007/2 [TN099/J89] //************************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreenTest3 extends JApplet implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; // JTextField leftField=new JTextField("100",3); JTextField topField=new JTextField("100",3); JTextField widthField=new JTextField("100",3); JTextField heightField=new JTextField("100",3); // JButton showButton=new JButton("Window表示"); JButton fullSizeButton=new JButton("サイズ指定でFullScreen"); JButton fullSysButton=new JButton("システムでFullScreen"); // public void init() { // JPanel panel=new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new JLabel("左位置")); panel.add(leftField); panel.add(new JLabel("上位置")); panel.add(topField); panel.add(new JLabel("幅")); panel.add(widthField); panel.add(new JLabel("高さ")); panel.add(heightField); panel.add(showButton); panel.add(fullSizeButton); panel.add(new JLabel(" ")); panel.add(fullSysButton); //コンテナ枠 Container cp=getContentPane(); cp.add(panel,BorderLayout.CENTER); // showButton.addActionListener(this); fullSizeButton.addActionListener(this); fullSysButton.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==showButton){ //位置とサイズ取得 int left,top,width,height; try{ left=Integer.parseInt(leftField.getText()); }catch(NumberFormatException nfe){ left=100; leftField.setText("100"); } try{ top=Integer.parseInt(topField.getText()); }catch(NumberFormatException nfe){ top=100; topField.setText("100"); } try{ //幅は100以上(ボタンがはみ出ないため) width=Integer.parseInt(widthField.getText()); if(width<100){ width=100; widthField.setText("100"); } }catch(NumberFormatException nfe){ width=100; widthField.setText("100"); } try{ //高さは100以上(ボタンがはみ出ないため) height=Integer.parseInt(heightField.getText()); if(height<100){ height=100; heightField.setText("100"); } }catch(NumberFormatException nfe){ height=100; heightField.setText("100"); } // NoFrameWindow window=new NoFrameWindow(); window.setBounds(left,top,width,height); window.setVisible(true); }else if(e.getSource()==fullSizeButton){ //画面のサイズを取得 Dimension dim=getToolkit().getScreenSize(); // NoFrameWindow window=new NoFrameWindow(); window.setBounds(0,0,dim.width,dim.height+50); //***下のバーが画面下に隠れるようにする*** window.setVisible(true); window.toFront(); }else if(e.getSource()==fullSysButton){ //その環境で利用可能なグラフィックデバイスを取得 GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // if(device.isFullScreenSupported()){ NoFrameWindow window=new NoFrameWindow(); window.setVisible(true); //window.toFront(); device.setFullScreenWindow(window); //このフレームをフルスクリーンに /*これでは上手くいかない try{ device.setFullScreenWindow(this); //このフレームをフルスクリーンに }finally{ device.setFullScreenWindow(null); //不正終了したら元に戻るように } */ }else{ //システムがフルスクリーン出来ない JOptionPane.showMessageDialog(this,"フルスクリーンに対応していません","エラー",JOptionPane.ERROR_MESSAGE); } } } }