example15_3.java.bak

来自「不错的教程 适合中高级人员的使用」· BAK 代码 · 共 39 行

BAK
39
字号
import java.awt.*;import java.awt.event.*;
class MyFrame extends Frame implements ItemListener,ActionListener
{  Checkbox box; Button button;
   Toolkit tool; Dimension dim;
   MyFrame(String s)
   {  super(s);
      box=new Checkbox("设置窗口和屏幕同样大小");
      add(box,BorderLayout.SOUTH);
      button=new Button("关闭窗口"); button.addActionListener(this);
      box.addItemListener(this);
      setBounds(100,100,200,300); setVisible(true);
      add(box,BorderLayout.SOUTH); add(button,BorderLayout.NORTH);
      tool=getToolkit();
	  addWindowListener(new WindowAdapter(){
	  public void windowClosing(WindowEvent e)
		  {System.exit(0);}});
      validate();
   } 
   public void itemStateChanged(ItemEvent e)
   {  if(box.getState()==true)
        {  dim=tool.getScreenSize();
           setBounds(0,0,dim.width,dim.height);
           validate(); 
        }
      else
        {  setBounds(0,0,dim.width,80);
           validate();
        }
   }
   public void actionPerformed(ActionEvent e)
   {  dispose();
   }
}
class Example15_2 
{  public static void main(String args[])
   {new MyFrame("窗口");
   } 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?