java 方法声明无效,需要返回值
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassHelloJavaexten...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HelloJava
extends JComponent implements MouseMotionListner{
int messageX=125,messageY=95;
String theMessage;
public HelloJava2(String message){
theMessage=message;
addMouseMotionListener(this); 这里出错。
}
public void paintComponent(Graphics g){
g.drawString(theMessage,messageX,messageY);
}
public void mouseDragged(MouseEvent e){
messageX=e.getX();
messageY=e.getY();
repaint();
}
public void mouseMoved(MouseEvent e){}
public static void main(String[] args){
JFrame f=new JFrame("HelloJava2");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){System.exit(0);}
});
f.setSize(300,300);
f.getContentPane().add(new HelloJava2("Hello,java!"));
f.setvisible(true);
}
} 展开
import java.awt.event.*;
import javax.swing.*;
public class HelloJava
extends JComponent implements MouseMotionListner{
int messageX=125,messageY=95;
String theMessage;
public HelloJava2(String message){
theMessage=message;
addMouseMotionListener(this); 这里出错。
}
public void paintComponent(Graphics g){
g.drawString(theMessage,messageX,messageY);
}
public void mouseDragged(MouseEvent e){
messageX=e.getX();
messageY=e.getY();
repaint();
}
public void mouseMoved(MouseEvent e){}
public static void main(String[] args){
JFrame f=new JFrame("HelloJava2");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){System.exit(0);}
});
f.setSize(300,300);
f.getContentPane().add(new HelloJava2("Hello,java!"));
f.setvisible(true);
}
} 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询