public static void main(String[] args) {

final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("横线");
shell.setSize(1024,768);
shell.open();
shell.addPaintListener(new PaintListener(){ 
        public void paintControl(PaintEvent e){
         int rowx=10,rowy=10,rowx1=1000,rowy1=10;
     int listx=10,listy=10,listx1=10,listy1=1000;
GC gc = new GC(shell);
GC gs= new GC(shell);
int ix[]= {10,10,10,20,20,20,20,10};
gc.drawPolygon(ix);
for(int i=0;i<100;i++){
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.drawRoundRectangle(listx+2, rowy+2, 3, 3,5, 5);//画圆圈
gs.setAlpha(50);//设置透明度。
gs.setForeground(display.getSystemColor(SWT.COLOR_DARK_RED));
gs.drawLine(listx, listy, listx1, listy1);
gs.drawLine(rowx, rowy, rowx1, rowy1);
listx+=10;
listx1+=10;
rowy=rowy+10;
rowy1=rowy1+10;
}

        } 
        
    }); 

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}这代码能画出线和圆圈,但我想知道怎么画出小叉子来呢?(x)有知道的希望能告诉下,谢谢了

解决方案 »

  1.   

    右击键盘属性,选择“数学符号”,里面有个乘的符号,就是你要的小叉子了(x)!
    String input="×";
    ..........
    ...........
      

  2.   

    这个方法确实很管用,可是有swt里面有没有什么类活方法能直接画出X来啊。因为你那个输出的是个字符,很容易把别的线条和图给覆盖了,那就不后了!
      

  3.   

    把你"// 画圆圈"那段代码注释掉.加上下面的代码,就是X了! // Draw Fork Start
    int x = listx;
    int y = rowy;
    int[] shape = new int[] { x, y, x + 2, y, x + 4, y + 2,
    x + 5, y + 2, x + 7, y, x + 9, y, x + 9, y + 2,
    x + 7, y + 4, x + 7, y + 5, x + 9, y + 7, x + 9,
    y + 9, x + 7, y + 9, x + 5, y + 7, x + 4, y + 7,
    x + 2, y + 9, x, y + 9, x, y + 7, x + 2, y + 5,
    x + 2, y + 4, x, y + 2 };
    gc.fillPolygon(shape);
    gc.drawPolygon(shape);
    // Draw Fork End
      

  4.   

    实际上这就是在画一个多边形,shape 这个数组的每两个元素为一个点,一个点一个点地描述出多边形来就OK了。
    比如上面的代码
    x, y是第一个点
    x + 2, y, x + 4是第二个点。