📄 complete11_5.java
字号:
package questions.c11;
import java.awt.*;
import java.awt.event.*;
public class Complete11_5 extends Frame {
private BallPanel redPanel;
private BallPanel greenPanel;
private BallPanel bluePanel;
Complete11_5( String title ) {
super( title );
setLayout( new GridLayout( 3, 1 ) );
redPanel = new BallPanel( Color.red );
add( redPanel );
greenPanel = new BallPanel( Color.green );
add( greenPanel );
bluePanel = new BallPanel( Color.blue );
add( bluePanel );
addWindowListener( new WindowAdapter () {
public void windowClosing( WindowEvent event ) {
dispose();
System.exit( 0 );
}
}
);
pack();
setVisible( true );
}
public static void main( String[] args ) {
Complete11_5 area = new Complete11_5( " Moving Ball" );
area.redPanel.dropBall();
area.greenPanel.dropBall();
area.bluePanel.dropBall();
}
}
class BallPanel extends Panel implements Runnable {
private int x = 0, y = 20;
private Thread ballThread;
BallPanel( Color foreground ) {
setForeground( foreground );
setSize( 400, 60 );
setLayout( null );
}
void dropBall() {
ballThread = new Thread( this );
ballThread.start();
}
public void paint( Graphics g ) {
g.fillArc( x, y, 20, 20, 0, 360 );
}
public void update( Graphics g ) {
g.fillArc( x, y, 20, 20, 0, 360 );
}
public void run() {
while ( x < (int) (getSize().getWidth() ) ) {
x += 20;
repaint();
// your code goes here
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -