⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frameadapter.java

📁 Java 入门书的源码
💻 JAVA
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

/*  Defines a subclass of WindowAdapter, overriding
 *  the windowClosing method but inheriting the default
 *  implementations of the other six window handling
 *  methods. Defines a subclass of Frame, adding a text
 *  field, and displaying the string the user enters.
 */
  
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class FrameAdapter extends Applet {
  private MyFrame f;

  public void init() {
    f = new MyFrame("MyFrame");
    f.setSize(150,150);
    f.show();
    f.addWindowListener(new CloseWindow());
  }
  class CloseWindow extends WindowAdapter {
    public void windowClosing(WindowEvent event) {
      f.setVisible(false); 
      f.dispose();
    }
  }	
}

class MyFrame extends Frame implements ActionListener {
  Font font = new Font("Serif",Font.BOLD,24);
  TextField text = new TextField(10);
  public MyFrame(String title) {
    super(title);
    add(text,"North");
    text.addActionListener(this);
  }
  public void actionPerformed(ActionEvent event) {
    repaint();
  }
  public void paint(Graphics g) {
    g.setFont(font);
    g.drawString(text.getText(),20,100);
  }
}
    

⌨️ 快捷键说明

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