求将java源代码加详细的注释,程序已给出
程序后面加点解析,越详细越好!importjava.awt.Color;importjava.awt.Graphics;importjava.awt.Graphics2D...
程序后面加点解析,越详细越好!
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class pentagram extends JFrame implements KeyListener {
int x=150,y=150;
public pentagram() {
setSize(400, 400);
setVisible(true);
this.addKeyListener(this);
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==37)
{
x-=10;
repaint();
}
if(e.getKeyCode()==38)
{
y-=10;
repaint();
}
if(e.getKeyCode()==39)
{
x+=10;
repaint();
}
if(e.getKeyCode()==40)
{
y+=10;
repaint();
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public void paint(Graphics g) {
super.paint(g);
int xPoint[]={55,67,109,73,83,55,27,37,1,43};
int yPoint[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;
GeneralPath star=new GeneralPath();
star.moveTo(xPoint[0], yPoint[0]);
for(int count=1;count<xPoint.length;count++)
{
star.lineTo(xPoint[count], yPoint[count]);
}
star.closePath();
g2d.translate(x, y);
g2d.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
g2d.fill(star);
}
public static void main(String[] arge) {
pentagram s = new pentagram();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} 展开
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class pentagram extends JFrame implements KeyListener {
int x=150,y=150;
public pentagram() {
setSize(400, 400);
setVisible(true);
this.addKeyListener(this);
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==37)
{
x-=10;
repaint();
}
if(e.getKeyCode()==38)
{
y-=10;
repaint();
}
if(e.getKeyCode()==39)
{
x+=10;
repaint();
}
if(e.getKeyCode()==40)
{
y+=10;
repaint();
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public void paint(Graphics g) {
super.paint(g);
int xPoint[]={55,67,109,73,83,55,27,37,1,43};
int yPoint[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;
GeneralPath star=new GeneralPath();
star.moveTo(xPoint[0], yPoint[0]);
for(int count=1;count<xPoint.length;count++)
{
star.lineTo(xPoint[count], yPoint[count]);
}
star.closePath();
g2d.translate(x, y);
g2d.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
g2d.fill(star);
}
public static void main(String[] arge) {
pentagram s = new pentagram();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} 展开
展开全部
package com.the2cities.servlet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class pentagram extends JFrame implements KeyListener {
int x=150,y=150;
public pentagram() {
//初始化
setSize(400, 400);//设置大小
setVisible(true);//显示
this.addKeyListener(this);//按键的监听事件
}
public void keyPressed(KeyEvent e) {
//方向键
if(e.getKeyCode()==37)
{
x-=10; //向左边移动10像素
repaint(); //刷新
}
if(e.getKeyCode()==38)
{
y-=10; //向上边移动10像素
repaint();//刷新
}
if(e.getKeyCode()==39)
{
x+=10;//向右边移动10像素
repaint();//刷新
}
if(e.getKeyCode()==40)
{
y+=10;//向下边移动10像素
repaint();//刷新
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public void paint(Graphics g) {//重写了JFrame的paint,在上面刷新的方法可以调用到这个方法。
super.paint(g);
//A
int xPoint[]={55,67,109,73,83,55,27,37,1,43};
int yPoint[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;//整个窗口就是一个画板
GeneralPath star=new GeneralPath();
star.moveTo(xPoint[0], yPoint[0]);
for(int count=1;count<xPoint.length;count++)
{
star.lineTo(xPoint[count], yPoint[count]);
}
star.closePath();
//B
//A到B是画出一个星星。
g2d.translate(x, y);//设置星星位置,x,y就是上面,按方向键产生的数字。
g2d.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));//随机设置颜色
g2d.fill(star);//把星星放到画板里去。
}
public static void main(String[] arge) {
pentagram s = new pentagram();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class pentagram extends JFrame implements KeyListener {
int x=150,y=150;
public pentagram() {
//初始化
setSize(400, 400);//设置大小
setVisible(true);//显示
this.addKeyListener(this);//按键的监听事件
}
public void keyPressed(KeyEvent e) {
//方向键
if(e.getKeyCode()==37)
{
x-=10; //向左边移动10像素
repaint(); //刷新
}
if(e.getKeyCode()==38)
{
y-=10; //向上边移动10像素
repaint();//刷新
}
if(e.getKeyCode()==39)
{
x+=10;//向右边移动10像素
repaint();//刷新
}
if(e.getKeyCode()==40)
{
y+=10;//向下边移动10像素
repaint();//刷新
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public void paint(Graphics g) {//重写了JFrame的paint,在上面刷新的方法可以调用到这个方法。
super.paint(g);
//A
int xPoint[]={55,67,109,73,83,55,27,37,1,43};
int yPoint[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;//整个窗口就是一个画板
GeneralPath star=new GeneralPath();
star.moveTo(xPoint[0], yPoint[0]);
for(int count=1;count<xPoint.length;count++)
{
star.lineTo(xPoint[count], yPoint[count]);
}
star.closePath();
//B
//A到B是画出一个星星。
g2d.translate(x, y);//设置星星位置,x,y就是上面,按方向键产生的数字。
g2d.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));//随机设置颜色
g2d.fill(star);//把星星放到画板里去。
}
public static void main(String[] arge) {
pentagram s = new pentagram();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询