Java applet 问题紧急高分求助!!!
1.WriteaJavaappletwhichwaitsforakeytobepressedandthendrawsalinefromtheposition(50,50)...
1. Write a Java applet which waits for a key to be pressed and then draws a line from the
position (50, 50) to a position given as a parameter to the applet. The applet object
should register itself as the event handler.
写一个java applet 当一个键盘上的按键被按下时 程序会从点(50,50)画一条直线到一个给定的参数点,程序把自己作为事件处理器
2. Write a Java applet which waits for a mouse button to be clicked and then outputs the
text ‘Hello World!’ at a position in the frame given as a parameter to the applet. The
applet object should register itself as the event handler but you need not provide
implementations for unused ‘MouseListener’ methods.
写一个java applet 当一个button被按下时, 输出“Hello World!” 到一个给定的位置(参数)。程序把自己作为事件处理器,但是不需要 实现 没有用到的 MouseListener 的方法。
翻译仅供参考,具体内容按照英文为准 展开
position (50, 50) to a position given as a parameter to the applet. The applet object
should register itself as the event handler.
写一个java applet 当一个键盘上的按键被按下时 程序会从点(50,50)画一条直线到一个给定的参数点,程序把自己作为事件处理器
2. Write a Java applet which waits for a mouse button to be clicked and then outputs the
text ‘Hello World!’ at a position in the frame given as a parameter to the applet. The
applet object should register itself as the event handler but you need not provide
implementations for unused ‘MouseListener’ methods.
写一个java applet 当一个button被按下时, 输出“Hello World!” 到一个给定的位置(参数)。程序把自己作为事件处理器,但是不需要 实现 没有用到的 MouseListener 的方法。
翻译仅供参考,具体内容按照英文为准 展开
展开全部
按照你的要求编写的java applet程序如下:(不知道是不是你要的效果)
一. DD.java文件
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class DD extends Applet implements MouseListener{
int x,y;
public void init(){
addMouseListener(this);
}
public void paint(Graphics g){
g.drawLine(50, 50, x, y);
}
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent me) {
x=me.getX();
y=me.getY();
repaint();
}
public void mouseReleased(MouseEvent arg0) {
}
}
二. DDD.java文件
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class DDD extends Applet implements MouseListener{
int x,y;
public void init(){
addMouseListener(this);
}
public void paint(Graphics g){
g.drawString("HelloWorld!", x, y);
}
public void mouseClicked(MouseEvent me) {
x=me.getX();
y=me.getY();
repaint();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询