//************************************************************* // Java application // 「WindowTest」 // //          作 成 者:ルート高菜    //          作成開始月:2007/1 //          最終更新月:2007/1 [TN096/J86] //************************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class WindowTest extends JFrame implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; public static void main(String[] args) { WindowTest frame=new WindowTest(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //右上×印で終了 frame.setVisible(true); frame.setLocationRelativeTo(null); //画面の真ん中に表示 } // 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("JWindow表示"); JButton fullSizeButton=new JButton("サイズ指定でFullScreen"); JButton fullSysGoButton=new JButton("システムでFullScreen"); // public WindowTest(){ setTitle("WindowTest"); setSize(500,200); // 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(fullSysGoButton); //コンテナ枠 Container cp=getContentPane(); cp.add(panel,BorderLayout.CENTER); // showButton.addActionListener(this); fullSizeButton.addActionListener(this); fullSysGoButton.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); window.setVisible(true); //window.toFront(); }else if(e.getSource()==fullSysGoButton){ //***GraphicsDeviceを使ってフルスクリーンを実行 //その環境で利用可能なグラフィックデバイスを取得 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); } } } }