java 画个图
我想把6,55,44,33,42,51,6这六个点用java画图绘制出来,类似于棋盘格的形式,这几个点所代表的方格为红色,其余格为蓝色~怎么写?帮忙,晚上查~...
我想把6,5 5,4 4,3 3,4 2,5 1,6这六个点用java 画图绘制出来,类似于棋盘格的形式,这几个点所代表的方格为红色,其余格为蓝色~ 怎么写? 帮忙,晚上查~
展开
1个回答
展开全部
不明白你说的意思,到底是画点呢,还是画方格呢?
追问
额...就是 10*10的方格,然后 这些点代表这些方格的位置~ 明白了吗?
追答
不知道是不是这个意思:
一次贴不完了。。。
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/**
* @author 熙熙
* @2011-4-19
*/
class GraphicPanel extends JPanel {
private int rows = 10;
private int cols = 10;
private int blockSize = 40;
private Point[] someBlockIndexs = { new Point(6, 5), new Point(5, 4),
new Point(4, 3), new Point(3, 4), new Point(2, 5), new Point(1, 6) };
private Color colorForSomeBlocks = Color.RED;
private Color colorForAllBlocks = Color.BLUE;
public GraphicPanel() {
this(10, 10, 40);
}
public GraphicPanel(int rows, int cols) {
this(rows, cols, 40);
}
public GraphicPanel(int rows, int cols, int blockSize) {
super();
this.rows = rows;
this.cols = cols;
this.blockSize = blockSize;
this.setOpaque(false);
setSize(cols * blockSize, rows * blockSize);
this.repaint();
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
this.rows = rows;
}
public int getCols() {
return cols;
}
public void setCols(int cols) {
this.cols = cols;
}
public int getBlockSize() {
return blockSize;
}
public void setBlockSize(int blockSize) {
this.blockSize = blockSize;
}
public Point[] getSomeBlockIndexs() {
return someBlockIndexs;
}
public void setSomeBlockIndexs(Point[] someBlockIndexs) {
if (isBlockIndexsAvailable(someBlockIndexs)) {
this.someBlockIndexs = someBlockIndexs;
} else {
throw new IllegalArgumentException(
"the x index cound only between 1 to rows,and the y index cound only between 1 to cols");
}
}
public void setSomeBlockIndexsAndColor(Point[] someBlockIndexs,
Color colorForSomeBlocks) {
setSomeBlockIndexs(someBlockIndexs);
setColorForSomeBlocks(colorForSomeBlocks);
}
下面的是接着的:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询