Which is a method of the MouseMotionListener interface?()A、 Public void mouseMoved(MouseEvent)B、 Public boolean mouseMoved(MouseEvent)C、 Public void mouseMoved(MouseMotionEvent)D、 Public boolean MouseMoved(MouseMotionEvent)E、 Public boolean mouseMoved(MouseMotionEvent)
Which is a method of the MouseMotionListener interface?()
- A、 Public void mouseMoved(MouseEvent)
- B、 Public boolean mouseMoved(MouseEvent)
- C、 Public void mouseMoved(MouseMotionEvent)
- D、 Public boolean MouseMoved(MouseMotionEvent)
- E、 Public boolean mouseMoved(MouseMotionEvent)
相关考题:
【Java代码】import Java.util.ArrayList;import java.util.List;(1) class AbstractFile{protected String name;public void printName(){System.out.println(name);}public abstract boolean addChild(AbstractFile file);public abstract boolean removeChild(AbstractF ile file);public abstract ListAbstractFile getChildren();}class File extends AbstractFile{public File(String name){this.name=name;}public boolean addChild(AbstractFile file){return false;}public boolean removeChild(AbstractFile file){return false;}public ListAbstractFile getChildren(){return (2) ;}}class Folder extends AbstractFile{private List AbslractFile childList;public Folder(String name){this.name=name;this.childList=new ArrayListAbstractFile();}public boolean addChild(AbstractFile file) { return childList.add(file);}public boolean removeChild(AbstractFile file){return childList.remove(file);}public (3) AbstractFile getChildren(){return (4) ;}}public class Client{public static void main(String[] args){//构造一个树形的文件/目录结构AbstractFile rootFolder= new Folder("c:\\ ");AbstractFile compositeFolder=new Folder("composite");AbstractFile windowsFolder=new Folder("windows");AbstractFile file=new File("TestComposite.java");rootFolder.addChild(compositeFolder) ;rootFolder.addChild(windowsFolder);compositeFolder.addChild(file) ;//打印目录文件树printTree(rootFolder);}private static void printTree(AbslractFile ifile){ifile.printName();List AbslractFile children=ifile.getChildreno:if(children==null) return;for (AbstractFile file:children) {(5) ;}}}该程序运行后输出结果为:c:\compositeTestComposite.javaWindows
本题的功能是跟踪鼠标在窗口的操作,以及在窗口的坐标,包括移进、移出、移动、单击、释放和拖曳,并将这些信息显示在窗口的文字标签上。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class java3 extends JFrame. implements MouseL- istener MouseMotionListener { private JLabel statusBar; public java3 { super("java3"); statllsBar=new TLabel; getContentPane.add(statusBar,BorderLayout. SOUTH); addMouseListener(this); addMouseMotionListener(this); setSize(275,100); show; } public void mouseClicked(MouseEvent e) { statusBar.setText("Clicked at["+e.getX+ ","+e.getY+"]"); } public void mousePressed(MouseEvent e) { statusBar.setText("Pressed at["+e.getX+ ","+e.getY+"]"); } public void mouseReleased(MouseEvent e) { statusBar.setText("Released at["+e.getX +","+e.getY+"]"); } public void mouseln(MouseEvent e) { statusBar.setText("Mouse in window"); public void mouseExited(MouseEvent e) { statusBar.setText("Mouse outside window"); } public void mouseDragged(MouseEvent e) { statusBar.setText("Dragged at["+e.getX +","+e.getY+"]"); } public void mouseMoved(MouseEvent e) { statusBar.setText("Moved at["+e.getX+ ","+e.getY+"]"); } public static void main(String args[]) { java3 app=new java3; app.addWindowListener(new WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } };
阅读以下说明和JAVA2代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序实现了利用鼠标任意移动该圆形的位置,仔细阅读代码和相关注释,将程序补充完整。【代码6】import java.awt.*;import java.awt.event.*;public class CIUSAMPLE extends Frame. implements MouseMotionListener, MouseListener{static CIUSAMPLE frm=new CIUSAMPLE ();int x=70,y=60,posX=70,posY=60,dx,dy;public static void main ( String args[]){frm.setTitle ("Dragging a circle");frm.setSize ( 200,150 );(1)frm.addMouseMotionListener ( frm );frm. setVisible ( true );}public void mousePressed ( MouseEvent e ){(2)dy=e.getY () -posY;}public void mouseDragged ( MouseEvent e ){(3)y=e.getY () -dy;if ( dx>0 dx<50 dy>0 dy<50 ) //如果指我落在正方形区域内{Graphics g=getGraphics ();(4)}}public void paint ( Graphics g ){g.setColor ( Color. pink ); // 设置绘图颜色为粉红g.fillOval ( x,y,50,50 ); //以基准点为图形的左上角绘出圆形(5)posY=y;}public void mouseMoved ( MouseEvent e ) { }public void mouseReleased ( MouseEvent e ) { }public void mouseEntered ( MouseEvent e ) { }public void mouseExited ( MouseEvent e ) { }public void mouseClicked ( MouseEvent e ) { }}
下列代码的编译或执行结果是______。public class MyVal{puhlic static void main(String args[]){MyVal m=new MyVal();m.aMethod();}public void aMethod(){boolean b[]=new Boolean[5];System.out.println(b[0]);}A) 1B) nullC) 0D) 编译错误A.B.C.D.
本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。 import java.awt.*; import java.awt.event.*; import javax swing.*; class MousePanel extends JPanel extends MouseMo- tionListener {public MousePanel {addMouseListener(new MouseAdapter {public void mousePressed(MouseEvent evt) {int X=evt.getX; int Y=evt.getY; current=find(x,y); if(current0) add(x,y); } public void mouseClicked(MouseEvent evt) {int X=evt.getX; int Y=evt.getY; if(evt.getClickCount=2) {remove(current); } } }); addMouseMotionListener(this); } public void paintComponent(Graphics g) {super.paintComponent; for(int i=0;insquares;i++) draw(g,i); } public int find(int X,int y) (for(int i=0;insquares;i++) if(squares[i].x-SQUARELENGTH/2= x X=squares[i].x+SQuARELENGTH/2 squares[i].Y-SQUARELENGTH/2 =Y y=squares[i].Y+SQUARELENGTH /2) return i ; return-1 ; } public void draw(Graphics g,int i) {g.drawRect(squares[i].X-SQUARE- LENGTH/2。 squares[i].Y-SQUARELENGTH/2, SQUARELENGTH, SQUARELENGTH); } public void add(int X,int Y) {if(nsquaresMAXNSQUARES) {squares[nsquares]=new Point(x,y); current=nsquares ; nsquares++; repaint; } } public void remove(int n) {if(n0 ‖ n=nsquares)return; Nsquares- -; squares[n]=squares[nsquares]; if(current= =n)current= -l; repaint; } public void mouseMoved(MouseEvent evt) {} public void mouseDragged(MouseEvent evt) {} private static final int SQUARELENGTH=10: private static final int MAXNSQUARES=100; private Point[]squares=new Point[MAX- NSQUARES]; private int nsquares=0; private int current=-l; } class MouseFrame. extends JFramc {public MouseFrame {setTitle("java3"); setSize(300,200); addWindowListener(new WindowAdapter {public void windowClosing(WindowEvent e) {System.exit(0); } }); Container contentPane=getContentPane; contentPane.add(MousePanel); } } public class java3 {public static void main(String[]args) {JFrame. frame=new MouseFrame; frame.show; } }
请完成下列Java程序:记录鼠标在窗口中的信息,包括鼠标的移动事件以及鼠标在窗口中的位置坐标,要求在窗口下方显示鼠标的事件和位置信息,在窗口上方有按钮控制程序的正常退出。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;public class ex12_2extends Frame. implements MouseMotionListener, ActionListenerprivate Label 1;private String str=" ";public static void main(String args[]){new ex12_2();}ex12_2( ){______;setSize(200,200);Button btn=new Button("exit");btn.addActionListener (this);add (btn, "North" );l=new Label(str);add (l, "South" );show ();}public void mouseMoved(MouseEvent event){str="Move: "+l. setText (str);}public void mouseDragged(MouseEvent event){}public void actionPerformed(ActionEvent event){if(event.getActionCommand().equals("exit")){System.exit(0);}}}
public void testIfA(){if(testIfB(True)){System.out.println(True);}else{System.out.println(Nottrue);}}public Boolean testIfB(Stringstr){return Boolean.valueOf(str);}What is the result when method testIfA is invoked?()A.TrueB.NottrueC.Anexceptionisthrownatruntime.D.Compilationfailsbecauseofanerroratline12.E.Compilationfailsbecauseofanerroratline19.
下列______方法属于MouseMotionListener接口中的方法。A.mouseExited(MouseEvent)B.mouseEntered(MouseEvent)C.mouseMoved(MouseEvent)D.mousePressed(MouseEvent)
阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是A.1B.nullC.D.编译不能过
下列代码的编译或执行结果是( )。 public class Myval{ public static void main(string args[]){ MyVal m=new MyVal; aMethod; } public void aMethod{ boolean b[]=new Boolean[5]; System.OUt.println(b[0]); } }A.1B.nullC.0D.编译错误
阅读以下说明和JAVA 2代码,填入(n)处。[说明]以下程序实现了利用鼠标任意移动圆形的位置,仔细阅读代码和相关注释,将程序补充完整。[代码6-1]import java.awt.*;import java.awt.event.*;public class CIUSAMPLE extends Frame. implements MouseMotionListener, MouseListener{static CIUSAMPLE frm=new CIUSAMPLE ( );int x=70,y=60,posX=70,posY=60,dx,dy;public static void main (String args[]){frm.setTitle ("Dragging a circle");frm.setSize (200,150);(1)ffm.addMouseMotionListener (frm);frm.setVisible (true);}public void mousePressed (MouseEvent e){(2)dy=e.getY ( ) -posY;}public void mouseDragged (MouseEvent e){(3)y=e.getY ( ) -dy;if(dx>0dx<50dy>0dy<50) //如果指针落在正方形区域内{Graphicsg=getGraphics ( );(4)}}public void paint (Graphics g){g.setColor (Color.pink); //设置绘图颜色为粉红g.fillOval(x,y,50,50); //以基准点为图形在左上角绘出圆形(5)posY=y;}public void mouseMoved (MouseEvent e) {}public void mouseReleased (MouseEvent e) {}public void mouseEntered (MouseEvent e) {}public void mouseExited (MouseEvent e) {}public void mouseClicked (MouseEvent e) {}}
本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为"鼠标的当前位置:X:Y"(其中,X为横坐标,Y为纵坐标)。import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;public class java2{public static void main(String[]args){MouseFrame. frame=new MouseFrame();frame.setDefaultCloseoperation(JFrame.EXIT_0N CLOSE);frame.show();}}class MouseFrame. extends JFrame{public MouseFrame(){setTitle("java2");setSize(WIDTH,HEIGHT);MousePanel panel=new MousePanel();Container contentPane=getContentPane();contentPane.add(panel);}public static final int WIDTH = 300;public static final int HEIGHT=200;}class MousePanel extends JPanel{public MousePanel(){addMouseListener(new MouseHandler());addMouseMotionListener(new MouseMotionHan-dler());}public void paintComponent(Graphics g)(super.paintComponent(g);String text="鼠标指针位置:"+mousex+":"+mousey;g.drawString(text,10,10);}private int mousex,mousey;private class MouseMotionHandler {public void mouseMoved(MouseEvent event){mousex=event.getX();mousey=event.getY();repaint();}public void mouseDragged(MouseEvent event){mousex=event.getX();mousey=event.getY();repaint();}}private class MouseHandler{public void mousePressed(MouseEvent eveat){mousex=event.getX();mousey=event.getY();}}}
以下哪个是Java应用程序main方法的有效定义? A. public static void main();B. public static void main( String args );C. public static void main( String args[] );D. public static void main( Graphics g );E. public static boolean main( String a[] );
以下哪个方法可以用来获得进度条的当前进度值?()A、public synchronized int getProgress()B、public synchronized void setIndeterminate (boolean indeterminate)C、public synchronized void setProgress(int progress)D、Public final synchronized void incrementProgressBy(int diff)
public interface A { String DEFAULT_GREETING = “Hello World”; public void method1(); } A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?() A、 public interface B extends A {}B、 public interface B implements A {}C、 public interface B instanceOf A {}D、 public interface B inheritsFrom A {}
interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?() A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
A JavaBeans component has the following field: 11. private boolean enabled; Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()A、 public void setEnabled( boolean enabled) public boolean getEnabled()B、 public void setEnabled( boolean enabled) public void isEnabled()C、 public void setEnabled( boolean enabled) public boolean isEnabled()D、 public boolean setEnabled( boolean enabled) public boolean getEnabled()
Which method must be defined by a class implementing the java.lang.Runnable interface? () A、 void run()B、 public void run()C、 public void start()D、 void run(int priority)E、 public void run(int priority)F、 public void start(int priority)
public void testIfA(){ if(testIfB("True")){ System.out.println("True"); }else{ System.out.println("Nottrue"); } } public Boolean testIfB(Stringstr){ return Boolean.valueOf(str); } What is the result when method testIfA is invoked?()A、TrueB、NottrueC、Anexceptionisthrownatruntime.D、Compilationfailsbecauseofanerroratline12.E、Compilationfailsbecauseofanerroratline19.
public class Key { private long id1; private long 1d2; // class Key methods } A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()A、 public int hashCode()B、 public boolean equals(Key k)C、 public int compareTo(Object o)D、 public boolean equals(Object o)E、 public boolean compareTo(Key k)
单选题public interface A { String DEFAULT_GREETING = “Hello World”; public void method1(); } A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?()A public interface B extends A {}B public interface B implements A {}C public interface B instanceOf A {}D public interface B inheritsFrom A {}
单选题Which method must be defined by a class implementing the java.lang.Runnable interface? ()A void run()B public void run()C public void start()D void run(int priority)E public void run(int priority)F public void start(int priority)
多选题A JavaBeans component has the following field: 11. private boolean enabled; Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()Apublic void setEnabled( boolean enabled) public boolean getEnabled()Bpublic void setEnabled( boolean enabled) public void isEnabled()Cpublic void setEnabled( boolean enabled) public boolean isEnabled()Dpublic boolean setEnabled( boolean enabled) public boolean getEnabled()
单选题下列代码的编译或执行结果是( )。public class MyVal{ public static void main(String args[]){ MyVal m = new MyVal(); m.aMethod(); } public void aMethod(){ boolean b[] = new Boolean[5]; System.out.println(b[0]); }}A1BnullC0D编译错误
单选题Which is a method of the MouseMotionListener interface?()A Public void mouseMoved(MouseEvent)B Public boolean mouseMoved(MouseEvent)C Public void mouseMoved(MouseMotionEvent)D Public boolean MouseMoved(MouseMotionEvent)E Public boolean mouseMoved(MouseMotionEvent)
单选题public void testIfA(){ if(testIfB("True")){ System.out.println("True"); }else{ System.out.println("Nottrue"); } } public Boolean testIfB(Stringstr){ return Boolean.valueOf(str); } What is the result when method testIfA is invoked?()ATrueBNottrueCAnexceptionisthrownatruntime.DCompilationfailsbecauseofanerroratline12.ECompilationfailsbecauseofanerroratline19.
单选题interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?()A public class Employee extends Info implements Data { public void load() { /*do something*/ } }B public class Employee implements Info extends Data { public void load() { /*do something*/ } }C public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }