欢迎来到牛牛题库网 牛牛题库官网
logo

未知题型

本题中,主窗口中有两个下拉菜单,一个控制绘制图形的颜色,另一个控制绘制的图形,在画板中单击鼠标,则以单击的位置为左上角、以选定的颜色绘制选定的图形。 import javA.awt.*; import javA.awt.event.*; class java3 extends FramE.{ String[]figureNames={'圆形','椭圆形','正 方形','长方形'); String[]colorNames={'红色','绿色','蓝 色','黄色'}; Color[]colorValues={Color.red,Color.green, Color.blue,Color.yellow); Choice chFigure=new Choice; Choice chColor=new Choice; int curX,curY; java3{ super('java3'); addWindowListener(new WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(O); } }); Panel P=new Panel(new GridLayout(1,O)); for(int i=0;i<figureNames.length;i++){ ehFigurE.addhem(figureNames[i]); } for(int i=0;i<colorNames.length;i++){ chColor.addhem(eolorNames[i]); } P.add(chColor); P.add(chFigure); add(p,BorderLayout.NORTH); addMouseListener(this); setSize(300,300); show; } public void update(Graphics g){ g.getColor(colorValues[chColor,getSelectedIndex ]); switch(chFigurE.getSelectedlndex){ case 0; g.fillOval(curX,curY,30,30); break; case l: g.fillOval(curX,curY,30,50); break; case 2: g.fillRect(curX,curY,30,30); break; case 3: g.fillRect(curX,curY,30,50); break; } } class MouseEventListener implements MouseAda- pter{ public void mousePressed(MouseEvent evt){ curX=evt.getX; curY=evt.getY; repaint; } } static public void main(String[]args){ new java3; } )

A.awt.*;
B.awt.event.*;
C.red,Color.green,
D.blue,Color.yellow);
E.exit(O);
F.length;i++){
G.addhem(figureNames[i]);
H.length;i++){
I.addhem(eolorNames[i]);
J.add(chColor);
K.add(chFigure);
L.NORTH);
M.getColor(colorValues[chColor,getSelectedIndex
N.getSelectedlndex){
O.fillOval(curX,curY,30,30);
P.fillOval(curX,curY,30,50);
Q.fillRect(curX,curY,30,30);
R.fillRect(curX,curY,30,50);
S.getX;
T.getY;
【参考答案】

第1处:addMouseListener(new MouseEventListener)
第2处:g.setco......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)

点击查看答案
微信小程序免费搜题
微信扫一扫,加关注免费搜题

微信扫一扫,加关注免费搜题