??xml version="1.0" encoding="utf-8" standalone="yes"?> Style Description SWT.SINGLE Allow a single line to be edited 单行 SWT.MULTI Allow multiple lines to be edited 多行 SWT.READ_ONLY Make the control noneditable 不可~辑 SWT.WRAP Allow strings to wrap instead of scrolling 自动换行 SWT.LEFT Left-align the contents of the control 左对?/P> SWT.CENTER Center-align the contents of the control 中间寚w SWT.RIGHT Right-align the contents of the control 叛_?/P> Event Description SWT.DefaultSelection Default selection occurred (user pressed <Enter>) SWT.Modify Text has changed in the control 控g中的文本内容发生了改?/P> SWT.Verify Text is to be validated in the control 文本内容需要验?/P>
java以这4个抽象类为基Q衍生出一pd具体的类Q几乎可以完成所有的输入/输出q程?BR>
InputStreamcL供了一个抽象方法:abstract int readQ)
d一个字节ƈ它q回Q由此类衍生出来的其它具体类都会覆盖q个ҎQ以提供有用的功能?BR>cM的,OutputStreamcd义了抽象Ҏabstract int writeQint bQ?BR>
完成的d操作后应C要用closeQ)Ҏ其关闭。关闭输出流的同时也会刷新输出流使用的缓冲区Q在~冲Z{待l合成一个较大的数据包的临时存储的字W,都会通过|络传送出厅R特别是Q加入没有关闭一个文Ӟ最后一个字节报可能永远都不会投递出厅R?BR>
InputStream和OutputStreamcd许我们读取单独的字节和字节数l,它们不对字符串及数字q行d。DataInputStream和DataOutputStream允许Ҏ有基本javacdq行d?BR>对于Unicode文本Q需使用Reader和Writer衍生出的c,它提供的基本Ҏ和InputStream和OutputStreamcMQabstract int readQ)
abstract int writeQint bQ?BR>readҎq回的要么是个Unicode字符Q?-65535间的一个整敎ͼ要么?1Q已抵达文g末尾Q?BR>无论是readq是writeҎ都会dU程的运行,直到字节被实际读出或写入为止。利用availableҎQ我们可以检查目前能够读取的字节数?BR>
int byteAvailable = System.in.availableQ)Q?BR>if QbyteAvailable ?0Q?
{byte[] data = new byte [byteAvailable]Q?BR> System.in.readQdataQ;
}
FileInputStream ?FileOutputStream 使我们能磁盘文件和输入及输出关联v来?BR>FileInputStream fin = new FileInputStream("employee.dat");
也可?BR>File f = new File("employee.dat");
FileInputStream fin = new FileInputStream(f);
与InputStream and OutputStream cMQ?它也仅支持字节的读写操作,只能从fin对象中读取字节和字节数组Qbyte b = (byte) fin.read();
FileOutputStreamQString nameQ新Z个name指定的文件输出流Q该Ҏ会自动删除同名的M现存文gQ!Q?BR>
文本?BR>
二进制的输入输出速度很快效率很高但是人无法看懂这U格式。java使用的是Unicode字符
File, File(Input/Output)Stream, RandomAccessFile是处理本地文件的c?BR>
Data(Input/Output)Stream是一个过滤流的子c?借此可以d各种基本数据, 在文件和|络中经怋?? readByte, writeBoolean{?
Buffered(Input/Output)Stream的作用是在数据送到目的之前先缓?辑ֈ一定数量时再送到目的,用已减少dơ数.
Piped(Input/Output)Stream适合与一个处理的输出作ؓ另一个处理的输入的情?BR>
Q要想以二进制格式写入数据,使用DataOutputStreamQ要想以文本格式写入数据Q用PrintWriter
二进制读入用DataInputStreamQ可d文本格式的数据Javaq未提供q样的类。唯一用来处理文本输入的是BufferedReadercd包含了一个方法readLine?BR>
]]>
Text Styles
Text Events
text控g支持"plain"textQ这意味着text中的字符必须都是同样的字体和颜色Q如果需?更多的功能就使用org.eclipse.swt.custom.StyledTextQeclipse为用户定制的Q注意StyledText不是本地QnativeQ控?BR>
一共有2U类型的text控gQ单行的和多行的
Single-Line and Multiline Text Controls
SWT.SINGLE
Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
text.setText("Texan");
SWT.MULTI
与单行的text不同它可以含有scroll bar Q通过讄SWT.H_SCROLL or SWT.V_SCROLL Q?BR>
int style =
SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL;
Text text = new Text(parent, style);
String Operations
setText(String string)
getText()
getText(int start, int end) 获取text的文本内容从start到end
getCharCount() q回字符的数?BR>
Passwords and the Echo Character
int style = SWT.SINGLE | SWT.BORDER | SWT.PASSWORD;
Text text = new Text(parent, style);
text.setText("fred54"); //在text上不会显C?fred54"Q而是以echo字符代替
注意在不同的q_上echo字符是不同的Q我们常见的密码echo字符是?”,可以自己讄echo字符
setEchoChar(char echo)如果讄的字W是'\0'则不再隐藏字W,当前的字W被昄
getEchoChar() q回setEchoChar函数讄的echoQ如果未讄则返?\0'Q如果用了SWT.PASSWORD 则返回的字符不确?BR>通常来说自己讄echo字符是不明智的,因ؓq是q_look and feel的一部分?BR>
Lines and Line Height
getLineCount() q回行数
getLineHeight() q回每行高度Q像素)该g字符的高度ƈ不相同,因ؓ行间有空?BR>
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Text text = new Text(shell, SWT.H_SCROLL|SWT.V_SCROLL);
int rows = 5, columns = 10;
GC gc = new GC(text);
FontMetrics fm = gc.getFontMetrics();
gc.dispose();
int height = rows * text.getLineHeight();
int width = columns * fm.getAverageCharWidth();
text.setSize(text.computeSize (width, height));
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Line Delimiters
行定义符?BR>
]]>
Button Styles
SWT.ARROW |
Draw an arrow instead of text or an image button的Ş状显CZؓ头 |
SWT.CHECK |
Create a check button |
SWT.PUSH |
Create a push button |
SWT.RADIO |
Create a radio button |
SWT.TOGGLE |
Create a toggle button |
SWT.FLAT |
Draw the button with a flat look 使button看v来是flat?/P> |
SWT.UP |
Draw an up arrow 头向上Qarrow时才有效Q?/P> |
SWT.DOWN |
Draw a down arrow 头向下Qarrow时有效) |
SWT.LEFT |
Left-align the button (or draw a left arrow)文字向左寚w或箭头向左(arrowӞ |
SWT.RIGHT |
Right-align the button (or draw a right arrow)文字向右寚w或箭头向叻IarrowӞ |
SWT.CENTER |
Center align the button button上的文字中间寚w |
Button Events
SWT.Selection |
The button was selected button被选中事g |
button是活动控Ӟ当用LM们会发送事?BR>
Text and Images
button支持昄文本和图像,它的使用大体上与label相同Q但是它不支持SWT.WARP和换行符Q既button上的文本字符只能是一行,而且它能只能昄文本或图像中的一U不能同旉昄
setText(String string)
getText()
setImage(Image image)
getImage()
管button支持囄昄但是通常不这么用,一般用Tool bars 来代?BR>
Alignment
setAlignment(int alignment) 讄寚w方式 SWT.LEFT, SWT.CENTER, or SWT.RIGHT中的一U?BR>getAlignment() q回寚w方式
通常很少使用q?个函敎ͼ因ؓ默认的对齐一般都很好
Push Buttons
SWT.PUSHQ它们通常用来产生一个动作,与其它类型的button不同push button不会?SWT.Selection 事g中保持选中或未选中状态。它们通常被认为是未选中?BR>Button button = new Button(parent, SWT.PUSH);
button.setText("Ok");
Check Buttons
SWT.CHECK。它与push button不同的是它会保持一个选中的状态,用户使用鼠标或者键盘选择q个状?BR>
你可以用方法设|check button的选中状?BR>setSelection(boolean selection) 讄该button为选中状态check, radio, or toggle button时有?BR>getSelection() q回该button是否被选中
Button button = new Button(parent, SWT.CHECK);
button.setText("Overwrite when typing");
button.setSelection(true);
注意Q调?nbsp;setSelection() 不会产生一个SWT.Selection 事gQSWT的编E新手经怼对这个感到很困惑?BR>
当用LM个checkQ就会触发一个动作事件。你可以讄动作监听?BR>
ActionListener listener =....
bold.addActionListener(listener);
italic.addActionListener(listener);
监听器的actionPerformedҎ查询bold和italic两个check button的状态ƈ且相应地把面板中的字体设为普通、加_、倾斜以及后两U组合?BR>public void actionPerformed(ActionEvent event)
{
int mode = 0;
if (bold.isSelected()) mode +=Font.BOLD;
if (italic.isSelected()) mode += Font.ITALIC;
label.setFont(new Font("Serif", mode, FONTSIZE));
}
Radio Buttons
SWT.RADIO 与check button一样它们会保持一个布状态,但是当多个radio button都是属于一个parentӞ一ơ只能有一个被选中
Button button1 = new Button(parent, SWT.RADIO);
button1.setText("Don't wrap");
button1.setSelection(true);
Button button2 = new Button(parent, SWT.RADIO);
button2.setText("Wrap to window");
Button button3 = new Button(parent, SWT.RADIO);
button3.setText("Wrap to ruler");
Toggle Buttons
SWT.TOGGLE toggle button是当被选中时一直停留在pressed状态下的push button
Arrow Buttons
SWT.ARROW
Button button = new Button(parent, SWT.ARROW);
button.setAlignment(SWT.RIGHT);
arrow button主要用于昄“上一”或“下一”时使用
Button Events
SWT.Selection (SelectionEvent)
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
System.out.println("Ok Pressed");
}
});
Using SWT.Selection with Radio Buttons
SWT.Selection 很少与radio一起用,与check button一P它们通常使用于对话框Q对于绝大多数的操作pȝQ程序不会生一个action直到dialog被关?BR>令h意外的是当用户在一lradio button中选择一个radioӞ2个SWT.Selection 事g被发送:前一个被选中的radio button接收C?SWT.Selection 事g通知它的选中状态改为falseQ新的被选中的radio button接收C?SWT.Selection事g通知它已被选中
Listener listener = new Listener() {
public void handleEvent(Event event) {
Button button = (Button) event.widget;
if (!button.getSelection()) return;
System.out.println(
"Arriving " + button.getText());
}
};
Button land = new Button(shell, SWT.RADIO);
land.setText("By Land");
land.addListener(SWT.Selection, listener);
Button sea = new Button(shell, SWT.RADIO);
sea.setText("By Sea");
sea.addListener(SWT.Selection, listener);
sea.setSelection(true);
SWT.WRAP 自动调整label中的内容行以适应可见区域的大(既label内容自动换行Q?BR>SWT.LEFT label内容左对?BR>SWT.CENTER label内容中间寚w
SWT.RIGHT label内容叛_?BR>SWT.SEPARATOR M个分割符
SWT.HORIZONTAL 使分割符水^Q仅在画分割W时使用Q?BR>SWT.VERTICAL 使分割符垂直Q仅在画分割W时使用Q?BR>SWT.SHADOW_IN 使分割符有“SHADOW_IN ”的效果Q仅在画分割W时使用Q?BR>SWT.SHADOW_OUT 使分割符有“SHADOW_OUT”的效果 Q仅在画分割W时使用Q?/P>
Label Events (none)
label是一个静态组件可用来攄文本Q图像,分隔W,一个静态的控g既不含有焦点QfocusQ也不参与tab traversalQ鼠标点M产生M影响
Label label = new Label(parent, SWT.NONE);
label.setText("User Name:");
Text and Images
label允许你设|文本或囑փ在上面如果你什么都不设|则label昄的是background color
setText(String string) 讄label昄文本内容string
getText() q回label的文本内?BR>setImage(Image image) 讄label昄的图?BR>getImage() q回囑փ
注意Q文本和囑փ只能讄其中的一U,若你惛_label上文本和囑փ都加入,你要使用CLabel
很典型地Q一?/SPAN>FormData实例在一个合成器内被帮定于各个子control。因为对于一个表格布局其核心思想是指明各个?/SPAN>control的相对位|,所以不同于其他的布局Q给予各个子control提供讄?/SPAN>data非常重要。如果一个给定的control没有一?/SPAN>FormData实例来描q它Q则它会被默认ؓ攄于合成器的左上角Q而这U位|是你极期望的。宽度和高度属性用象素来指明一?/SPAN>control的方位。顶部、底部和左右属性较为重要,且都持有一?/SPAN>FormAttachment实例。这?/SPAN>attachment描绘了在一个合成器?/SPAN>control间的关系?BR>注意Q如果多个widgets未指明Q何attachmentQ他们都会在~省值指定的位置重叠h
使用FormAttachment指明关系
理解FormAttachment是用表格布局的一个非帔R要的斚w。就像早先提LQ每一?/SPAN>FormAttachment实例描述了一?/SPAN>control某一面的位置。你可以以两U不同的方式使用FormAttachment?/SPAN>
首先Q你可以使用父合成器的百分比来指明一?/SPAN>FormAttachment。例如,如果一个左侧的FormData被设定ؓ50%Q则control的右辚w会处于合成器的水q中央。同样地Q如果设定顶端边界ؓ75%?/SPAN>control会处于合成器自上而下的四分之三处。表6.3ȝ了用以指定百分比?/SPAN>FormAttachment构造器。以癑ֈ比的形式来指?/SPAN>FormAttachment是有用的Q但你不能L应用q种Ҏ。将你的所?/SPAN>control通用癑ֈ比方式作说明和用l对的象素点来指明他们没有太大的区别Q因为当合成器被重定大小Ӟ如何快速定位每一个元素会变得相当困难Q因?/SPAN>controlq不会如你所愿地在该位置上。用表格式布局的关键点是在于确?/SPAN>control间的怺位置Q而这正是FormAttachement所允许的?BR>
构造器 |
描述 |
FormAttachment(int numerator) |
假定分母?/SPAN>100Q意味着参数卌视ؓ一个百分比?/SPAN> 仅在SWT 3.0中可用?/SPAN> |
FormAttachment(int numerator, int offset) |
假定分母?/SPAN>100Q意味着参数卌视ؓ一个百分比?/SPAN> 偏移?/SPAN>offset是在癑ֈ比定位的基础上再行偏Uȝ象素数目?/SPAN> |
FormAttachment(int numerator, int denominator, int offset) |
假定分母?/SPAN>denominatorQ意味着参数卌视ؓ一个百分比?/SPAN> 偏移?/SPAN>offset是在癑ֈ比定位的基础上再行偏Uȝ象素数目?/SPAN> |
FormAttachmentW二pd的构造器是基于对其他control的参照。它们常常将一?/SPAN>control的边~与盔R?/SPAN>control相对定位。通过?/SPAN>button1讑֮FormData叛_性到一个基?/SPAN>button2而构建的FormAttachmentQ你可以?/SPAN>button1应该L定位?/SPAN>button2的右侧。将你的l大多数control依照q种方式d位有多种好处。你的布局代码目的变得很Ҏ理解Q在q去的象素或是百分壁基础上的那个control与哪?/SPAN>control盔R的表达方式被取代后,变得很明显了,例如Q名?/SPAN>foo?/SPAN>control应该位于工具条之下;其次Q表格式布局也容易维持你的这U布局意图。无论合成器的尺寸如何大变化,它L能够l持其正的相对位置?BR>
FormData formData = new FormData();
formData.top = new FormAttachment(30,70,10);
button1.setLayoutData(formData);
指的是加入该Composite含有70个单元则该button1的顶部位于Composite从上?0个单元再?0个像素的位移
作ؓ指定相对位置之用?/SPAN>FormAttachment构造器有若q种形式Q具体ȝ如下
Q?/SPAN>
构造器 |
描述 |
FormAttachment(Control control) |
现有小部gML?/SPAN>control一侧的参数?/SPAN> |
FormAttachment(Control control, int offset) |
现有小部gML?/SPAN>control一侧的参数Qƈ且有offset数量象素的偏U量?/SPAN> |
FormAttachment(Control control, int offset, int alignment) |
排列alignment必须?/SPAN> SWT.TOP?/SPAN> SWT.BOTTOM?/SPAN>SWT.LEFT?/SPAN> SWT.RIGHT?/SPAN>SWT.CENTER其中之一?/SPAN> 现有小部gML?/SPAN>control一侧的参数Qƈ且有offset数量象素的偏U量?/SPAN> |
FormData formData = new FormData(50,50);
formData.top = new FormAttachment(20,0);
button1.setLayoutData(formData);
FormData formData2 = new FormData();
FormData2.left = new FormAttachment(button1,5);
formData2.top = new FormAttachment(button1,0,SWT.TOP);
button2.setLayoutData(formData2);
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class RowDataExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout());
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("Button 1");
button1.setLayoutData(new RowData(50, 40));
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("Button 2");
button2.setLayoutData(new RowData(50, 30));
Button button3 = new Button(shell, SWT.PUSH);
button3.setText("Button 3");
button3.setLayoutData(new RowData(50, 20));
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}
参考:http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm
Button button0 = new Button (shell, SWT.PUSH);
button0.setText ("button0");
Button button1 = new Button (shell, SWT.PUSH);
button1.setText ("button1");
Button button2 = new Button (shell, SWT.PUSH);
button2.setText ("button2");
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}
}
参考:http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm
Display display = new Display();
Shell shell = new Shell(display);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
shell.setLayout(gridLayout);
new Button(shell, SWT.PUSH).setText("B1");
new Button(shell, SWT.PUSH).setText("Wide Button 2");
new Button(shell, SWT.PUSH).setText("Button 3");
new Button(shell, SWT.PUSH).setText("B4");
new Button(shell, SWT.PUSH).setText("Button 5");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
使每列的宽度相同Q默认gؓfalse
MarginWidth, MarginHeight, HorizontalSpacing, and VerticalSpacing
边宽度Q页辚w度,水^间隔Q垂直间?BR>
GridData
GridData是控制小部g布局的对象,例如
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;//horizontalAlignment是指水^寚w方式
//Q有GEGININGQENDQCENTREQFILLQ?BR> gridData.grabExcessHorizontalSpace = true;
button1.setLayoutData(gridData);
gridData.horizontalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
button5.setLayoutData(gridData);
Style 帔R |
描述 |
FILL_HORIZONTAL |
扩展单元来水q_充满MIZI间?/SPAN> ?/SPAN>HORIZONTAL_ALIGN_FILL |
FILL_VERTICAL |
扩展单元来垂直地充满MIZI间?/SPAN> ?/SPAN>VERTICAL_ALIGN_FILL |
FILL_BOTH |
水^和垂直地扩展单元I间?/SPAN> {h?/SPAN>FILL_HORIZONTAL | FILL_VERTICAL. |
HORIZONTAL_ALIGN_BEGINNING |
居左排列单元内容?/SPAN> |
HORIZONTAL_ALIGN_END |
居右排列单元内容?/SPAN> |
HORIZONTAL_ALIGN_CENTER |
水^居中排列单元内容?/SPAN> |
HORIZONTAL_ALIGN_FILL |
扩展单元I间充满单元内水q空余空间?/SPAN> |
VERTICAL_ALIGN_BEGINNING |
排列单元内容于单元顶部?/SPAN> |
VERTICAL_ALIGN_END |
排列单元内容于单元底部?/SPAN> |
VERTICAL_ALIGN_CENTER |
排列单元内容于垂直中央?/SPAN> |
VERTICAL_ALIGN_FILL |
扩展单元I间充满单元内垂直空余空间?/SPAN> |
Table 6.2 GridData 寸属?/SPAN>
属?/SPAN> |
描述 |
默认?/SPAN> |
widthHint |
列的最宽度?/SPAN>SWT.DEFAULT指明了没有最宽度?/SPAN> |
SWT.DEFAULT |
heightHint |
行的最高度?/SPAN>SWT.DEFAULT指明了没有最高度?/SPAN> |
SWT.DEFAULT |
horizontalIndent |
单元左侧辚w?/SPAN>control之间的象素间隙数量?/SPAN> |
0 |
horizontalSpan |
单元所覆盖的网格的列的数目?/SPAN> |
1 |
verticalSpan |
单元所覆盖的网格的行的数目?/SPAN> |
1 |
http://sourceforge.net/
public class BounceBall {
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Canvas canvas = null;
private Button startButton = null;
ballThread bt = null;
Display display = null;
public BounceBall() {
super();
// TODO Auto-generated constructor stub
// bt = new ballThread(canvas);
display = Display.getDefault();
}
/**
* This method initializes canvas
*
*/
private void createCanvas() {
canvas = new Canvas(sShell, SWT.NONE);
canvas.setBackground(new Color(Display.getCurrent(), 0, 0, 255));
canvas.setBounds(new org.eclipse.swt.graphics.Rectangle(26,14,527,242));
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)
* for the correct SWT library path in order to run with the SWT dlls.
* The dlls are located in the SWT plugin jar.
* For example, on Windows the Eclipse SWT 3.1 plugin jar is:
* installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar
*/
// Display display = Display.getDefault();
BounceBall thisClass = new BounceBall();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!thisClass.display.readAndDispatch())
thisClass.display.sleep();
}
thisClass.display.dispose();
}
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
createCanvas();
sShell.setSize(new org.eclipse.swt.graphics.Point(588,367));
startButton = new Button(sShell, SWT.NONE);
startButton.setBounds(new org.eclipse.swt.graphics.Rectangle(87,284,76,33));
startButton.setText("Start");
startButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
//System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()
new ballThread(40,40,canvas).start();
}
});
}
}
class ballThread extends Thread {
int x, y, xsize, ysize, addx, addy;
Rectangle rc = null;
GC gc = null;
Canvas c = null;
Color red = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
public ballThread(int x,int y,Canvas ca) {
c = ca;
this.x = x;
this.y = y;
xsize = 10;
ysize = 10;
addx = 1;
addy = 2;
rc = c.getBounds();
}
public void draw(int x, int y, int xsize, int ysize) {
gc = new GC(c);
gc.drawOval(x, y, xsize, ysize);
gc.setBackground(red);
gc.fillOval(x, y, xsize, ysize);
gc.dispose();
}
public void clean() {
gc = new GC(c);
// Rectangle rt = canvas.getBounds();
gc.drawRectangle(rc.x - 100, rc.y - 100, rc.width + 100,
rc.height + 100);
gc.fillRectangle(rc.x - 100, rc.y - 100, rc.width + 100,
rc.height + 100);
gc.dispose();
}
public void run() {
for (int i = 1; i < 1500; i++) {
try{
Display.getDefault().asyncExec(new Thread () {
public void run(){
draw(x, y, xsize, ysize);}});
Thread.sleep(10);
Display.getDefault().asyncExec(new Thread () {
public void run(){
clean();}});
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (rc.contains(x, y)) {
x += addx;
y += addy;
} else {
if (x >= rc.width || x <= 26) {
addx = -addx;
x += addx;
y += addy;
} else if (y >= rc.height || y <= 14) {
addy = -addy;
x += addx;
y += addy;
}
}
}
}
}
惛_一个办法能够去除那些exceptionsQ就是在display.dispose()前加一句Thread.currentThread().stop();强制l止U程Q不q这个办法肯定是最垃圾的办?......