myframe.java~17~

来自「GUI java源码 多种例子 java大学课程」· JAVA~17~ 代码 · 共 79 行

JAVA~17~
79
字号
package awt;

import java.awt.*;
import java.awt.event.*;

public class MyFrame {
  public MyFrame() {
  }

  public static void main(String[] args) {
    Frame mf = new Frame("我的图形界面");
    mf.setBackground(Color.RED);
    mf.setSize(400, 400);
    mf.setLocation(200, 200);
    //mf.setLayout(new BorderLayout(10,10));
    //mf.setLayout(new FlowLayout(10,10,10));
    mf.setLayout(new GridLayout(3, 2, 10, 10));
    Button a = new Button("上北");
    Button b = new Button("下南");
    Button c = new Button("左西");
    Button d = new Button("右东");
    Button e = new Button("提交");
    mf.add(a, "North");
    mf.add(b, "South");
    mf.add(c, "West");
    mf.add(d, "East");
    mf.add(e, "Center");
    //mf.addWindowListener(new MyWindowListener());
    mf.addWindowListener(new HisWindowListener());

    mf.setVisible(true);
  }
}

class MyWindowListener
    implements WindowListener {
  public void windowOpened(WindowEvent e) {

  }

  public void windowClosing(WindowEvent e) {
    System.exit(0);

  }

  public void windowClosed(WindowEvent e) {

  }

  public void windowIconified(WindowEvent e) {

  }

  public void windowDeiconified(WindowEvent e) {

  }

  public void windowActivated(WindowEvent e) {

  }

  public void windowDeactivated(WindowEvent e) {

  }
}

class YourWindowListener {

}

class HisWindowListener
    extends WindowAdapter {
  public void windowClosing(WindowEvent e) {
    System.exit(0);

  }

}

⌨️ 快捷键说明

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