📄 testcanvas.java~27~
字号:
package TestCanvas;import java.awt.*;import java.awt.event.*;import java.util.*;public class TestCanvas extends Canvas implements KeyListener{ String s=""; public void paint(Graphics g){ g.setColor(Color.magenta); g.drawRect(50,50,100,100); g.drawString("你好吗?",60,60); } public void keyReleased(KeyEvent e){ System.out.println("keyReleased"); } public void KeyTyped(KeyEvent ev){ requestFocus(); s+=ev.getKeyChar(); getGraphics().drawString(s,30,20); } public void KeyPressed(KeyEvent ev){ System.out.println("keypressed"); } /*public void windowClosing(WindowEvent e) {System.exit(1);} public void windowActivated(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowOpened(WindowEvent e){} */ public static void main(String[] args) { TestCanvas c = new TestCanvas(); Frame f=new Frame("testing canvas"); c.addKeyListener(c); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){System.exit(0);} }); f.setLayout(new BorderLayout()); //f.addWindowListener(c); f.add(c,"Center"); f.setSize(200,200); f.setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -