eclipse麻烦帮我看看,感谢! 就是我定义的类MyPanel中paint函数下if语句怎么才能进去,新手求解惑!
importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.awt.Grap...
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.awt.Point;
class Mouse extends MouseAdapter
{
protected ArrayList<Point> points=new ArrayList<Point>();
protected int endX=0,endY=0;
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount()==1)
points.add(new Point(e.getX(),e.getY()));
else if(e.getClickCount()==2)
{
endX=e.getX();
endY=e.getY();
}
}
}
class MyPanel extends JPanel
{
private Mouse mouse=new Mouse();
public MyPanel()
{
this.addMouseListener(mouse);
}
public void paint(Graphics g)
{
Graphics2D gg=(Graphics2D)g;
if(mouse.points.size()>0)
{
for(int i=0;i<mouse.points.size()-1;i++)
gg.drawLine(mouse.points.get(i).x, mouse.points.get(i).y, mouse.points.get(i+1).x, mouse.points.get(i+1).y);
gg.drawLine(mouse.endX,mouse.endY,mouse.points.get(0).x, mouse.points.get(0).y);
}
}
}
public class Paint extends JFrame{
private MyPanel mpl=new MyPanel();
public Paint()
{
this.add(mpl);
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String[] args) throws Exception
{
new Paint();
}
}
可能点了什么问题关闭了 。。。
求帮忙。。。 展开
import java.awt.event.MouseEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.awt.Point;
class Mouse extends MouseAdapter
{
protected ArrayList<Point> points=new ArrayList<Point>();
protected int endX=0,endY=0;
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount()==1)
points.add(new Point(e.getX(),e.getY()));
else if(e.getClickCount()==2)
{
endX=e.getX();
endY=e.getY();
}
}
}
class MyPanel extends JPanel
{
private Mouse mouse=new Mouse();
public MyPanel()
{
this.addMouseListener(mouse);
}
public void paint(Graphics g)
{
Graphics2D gg=(Graphics2D)g;
if(mouse.points.size()>0)
{
for(int i=0;i<mouse.points.size()-1;i++)
gg.drawLine(mouse.points.get(i).x, mouse.points.get(i).y, mouse.points.get(i+1).x, mouse.points.get(i+1).y);
gg.drawLine(mouse.endX,mouse.endY,mouse.points.get(0).x, mouse.points.get(0).y);
}
}
}
public class Paint extends JFrame{
private MyPanel mpl=new MyPanel();
public Paint()
{
this.add(mpl);
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String[] args) throws Exception
{
new Paint();
}
}
可能点了什么问题关闭了 。。。
求帮忙。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询