当前位置: 技术问答>java相关
各位大虾:这个applet程序为什么运行时不能初始化???
来源: 互联网 发布时间:2014-12-25
本文导语: //启动时读如一个图像(存放在当前目录);然后可以用鼠标选取一个区域,图像将在新 //的区域重新显示。 // example1.htm //-------------------------------------------------------------------- MyApp Example1 MyApp ...
//启动时读如一个图像(存放在当前目录);然后可以用鼠标选取一个区域,图像将在新
//的区域重新显示。
// example1.htm
//--------------------------------------------------------------------
MyApp Example1
MyApp
//ttt6.java
//--------------------------------------------------------------------
import java.*;
import java.lang.Math;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public abstract class ttt6 extends Applet implements MouseListener {
Image image;
boolean bMouseDownFlag = false;
boolean bMouseUpFlag = false;
Point ptAnchor,ptDrawTo;
public void init() {
image = getImage(getCodeBase(),"ht1.bmp");
addMouseListener(this);
}
public void mousePressed(MouseEvent e) {
bMouseDownFlag = true;
bMouseUpFlag = false;
ptAnchor = new Point(e.getX(),e.getY());
}
public void mouseReleased(MouseEvent e) {
bMouseDownFlag = false;
bMouseUpFlag = true;
ptDrawTo = new Point(Math.max(e.getX(),ptAnchor.x),Math.max(e.getY(),ptAnchor.y));
ptAnchor = new Point(Math.min(e.getX(),ptAnchor.x),Math.min(e.getY(),ptAnchor.y));
repaint();
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void paint(Graphics g) {
int drawWidth,drawHeight;
if(bMouseUpFlag) {
drawWidth = ptDrawTo.x - ptAnchor.x;
drawHeight = ptDrawTo.y - ptAnchor.y;
g.drawRect(ptAnchor.x,ptAnchor.y,drawWidth,drawHeight);
g.drawImage(image,ptAnchor.x,ptAnchor.y,drawWidth,drawHeight,this);
}
}
}
//的区域重新显示。
// example1.htm
//--------------------------------------------------------------------
MyApp Example1
MyApp
//ttt6.java
//--------------------------------------------------------------------
import java.*;
import java.lang.Math;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public abstract class ttt6 extends Applet implements MouseListener {
Image image;
boolean bMouseDownFlag = false;
boolean bMouseUpFlag = false;
Point ptAnchor,ptDrawTo;
public void init() {
image = getImage(getCodeBase(),"ht1.bmp");
addMouseListener(this);
}
public void mousePressed(MouseEvent e) {
bMouseDownFlag = true;
bMouseUpFlag = false;
ptAnchor = new Point(e.getX(),e.getY());
}
public void mouseReleased(MouseEvent e) {
bMouseDownFlag = false;
bMouseUpFlag = true;
ptDrawTo = new Point(Math.max(e.getX(),ptAnchor.x),Math.max(e.getY(),ptAnchor.y));
ptAnchor = new Point(Math.min(e.getX(),ptAnchor.x),Math.min(e.getY(),ptAnchor.y));
repaint();
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void paint(Graphics g) {
int drawWidth,drawHeight;
if(bMouseUpFlag) {
drawWidth = ptDrawTo.x - ptAnchor.x;
drawHeight = ptDrawTo.y - ptAnchor.y;
g.drawRect(ptAnchor.x,ptAnchor.y,drawWidth,drawHeight);
g.drawImage(image,ptAnchor.x,ptAnchor.y,drawWidth,drawHeight,this);
}
}
}
|
应该是public abstract class ttt6 中的abstract出问题了吧?
applet能定义成抽象的吗?不能实例化了。
去掉abstract 试试。
applet能定义成抽象的吗?不能实例化了。
去掉abstract 试试。