影音先锋AⅤ天堂资源站,13小箩利洗澡无码视频APP,午夜理论片日本中文在线,最近新免费韩国日本电影

萬能百科  > 所屬分類  > 

本題的功能是監(jiān)聽鼠標(biāo)左右鍵的單擊,以及面板中滾動條的添加。在窗口的畫板中單擊鼠標(biāo)左鍵,在單擊

本題的功能是監(jiān)聽鼠標(biāo)左右鍵的單擊,以及面板中滾動條的添加。在窗口的畫板中單擊鼠標(biāo)左鍵,在單擊的位置繪制一個(gè)圓,當(dāng)繪制的圓大于畫板的大小時(shí),畫板就添加滾動條,在畫板中單擊鼠標(biāo)右鍵,則清除畫板中的所有圖形。 import javax.swing.*; import javax.swing.event.MouselnputAdapter; import java.a(chǎn)wt.*; import java.a(chǎn)wt.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.or- ange, 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); bjects=new Vector; JLabel instructionsLeft=new JLabel("單擊鼠標(biāo) 左鍵畫圓."); JLabel instructionsRight=new JLabel("單擊鼠 標(biāo)右鍵清空畫板."); JPanel instructionPanel=new JPanel(new Grid- Layout(0,1)); instructionPanel.a(chǎn)dd(instructionsLeft); instructionPanel.a(chǎn)dd(instructionsRight); drawingArea=new JPanel{ protected void paintComponent(Graphics g){ super.paintComponent(g); Rectangle rect; for(int i=0;i<objects.size;i++){ rect=(Rectangle)objects.elementAt(i): g.setColor(colors[(i%color_n)]); g.fillOval(rect.X,rect.Y,rect.width,rect. height); } } }; drawingArea.setBackground(Color.white); drawingArea.a(chǎn)ddMouseListener(new MouseLis- tener); JScrollPane scroller=new JScrollPane(drawing- Area); scroller.setPreferredSize(new Dimension(200, 200)); setLayout(new BorderLayout); add(instructionPanel,BorderLayout.NORTH); add(scroller,BorderLayout.CENTER): } class MyMouseListener extends mouseInputAdapt- er{ final int W=100; final int H=100; public void mouseReleased(MouseEvent e){ boolean changed=false; if(SwingUtilities.isRightMouseButton(e)){ objects.removeAllElements; size.width=0; size.height=0; changed=true; }else{ int X=e.getX-W/z; int Y=e.getY-H/2 if(x<0)x=0; if(y<O)Y=0; Rectangle rect=new Rectangle(X,Y,W,H); objeets.a(chǎn)ddElement(rect); drawingArea.scrollRectToVisible(rect); int this_width=(x+W+2); if(this width>size.width) {size.width=this_width;changed=true;} int this=height=(y+H+2); if(this_height>size.height) {size.height=this_height;changed=true;} } if(changed){ drawingArea.setPreferredSize(size); drawingArea.revalidateI; } drawingArea.paint; } } public static void main(String args[]){ JFrame. frame=new JFrame("java3"): frame.a(chǎn)ddWindowListener(new WindowAdapter { public void windowClosing(WindowEvent e) {System.exit(0);} }); frame.setContentPane(new java3); frame.pack; frame.setVisible(true); } }

正確答案:

第1處:drawingArea.a(chǎn)ddMouseListener(new MyMouseListener)第2處:class MyMouseListener ex{Cends MouselnputAdapter第3處:dwawingArea.repaint【解析】第1處注冊監(jiān)聽器參數(shù)應(yīng)為事件源,應(yīng)為MyMouseListener;第2處Java是大小寫敏感的;第3處重繪構(gòu)件。

詞條內(nèi)容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學(xué)等領(lǐng)域),建議您咨詢相關(guān)領(lǐng)域?qū)I(yè)人士。

標(biāo)簽

<蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <文本链> <文本链> <文本链> <文本链> <文本链> <文本链>