📄 inserta.java
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Uses a text field to enter data and a canvas
* to display the chart. This is an exploratory
* program to develop a GUI for insertion sort.
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class InsertA extends Applet implements ActionListener{
public static int ITEM_SIZE = 10;
public static int CHART_SIZE = 100;
TextField number = new TextField(5);
DrawOn canvas = new DrawOn();
int [] item = new int[ITEM_SIZE];
int count = 0;
public void init() {
add(number);
canvas.setSize(CHART_SIZE,CHART_SIZE);
canvas.setBackground(Color.pink);
add(canvas);
number.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
item[count++] = new Integer(number.getText()).intValue();
number.setText("");
canvas.repaint();
}
class DrawOn extends Canvas {
public void paint(Graphics g) {
if (count > 0){
int width = CHART_SIZE/count;
for (int i=0; i<count; i++)
g.fillRect(i*width,CHART_SIZE-item[i],width,item[i]);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -