📄 codewin.java
字号:
/* $Id: CodeWin.java,v 1.2 1996/06/28 04:09:39 kmillik1 Exp $ *//* $Log: CodeWin.java,v $# Revision 1.2 1996/06/28 04:09:39 kmillik1# Fixed $Log$ comment.## Revision 1.1 1996/06/28 04:00:02 kmillik1# Initial revision#*/import java.awt.*;public class CodeWin extends Canvas { private String[] text; private int num_threads; private int line_height; private int line_ascent; private int height; private int width; private int[] pos; private Image[] img; public CodeWin(int n, String[] t, Image[] im, Font f) { text = t; setFont(f); num_threads = n; // find the height of a single line FontMetrics fm = getFontMetrics(getFont()); line_height = fm.getHeight(); line_ascent = fm.getAscent(); // find the height of the entire object height = line_height * text.length; // find the width of the object, i.e. the width of the longest line int max_width = 0; int cur_width; for (int i = 0; i < text.length; ++i) { cur_width = fm.stringWidth(text[i]); if (cur_width > max_width) max_width = cur_width; } width = max_width; // create an array of ints to represent the line number of each thread pos = new int[num_threads]; for (int i = 0; i < num_threads; ++i) pos[i] = 0; img = im; } public CodeWin(int n, String[] t, Image[] im) { this(n, t, im, new Font("Courier", Font.PLAIN, 12)); } public Dimension minimumSize() { return new Dimension(width+15*num_threads+10, height+line_height); } public Dimension preferredSize() { // preferred size and minimum size are the same return minimumSize(); } public void paint(Graphics g) { Dimension d = size(); g.setColor(getBackground()); g.draw3DRect(0, 0, d.width-1, d.height-1, false); g.setColor(getForeground()); int y = line_height; for (int i = 0; i < text.length; ++i) { g.drawString(text[i], 15*num_threads+5, y); y += line_height; } for (int i = 0; i < num_threads; ++i) g.drawImage(img[i], 15*i+1, pos[i]*line_height, this); } public void step(int n) { step(n, 1); } public void step(int n, int num_steps) { Graphics g = getGraphics(); g.clearRect(15*n+2, pos[n]*line_height+1, 15, line_height); for (int i = 0; i < num_steps; ++i) { do pos[n] = (pos[n] + 1 == text.length) ? 0 : pos[n] + 1; while (text[pos[n]].compareTo("") == 0); } g.drawImage(img[n], 15*n+1, pos[n]*line_height, this); g.dispose(); } public void reset() { for (int i = 0; i < num_threads; ++i) pos[i] = 0; repaint(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -