游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1618|回复: 0

简单画图的请教

[复制链接]

12

主题

525

帖子

525

积分

高级会员

Rank: 4

积分
525
发表于 2007-1-26 10:55:00 | 显示全部楼层 |阅读模式
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.geom.*;
public class line
{
public static void main(String[] args)
{
CreatFrame frame=new CreatFrame();
frame.setDefaultCloseOperation(3);
frame.setVisible(true);
frame.setResizable(false);
}
}
class CreatFrame extends JFrame
{
public CreatFrame()
{
setTitle("测试");
setSize(X,Y);

CreatPanel panel=new CreatPanel();
Container contentPane=getContentPane();
contentPane.add(panel);
}
public static final int X=320;
public static final int Y=240;
}
class CreatPanel extends JPanel  
{
public double sX;
public double sY;
public double Ex;
public double Ey;
public CreatPanel()
{
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
sX=e.getX();
sY=e.getY();
//System.out.println(sX+":"+sY);
}
public void mouseReleased(MouseEvent e)
{
Ex=e.getX();
Ey=e.getY();
//System.out.println(Ex+":"+Ey);
}
});
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.RED);
Line2D line=new Line2D.Double(sX,sY,Ex,Ey);
System.out.println(sX+":"+sY);
g2.draw(line);
}
}

编译没错误,为什么运行时候画不出来呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 08:05

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表