分類: 電腦/網(wǎng)絡(luò) 程序設(shè)計(jì) 其他編程語(yǔ)言
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比漢陰網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式漢陰網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋漢陰地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。
問題描述:
要能在Eclipse下運(yùn)行通過。感激涕零!
解析:
很簡(jiǎn)單啊,我給你一個(gè)java類庫(kù)里的接口怎樣啊?是一個(gè)經(jīng)常用到的MouseListener:
/*
* @(#)MouseListener.java 1.17 03/12/19
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package java.awt.event;
import java.util.EventListener;
/**
* The listener interface for receiving "interesting" mouse events
* (press, release, click, enter, and exit) on a ponent.
* (To track mouse moves and mouse drags, use the
* codeMouseMotionListener/code.)
* P
* The class that is interested in processing a mouse event
* either implements this interface (and all the methods it
* contains) or extends the abstract codeMouseAdapter/code class
* (overriding only the methods of interest).
* P
* The listener object created from that class is then registered with a
* ponent using the ponent's codeaddMouseListener/code
* method. A mouse event is generated when the mouse is pressed, released
* clicked (pressed and released). A mouse event is also generated when
* the mouse cursor enters or leaves a ponent. When a mouse event
* occurs, the relevant method in the listener object is invoked, and
* the codeMouseEvent/code is passed to it.
*
* @author Carl Quinn
* @version 1.17, 12/19/03
*
* @see MouseAdapter
* @see MouseEvent
* @see a href="java.sun/docs/books/tutorial/post1.0/ui/mouselistener"Tutorial: Writing a Mouse Listener/a
* @see a href="awl/cp/javaseries/jcl1_2"Reference: The Java Class Libraries (update file)/a
*
* @since 1.1
*/
public interface MouseListener extends EventListener {
/**
* Invoked when the mouse button has been clicked (pressed
* and released) on a ponent.
*/
public void mouseClicked(MouseEvent e);
/**
* Invoked when a mouse button has been pressed on a ponent.
*/
public void mousePressed(MouseEvent e);
/**
* Invoked when a mouse button has been released on a ponent.
*/
public void mouseReleased(MouseEvent e);
/**
* Invoked when the mouse enters a ponent.
*/
public void mouseEntered(MouseEvent e);
/**
* Invoked when the mouse exits a ponent.
*/
public void mouseExited(MouseEvent e);
}
接口與類的寫法差不多,這個(gè)接口放在MouseListener.java(稱為一個(gè)編輯單元)里.
//Muitiplication接口
public interface Muitiplication{
double mult(double a, double b);
}
//MuitiplicationImpl實(shí)現(xiàn)類
public class MuitiplicationImpl implements Muitiplication{
public double mult(double a, double b){
return a * b;
}
}
//MuitiplicationImpls實(shí)現(xiàn)類
public class MuitiplicationImpls implements Muitiplication{
public double mult(double a, double b){
return a + b;
}
}
public static void main(args[]){
MuitiplicationImpl m = new MuitiplicationImpl();
System.out.println(m.mult(1.001,1.001));
MuitiplicationImpls ms = new MuitiplicationImpls();
System.out.println(ms.mult(1.001,1.001));
}
interface Bike{
public void radio();
}
interface Car{
public void tv();
}
interface Dt{
public void music();
}
public class InterfaceDemo implements Bike,Car,Dt{
public void radio() {
System.out.println("可以聽廣播");
}
public void tv() {
System.out.println("可以看電視");
}
public void music() {
System.out.println("可以聽音樂");
}
public static void main(String args[])
{
InterfaceDemo m=new InterfaceDemo();
m.radio();
m.tv();
m.music();
}
}
Display.java ? 接口代碼如下:
public?interface?Display?{
public?void?dis();
}
接口的實(shí)現(xiàn)類DisplayImpl.java ? ?代碼如下:
public?class?DisplayImpl?implements?Display?{
@Override
public?void?dis()?{
//?TODO?Auto-generated?method?stub
System.out.println("輸出方法");
}
public?static?void?main(String[]?args)?{
new?DisplayImpl().dis();
}
}