[问答题] 本题的功能是监听鼠标左右键的单击,以及面板中滚动条的添加。在窗口的画板中单击鼠标左键,在单击的位置绘制一个圆,当绘制的圆大于画板的大小时,画板就添加滚动条,在画板中单击鼠标右键,则清除画板中的所有图形。
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class java3 extends JPanel
private Dimension size;
private Vector objects;
private final Color colors[]=
Color.red,Color.blue,Color.green,Color.orange,
Color.cyan,Color.magenta,Color.darkGray,Color.yellow;
private final int color_n=colors.length;
JPanel drawingArea;
public java3()
setOpaque(true);
size=new Dimension(0,0);
objects=new Vector();
JLabel instructionsLeft=new JLabel("单击鼠标左键画圆.");
JLabel instructionsRight=new JLabel("单击鼠标右键清空画板.");
JPanel instructionPanel=new JPanel(new GridLayout(0,1));
in