ww2.java

来自「金旭亮的java教案」· Java 代码 · 共 41 行

JAVA
41
字号

class WarningWindow2 extends java.awt.Window {

    WarningWindow2(java.awt.Frame apple) { // constructor
        super(apple);
        setBackground(java.awt.Color.red);
    }

    public void setSize(int x, int y) { // overriding method
        int bigx = (int) (x*1.5);
        int bigy = (int) (y*1.5);
        super.setSize(bigx, bigy);
    }
}

// The method setSize() in WarningWindow2 replaces 
// or overrides the superclass's version of setSize() 
// when the method is invoked on a WarningWindow2 object. 
// C++ programmers will note that you do not need to 
// specifically point out to the compiler (with the C++ 'virtual' keyword)
// that overriding will take place. Here's some example code:

public class ww2 {
   public static void main(String args[]) {
        java.awt.Frame f = new java.awt.Frame();
        { 
          java.awt.Window w = new java.awt.Window(f);
          w.setSize(200,100);
          w.setVisible(true);
          w.setLocation(300,300);
        }
        { 
          java.awt.Window w = new WarningWindow2(f); // the only change
          w.setSize(200,100);
          w.setVisible(true);
          w.setLocation(370,370);
        }
   }

}

⌨️ 快捷键说明

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