J2ME中canvas如何通过drawline方法绘制矩形
这是我第一次在这里提问。
我是 J2ME 新手,现在正在开发一个小型应用程序,但是当我想将数据显示到表中时遇到问题。但在 J2me 中不支持表,因为我知道另一种方式可以表示表,例如通过 Canvas 或 CustomItem 创建表。
在画布中,我可以画2条线,例如:
-----------------------
|
|
|
|
但我不知道如何获得2条线的坐标,例如:
|
|
|
|
|
--------------------------
两条线在整个屏幕上绘制一个矩形,
我知道画线方法有4个因素x1,y1,x2,y2。
但我无法计算 x 点和 y 点来在上面画两条线
我需要你帮我解释或给我例子
我的代码:
package test;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
/**
*
* @author J2MENewBie
*/
public class TableCanvasExample extends Canvas {
private int cols=3;
private int rows =50;
protected void paint(Graphics g) {
g.setColor(0x94b2ff);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
//draw two lines
g.setColor(0xf8011e);
g.drawLine(0, 0, 0, this.getWidth());
g.drawLine(0, 0, this.getHeight(), 0);
}
}
package test;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;
/**
* @author J2ME NewBie
*/
public class TableCanvasMidlet extends MIDlet {
private TableCanvasExample tbcve;
public TableCanvasMidlet(){
tbcve = new TableCanvasExample();
}
public void startApp() {
Display.getDisplay(this).setCurrent(tbcve);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
P/s:垂直线不是完整尺寸我不知道为什么???
谢谢你!
This is first time I at a question in here.
Im new in J2ME, and now im developing a small application, but i get problem when i wanna show data into table. But in J2me not support table there for that i know another way can represent for table such as create table by Canvas or CustomItem.
In Canvas i can draw 2 lines something like:
-----------------------
|
|
|
|
but i dont know how can get coordinate of 2 lines remain such as like:
|
|
|
|
|
--------------------------
two draw a rectangular in whole screen,
i know drawline method has 4 factors x1,y1,x2,y2.
but i can not calculate x point and y point to draw two lines above
I need you help me explain or give me example
My Code:
package test;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
/**
*
* @author J2MENewBie
*/
public class TableCanvasExample extends Canvas {
private int cols=3;
private int rows =50;
protected void paint(Graphics g) {
g.setColor(0x94b2ff);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
//draw two lines
g.setColor(0xf8011e);
g.drawLine(0, 0, 0, this.getWidth());
g.drawLine(0, 0, this.getHeight(), 0);
}
}
package test;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;
/**
* @author J2ME NewBie
*/
public class TableCanvasMidlet extends MIDlet {
private TableCanvasExample tbcve;
public TableCanvasMidlet(){
tbcve = new TableCanvasExample();
}
public void startApp() {
Display.getDisplay(this).setCurrent(tbcve);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
P/s: the vertical line doesn't full size i dont know why ???
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码中有太多看起来相同的零 - 尝试使用描述性名称来代替:
如果绘制的矩形看起来不像您期望的那样,请找到上面代码中存在错误语义的地方
too much same-looking zeroes in your code - try using descriptive names instead:
if rectangle drawn doesn't look like you expect find where there is wrong semantic in code above