分类: 电脑/网络 >> 程序设计 >> 其他编程语言
问题描述:
本程序要实现的是随着鼠标点击,将在画布上话小方块。
import javaawt;
import javaawtevent;
import javautil;
import javaawtgeom;
import javaxswing;
public class MouseTest
{
public static void main(String[] args)
{
MouseFrame frame=new MouseFrame();
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
frameshow();
}
}
class MouseFrame extends JFrame
{
public MouseFrame()
{
setTitle("MouseTest");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
MousePanel panel=new MousePanel();
Container contentPane=getContentPane();
contentPaneadd(panel);
}
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=200;
}
class MousePanel extends JPanel
{
public MousePanel()
{
squares=new ArrayList();
current=null;
addMouseListener(new MouseHandler());
addMouseMotionListener(new MouseMotionHandler());
}
public void paintComponent(Graphics g)
{
superpaintComponent(g);
Graphics2D g2=(Graphics2D)g;
g2setPaint(ColorRED);
for(int i=0;i<squaressize();i++)
g2draw((Rectangle2D)squaresget(i));
}
public Rectangle2D find(Point2D p)
{
for(int i=0;i<squaressize();i++)
{
Rectangle2D r=(Rectangle2D)squaresget(i);
if(rcontains(p)) return r;
}
return null;
}
public void add(Point2D p)
{
double x=pgetX();
double y=pgetY();
current=new Rectangle2DDouble(x-SIDELENGTH/2,y-SIDELENGTH/2,SIDELENGTH,SIDELENGTH);
squaresadd(current);
repaint();
}
public void remove(Rectangle2D s)
{
if(s==null)return;
if(s==current) current=null;
squaresremove(s);
repaint();
}
private static final int SIDELENGTH=10;
private ArrayList squares;
private Rectangle2D current;
private class MouseHandler extends MouseAdapter
{
public void mouseHandler(MouseEvent event)
{
current=find(eventgetPoint());
if(current==null)
add(eventgetPoint());
}
public void mouseClicked(MouseEvent event)
{
current=find(eventgetPoint());
if(current==null&&eventgetClickCount()>=2)
remove(current);
}
}
private class MouseMotionHandler implements MouseMotionListener
{
public void mouseMoved(MouseEvent event)
{
if(find(eventgetPoint())==null)
setCursor(CursorgetDefaultCursor());
else
setCursor(CursorgetPredefinedCursor(CursorCROSSHAIR_CURSOR));
}
public void mouseDragged(MouseEvent event)
{
if (current!=null)
{
int x=eventgetX();
int y=eventgetY();
currentsetFrame(x-SIDELENGTH/2,y-SIDELENGTH/2,SIDELENGTH,SIDELENGTH);
repaint();
}
}
}
}
解析:
这地方是改错的,不是给你实现功能的,哈哈
#include<stdioh>
void main()
{
int n;
float s=10;
for(n=10;n>1;n--)
s=s+10/n; //这里要用10,否则分子分母都是整型结果也被截取为整型
printf("%61f",s);
}
void GreateGraphAL(ALGraph G)参数值G只是一个指向ALGraphi类型的指针,指针指向哪里并没有赋值,那你在函数你重新构造一个或者改为void GreateGraphAL(ALGraph G)
可能是你使用的皮肤用
都是粗体字体。
右键点击搜狗皮肤,设置属性,外观,勾选更换字体,中文选择宋体,确定。
如果是选完的字是粗体,那就是其他程序的问题,找到该软件调节字体的地方调一下即可。
以上就是关于简单java程序改错!全部的内容,包括:简单java程序改错!、C语言程序设计改错;、为我的程序改错等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)