Topic: swt 问题求助 |
Print this page |
1.swt 问题求助 | Copy to clipboard |
Posted by: poorbug Posted on: 2004-06-02 17:30 我想实现通过一个按钮来控制字符串的变化,写出的代码如下.问题是我怎么才 能够让字符串不重叠?即显示第二个字符串时自动消去第一个,如此循环. 我想了好久都没解决,请高手指点,Thanks!!! *************************************** import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.events.*; public class Test602{ private static Display display=new Display(); private static Shell parent= new Shell(display); private Label label1; private Button button1; private String string=new String(); private GC gc =new GC(parent); private boolean bool = false; public Test602(Shell parent,int sytle) { } public static void main(String[] args) { showGUI(); } public static void showGUI(){ Test602 Test = new Test602(parent,SWT.NULL); Test.open(); } public void open() { parent.setBounds(0,0,800,600); parent.open(); button1=new Button(parent,SWT.NULL); button1.setBounds(100,100,100,40); button1.setText("CHANGE"); SelectionAdapter a1 = new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { System.out.println("click"); if(bool==false) { string="hi!"; gc.drawText(string,0,0); bool=true; } else { string="hello!"; gc.drawText(string,0,0); bool=false; } } }; button1.addSelectionListener(a1); while(!parent.isDisposed()) { if(!display.readAndDispatch()) display.sleep(); } } } |
2.Re:swt 问题求助 [Re: poorbug] | Copy to clipboard |
Posted by: Jay Posted on: 2004-06-05 19:31 再你调用drawText()的时候需要完全覆盖掉上一次画出的区域 你可以这样做: 首先取得最长字符串的长和宽 Point size=gc.textExtent("hello"); 在绘制短字符串之前先填充长字符串的区域 gc.fillRectangle(0,0,size.x,size.y); gc.drawText("hi", 0, 0,false); |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |