求大虾检查或修改,画图程序出不来图形
RT,编译器也通过了,是不是缺少了哪句,望指点
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.io.*;
import java.awt.geom.*;
class Point implements Serializable{
int x,y;
int tool;
Point(int x,int y,int tool){
this.x=x;
this.y=y;
this.tool=tool;
}
}
class paintboard extends Frame implements ActionListener{
MenuBar mb=new MenuBar();
Menu f=new Menu("Flie"),d=new Menu("Draw");
MenuItem n=new MenuItem("New"),ex=new MenuItem("Exit");
MenuItem l=new MenuItem("Line"),o=new MenuItem("Oval"),r=new MenuItem("Rectangle");
int screenWidth=800;
int screenHeight=600;
int painttype=0;
MyCanvas can=new MyCanvas(painttype);
public paintboard(String s){
super(s);
setSize(screenWidth,screenHeight);
setBackground(Color.white);
setMenuBar(mb);
mb.add(f);
f.add(n);
f.add(ex);
mb.add(d);
d.add(l);
d.add(o);
d.add(r);
n.addActionListener(this);
ex.addActionListener(this);
l.addActionListener(this);
o.addActionListener(this);
r.addActionListener(this);
add("Center",can);
validate();
setVisible(true);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==n) can.clear();
if(e.getSource()==ex) System.exit(0);
if(e.getSource()==l) painttype=0;
if(e.getSource()==o) painttype=1;
if(e.getSource()==r) painttype=2;
}
}
class MyCanvas extends Canvas implements MouseListener,MouseMotionListener{
int type;
int num=0;
Vector<Point> vec=new Vector<Point>();
Point P1,P2,P3;
public MyCanvas(int type){
super();
this.type=type;
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g){
g.setColor(Color.red);
int n=vec.size();
if(n>=2){
for(int i=0; i<n ;i=i+2){
P1 = (Point)vec.elementAt(i);
P2 = (Point)vec.elementAt(i+1);
if(P1.tool==P2.tool) {
switch(P1.tool) {
case 0://直线
g.drawLine(P1.x,P1.y,P2.x,P2.y);
break;
case 1://圆
g.drawOval(Math.min(P1.x,P2.x),Math.min(P1.y,P2.y),Math.abs(P2.x-P1.x),Math.abs(P2.y-P1.y));
break;
case 2://矩形
g.drawRect(Math.min(P1.x,P2.x),Math.min(P1.y,P2.y),Math.abs(P2.x-P1.x),Math.abs(P2.y-P1.y));