[英]How to draw a rectangle in Java?
I am working on an application that needs to draw shapes (rectangle etc) by searching an array like: 我正在一个需要通过搜索数组来绘制形状(矩形等)的应用程序:
while(array!=null)
{
if(array.equals("x"))
then
drawRect(100,100,50,20);
}
Every rectangle must be drawn on a single Frame and with different coordinates. 每个矩形都必须在单个框架上绘制并使用不同的坐标。
There is an error in your code. 您的代码中有错误。 The word
then
doesn't exist in Java. 这个词
then
并不存在于Java中。
while(array!=null) {
if(array.equals("x")) {
drawRect(100,100,50,20);
}
}
There are so many example in Google. Google有很多例子。 The best of all is Drawing Geometric Primitives by Oracle Tutorials.
最好的是Oracle Tutorials的Drawing Geometric Primitives 。
public void paint (Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (yourCondition) {
g2.draw(new Rectangle2D.Double(x, y, rectwidth, rectheight));
}
}
// Define an array
String[] array = {"a","b","x"};
for(int i=0; i < array.length; i++)
{
if(array[i] == "x")
{
drawRect(100,100,50,20);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.