当前位置: 技术问答>java相关
请看一段代码
来源: 互联网 发布时间:2015-03-25
本文导语: 请问何为JAVA中自己调用自己定义的类? 下面的代码中在MAIN(STRING ARGV[])实例了自立定义的类,是什么语法? import java.awt.*; import java.awt.event.*; //AWTㄆン甅ン public class Mouse extends Frame { public static void main(...
请问何为JAVA中自己调用自己定义的类?
下面的代码中在MAIN(STRING ARGV[])实例了自立定义的类,是什么语法?
import java.awt.*;
import java.awt.event.*; //AWTㄆン甅ン
public class Mouse extends Frame {
public static void main(String argv[]){
new Mouse();
}
public Mouse(){
super("Mouse");
Demo_Mouse_Listener testListener = new Demo_Mouse_Listener();
addMouseListener(testListener);
addMouseMotionListener(testListener);
setSize(200,200);
show();
}
}
class Demo_Mouse_Listener implements MouseListener, MouseMotionListener {
//龟渡钮ざよ猭
public void mouseDragged(MouseEvent e) {
System.out.println("菲公砆╈笆");
}
public void mouseMoved(MouseEvent e) {
System.out.println("菲公砆簿笆");
}
public void mousePressed(MouseEvent e) {
System.out.println("菲公砆溃");
if(e.getClickCount() > 1)
System.exit(-1);
}
public void mouseReleased(MouseEvent e) {
System.out.println("菲公砆秨");
}
public void mouseEntered(MouseEvent e) {
System.out.println("菲公村夹秈ㄓ");
}
public void mouseExited(MouseEvent e) {
System.out.println("菲公村夹瞒秨");
}
public void mouseClicked(MouseEvent e) {
System.out.println("菲公砆");
}
}
下面的代码中在MAIN(STRING ARGV[])实例了自立定义的类,是什么语法?
import java.awt.*;
import java.awt.event.*; //AWTㄆン甅ン
public class Mouse extends Frame {
public static void main(String argv[]){
new Mouse();
}
public Mouse(){
super("Mouse");
Demo_Mouse_Listener testListener = new Demo_Mouse_Listener();
addMouseListener(testListener);
addMouseMotionListener(testListener);
setSize(200,200);
show();
}
}
class Demo_Mouse_Listener implements MouseListener, MouseMotionListener {
//龟渡钮ざよ猭
public void mouseDragged(MouseEvent e) {
System.out.println("菲公砆╈笆");
}
public void mouseMoved(MouseEvent e) {
System.out.println("菲公砆簿笆");
}
public void mousePressed(MouseEvent e) {
System.out.println("菲公砆溃");
if(e.getClickCount() > 1)
System.exit(-1);
}
public void mouseReleased(MouseEvent e) {
System.out.println("菲公砆秨");
}
public void mouseEntered(MouseEvent e) {
System.out.println("菲公村夹秈ㄓ");
}
public void mouseExited(MouseEvent e) {
System.out.println("菲公村夹瞒秨");
}
public void mouseClicked(MouseEvent e) {
System.out.println("菲公砆");
}
}
|
没什么特别的语法。因为你编译完成之后,该类就可以被访问了,当然可以生成它的对象。
|
new Mouse();
这一句实例了你自己定义的类。
这一句实例了你自己定义的类。