前不久写的 代码比较简单没有遵循java编程规律 敬请原谅!!!
这个是两个GUI 下面那个是处理类
package com.lusm;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
public class StortGUI {
/** *//**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell(SWT.CLOSE);
shell.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
shell.setImage(SWTResourceManager.getImage(StortGUI.class, "/com/sun/java/swing/plaf/windows/icons/JavaCup32.png"));
shell.setSize(401, 363);
shell.setText("Java实现排序算法");
//
shell.open();
final Text a = new Text(shell, SWT.BORDER);
a.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
a.setBackground(SWTResourceManager.getColor(243, 241, 211));
a.setBounds(5, 29, 50, 19);
final Text b = new Text(shell, SWT.BORDER);
b.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
b.setBackground(SWTResourceManager.getColor(243, 241, 211));
b.setBounds(61, 29, 50, 19);
final Text c = new Text(shell, SWT.BORDER);
c.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
c.setBackground(SWTResourceManager.getColor(243, 241, 211));
c.setBounds(117, 29, 50, 19);
final Text d = new Text(shell, SWT.BORDER);
d.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
d.setBackground(SWTResourceManager.getColor(243, 241, 211));
d.setBounds(173, 29, 50, 19);
final Text ee = new Text(shell, SWT.BORDER);
ee.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
ee.setBackground(SWTResourceManager.getColor(243, 241, 211));
ee.setBounds(229, 29, 50, 19);
final Text f = new Text(shell, SWT.BORDER);
f.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
f.setBackground(SWTResourceManager.getColor(243, 241, 211));
f.setBounds(285, 29, 50, 19);
final Text i = new Text(shell, SWT.BORDER);
i.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
i.setBackground(SWTResourceManager.getColor(243, 241, 211));
i.setBounds(341, 29, 50, 19);
final Text rs = new Text(shell, SWT.BORDER|SWT.V_SCROLL|SWT.H_SCROLL);
rs.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/bjs6.jpg"));
rs.setForeground(SWTResourceManager.getColor(0, 128, 0));
rs.setFont(SWTResourceManager.getFont("", 10, SWT.BOLD));
rs.setEditable(false);
rs.setBackground(SWTResourceManager.getColor(253, 247, 240));
rs.setBounds(5, 104, 386, 222);
final Combo combo = new Combo(shell, SWT.NONE);
combo.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
combo.setBackground(SWTResourceManager.getColor(243, 241, 211));
combo.setForeground(SWTResourceManager.getColor(128, 128, 255));
combo.setItems(new String[] {" ---冒泡法---", " ---选择排序---", " ---插入排序---"});
combo.setText(" ---常用算法---");
combo.setBounds(61, 60, 120, 19);
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
label_1.setForeground(SWTResourceManager.getColor(128, 128, 255));
label_1.setText("排序法:");
label_1.setBounds(5, 63, 50, 13);
final Button done = new Button(shell, SWT.NONE);
done.setForeground(SWTResourceManager.getColor(128, 0, 0));
done.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
done.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
rs.setText("");
String[] str={a.getText(),b.getText(),c.getText(),d.getText(),ee.getText(),f.getText(),i.getText(),};
StortDo sortdo=new StortDo();
sortdo.getstr(str);
if(!sortdo.check()){
MessageBox mess=new MessageBox(shell,SWT.None);
mess.setMessage("您输入的有问题!请在每个空格填上合理的值再点运算,谢谢合作!");
mess.open();
}else{
//实现数据转换
sortdo.StrToDou();
//System.out.println("选择的算法是:"+combo.getText());
if(combo.getText().equals(" ---冒泡法---")){
//实现冒泡法
sortdo.Stort1();
//将内容反映到GUI界面
double[][] dou=sortdo.getstort();
rs.setText(
"您的输入: "+String.valueOf(dou[0][1])+" "+String.valueOf(dou[1][1])+" "+String.valueOf(dou[2][1])+" "+String.valueOf(dou[3][1])+" "+String.valueOf(dou[4][1])+" "+String.valueOf(dou[5][1])+" "+String.valueOf(dou[6][1])+"\n\n"
+"第1行是: "+String.valueOf(dou[0][2])+" "+String.valueOf(dou[1][2])+" "+String.valueOf(dou[2][2])+" "+String.valueOf(dou[3][2])+" "+String.valueOf(dou[4][2])+" "+String.valueOf(dou[5][2])+" "+String.valueOf(dou[6][2])+"\n\n"
+"第2行是: "+String.valueOf(dou[0][3])+" "+String.valueOf(dou[1][3])+" "+String.valueOf(dou[2][3])+" "+String.valueOf(dou[3][3])+" "+String.valueOf(dou[4][3])+" "+String.valueOf(dou[5][3])+" "+String.valueOf(dou[6][3])+"\n\n"
+"第3行是: "+String.valueOf(dou[0][4])+" "+String.valueOf(dou[1][4])+" "+String.valueOf(dou[2][4])+" "+String.valueOf(dou[3][4])+" "+String.valueOf(dou[4][4])+" "+String.valueOf(dou[5][4])+" "+String.valueOf(dou[6][4])+"\n\n"
+"第4行是: "+String.valueOf(dou[0][5])+" "+String.valueOf(dou[1][5])+" "+String.valueOf(dou[2][5])+" "+String.valueOf(dou[3][5])+" "+String.valueOf(dou[4][5])+" "+String.valueOf(dou[5][5])+" "+String.valueOf(dou[6][5])+"\n\n"
+"结果是: "+String.valueOf(dou[0][6])+" "+String.valueOf(dou[1][6])+" "+String.valueOf(dou[2][6])+" "+String.valueOf(dou[3][6])+" "+String.valueOf(dou[4][6])+" "+String.valueOf(dou[5][6])+" "+String.valueOf(dou[6][6])+"\n\n"
);
}else if(combo.getText().equals(" ---选择排序---")){
//实现选择排序
sortdo.Srort2();
double[][] dou=sortdo.getstort();
rs.setText(
"您输入的是: "+a.getText()+" "+b.getText()+" "+c.getText()+" "+d.getText()+" "+ee.getText()+" "+f.getText()+" "+i.getText()+"\n\n"
+"第1行是: "+String.valueOf(dou[0][0])+" "+String.valueOf(dou[1][0])+" "+String.valueOf(dou[2][0])+" "+String.valueOf(dou[3][0])+" "+String.valueOf(dou[4][0])+" "+String.valueOf(dou[5][0])+" "+String.valueOf(dou[6][0])+"\n\n"
+"第2行是: "+String.valueOf(dou[0][1])+" "+String.valueOf(dou[1][1])+" "+String.valueOf(dou[2][1])+" "+String.valueOf(dou[3][1])+" "+String.valueOf(dou[4][1])+" "+String.valueOf(dou[5][1])+" "+String.valueOf(dou[6][1])+"\n\n"
+"第3行是: "+String.valueOf(dou[0][2])+" "+String.valueOf(dou[1][2])+" "+String.valueOf(dou[2][2])+" "+String.valueOf(dou[3][2])+" "+String.valueOf(dou[4][2])+" "+String.valueOf(dou[5][2])+" "+String.valueOf(dou[6][2])+"\n\n"
+"第4行是: "+String.valueOf(dou[0][3])+" "+String.valueOf(dou[1][3])+" "+String.valueOf(dou[2][3])+" "+String.valueOf(dou[3][3])+" "+String.valueOf(dou[4][3])+" "+String.valueOf(dou[5][3])+" "+String.valueOf(dou[6][3])+"\n\n"
+"第5行是: "+String.valueOf(dou[0][4])+" "+String.valueOf(dou[1][4])+" "+String.valueOf(dou[2][4])+" "+String.valueOf(dou[3][4])+" "+String.valueOf(dou[4][4])+" "+String.valueOf(dou[5][4])+" "+String.valueOf(dou[6][4])+"\n\n"
+"结果是: "+String.valueOf(dou[0][5])+" "+String.valueOf(dou[1][5])+" "+String.valueOf(dou[2][5])+" "+String.valueOf(dou[3][5])+" "+String.valueOf(dou[4][5])+" "+String.valueOf(dou[5][5])+" "+String.valueOf(dou[6][5])+"\n\n"
);
}else if(combo.getText().equals(" ---插入排序---")){
//实现插入排序
sortdo.Srort3();
double[][] dou=sortdo.getstort();
rs.setText(
"您输入的是: "+a.getText()+" "+b.getText()+" "+c.getText()+" "+d.getText()+" "+ee.getText()+" "+f.getText()+" "+i.getText()+"\n\n"
+"第1行是: "+String.valueOf(dou[0][1])+" "+String.valueOf(dou[1][1])+" "+String.valueOf(dou[2][1])+" "+String.valueOf(dou[3][1])+" "+String.valueOf(dou[4][1])+" "+String.valueOf(dou[5][1])+" "+String.valueOf(dou[6][1])+"\n\n"
+"第2行是: "+String.valueOf(dou[0][2])+" "+String.valueOf(dou[1][2])+" "+String.valueOf(dou[2][2])+" "+String.valueOf(dou[3][2])+" "+String.valueOf(dou[4][2])+" "+String.valueOf(dou[5][2])+" "+String.valueOf(dou[6][2])+"\n\n"
+"第3行是: "+String.valueOf(dou[0][3])+" "+String.valueOf(dou[1][3])+" "+String.valueOf(dou[2][3])+" "+String.valueOf(dou[3][3])+" "+String.valueOf(dou[4][3])+" "+String.valueOf(dou[5][3])+" "+String.valueOf(dou[6][3])+"\n\n"
+"第4行是: "+String.valueOf(dou[0][4])+" "+String.valueOf(dou[1][4])+" "+String.valueOf(dou[2][4])+" "+String.valueOf(dou[3][4])+" "+String.valueOf(dou[4][4])+" "+String.valueOf(dou[5][4])+" "+String.valueOf(dou[6][4])+"\n\n"
+"第5行是: "+String.valueOf(dou[0][5])+" "+String.valueOf(dou[1][5])+" "+String.valueOf(dou[2][5])+" "+String.valueOf(dou[3][5])+" "+String.valueOf(dou[4][5])+" "+String.valueOf(dou[5][5])+" "+String.valueOf(dou[6][5])+"\n\n"
);
}else{
MessageBox mess=new MessageBox(shell,SWT.None);
mess.setMessage("请您选择的一种算法,谢谢合作!");
mess.open();
}
}
}
});
done.setImage(SWTResourceManager.getImage(StortGUI.class, "/javax/swing/plaf/metal/icons/ocean/computer.gif"));
done.setText("运算");
done.setBounds(199, 56, 60, 26);
final Button clear = new Button(shell, SWT.NONE);
clear.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
clear.setImage(SWTResourceManager.getImage(StortGUI.class, "/javax/swing/plaf/metal/icons/ocean/file.gif"));
clear.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
a.setText("");b.setText("");c.setText("");d.setText("");
ee.setText("");f.setText("");i.setText("");combo.setText(" ---常用算法---");
rs.setText("");
}
});
clear.setBounds(265, 56, 60, 26);
clear.setText("清除");
final Button quit = new Button(shell, SWT.NONE);
quit.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
quit.setImage(SWTResourceManager.getImage(StortGUI.class, "/javax/swing/plaf/metal/icons/ocean/close-pressed.gif"));
quit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
quit.setBounds(331, 56, 60, 26);
quit.setText("退出");
final Label label = new Label(shell, SWT.NONE);
label.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
label.setForeground(SWTResourceManager.getColor(128, 128, 255));
label.setText("输入一组数据,选择您要使用的排序方法,点击运算。");
label.setBounds(5, 10, 296, 13);
final Label label_2 = new Label(shell, SWT.NONE);
label_2.setBackgroundImage(SWTResourceManager.getImage(StortGUI.class, "/图片/pic020.jpg"));
label_2.setForeground(SWTResourceManager.getColor(128, 128, 255));
label_2.setText("下面显示整个过程:");
label_2.setBounds(5, 85, 106, 13);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
package com.swtdesigner;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
/** *//**
* Utility class for managing OS resources associated with SWT controls such as
* colors, fonts, images, etc.
*
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code>
* method to release the operating system resources managed by cached objects
* when those objects and OS resources are no longer needed (e.g. on
* application shutdown)
*
* This class may be freely distributed as part of any application or plugin.
* <p>
* Copyright (c) 2003 - 2005, Instantiations, Inc. <br>All Rights Reserved
*
* @author scheglov_ke
* @author Dan Rubel
*/
public class SWTResourceManager {
/** *//**
* Dispose of cached objects and their underlying OS resources. This should
* only be called when the cached objects are no longer needed (e.g. on
* application shutdown)
*/
public static void dispose() {
disposeColors();
disposeFonts();
disposeImages();
disposeCursors();
}
//////////////////////////////
// Color support
//////////////////////////////
/** *//**
* Maps RGB values to colors
*/
private static HashMap m_ColorMap = new HashMap();
/** *//**
* Returns the system color matching the specific ID
* @param systemColorID int The ID value for the color
* @return Color The system color matching the specific ID
*/
public static Color getColor(int systemColorID) {
Display display = Display.getCurrent();
return display.getSystemColor(systemColorID);
}
/** *//**
* Returns a color given its red, green and blue component values
* @param r int The red component of the color
* @param g int The green component of the color
* @param b int The blue component of the color
* @return Color The color matching the given red, green and blue componet values
*/
public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b));
}
/** *//**
* Returns a color given its RGB value
* @param rgb RGB The RGB value of the color
* @return Color The color matching the RGB value
*/
public static Color getColor(RGB rgb) {
Color color = (Color) m_ColorMap.get(rgb);
if (color == null) {
Display display = Display.getCurrent();
color = new Color(display, rgb);
m_ColorMap.put(rgb, color);
}
return color;
}
/** *//**
* Dispose of all the cached colors
*/
public static void disposeColors() {
for (Iterator iter = m_ColorMap.values().iterator(); iter.hasNext();)
((Color) iter.next()).dispose();
m_ColorMap.clear();
}
//////////////////////////////
// Image support
//////////////////////////////
/** *//**
* Maps image names to images
*/
private static HashMap m_ClassImageMap = new HashMap();
/** *//**
* Maps images to image decorators
*/
private static HashMap m_ImageToDecoratorMap = new HashMap();
/** *//**
* Returns an image encoded by the specified input stream
* @param is InputStream The input stream encoding the image data
* @return Image The image encoded by the specified input stream
*/
protected static Image getImage(InputStream is) {
Display display = Display.getCurrent();
ImageData data = new ImageData(is);
if (data.transparentPixel > 0)
return new Image(display, data, data.getTransparencyMask());
return new Image(display, data);
}
/** *//**
* Returns an image stored in the file at the specified path
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(String path) {
return getImage("default", path); //$NON-NLS-1$
}
/** *//**
* Returns an image stored in the file at the specified path
* @param section The section to which belongs specified image
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(String section, String path) {
String key = section + '|' + SWTResourceManager.class.getName() + '|' + path;
Image image = (Image) m_ClassImageMap.get(key);
if (image == null) {
try {
FileInputStream fis = new FileInputStream(path);
image = getImage(fis);
m_ClassImageMap.put(key, image);
fis.close();
} catch (Exception e) {
image = getMissingImage();
m_ClassImageMap.put(key, image);
}
}
return image;
}
/** *//**
* Returns an image stored in the file at the specified path relative to the specified class
* @param clazz Class The class relative to which to find the image
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(Class clazz, String path) {
String key = clazz.getName() + '|' + path;
Image image = (Image) m_ClassImageMap.get(key);
if (image == null) {
try {
if (path.length() > 0 && path.charAt(0) == '/') {
String newPath = path.substring(1, path.length());
image = getImage(new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(newPath)));
} else {
image = getImage(clazz.getResourceAsStream(path));
}
m_ClassImageMap.put(key, image);
} catch (Exception e) {
image = getMissingImage();
m_ClassImageMap.put(key, image);
}
}
return image;
}
private static final int MISSING_IMAGE_SIZE = 10;
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
//
GC gc = new GC(image);
gc.setBackground(getColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
gc.dispose();
//
return image;
}
/** *//**
* Style constant for placing decorator image in top left corner of base image.
*/
public static final int TOP_LEFT = 1;
/** *//**
* Style constant for placing decorator image in top right corner of base image.
*/
public static final int TOP_RIGHT = 2;
/** *//**
* Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/** *//**
* Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/** *//**
* Returns an image composed of a base image decorated by another image
* @param baseImage Image The base image that should be decorated
* @param decorator Image The image to decorate the base image
* @return Image The resulting decorated image
*/
public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
}
/** *//**
* Returns an image composed of a base image decorated by another image
* @param baseImage Image The base image that should be decorated
* @param decorator Image The image to decorate the base image
* @param corner The corner to place decorator image
* @return Image The resulting decorated image
*/
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
HashMap decoratedMap = (HashMap) m_ImageToDecoratorMap.get(baseImage);
if (decoratedMap == null) {
decoratedMap = new HashMap();
m_ImageToDecoratorMap.put(baseImage, decoratedMap);
}
Image result = (Image) decoratedMap.get(decorator);
if (result == null) {
final Rectangle bid = baseImage.getBounds();
final Rectangle did = decorator.getBounds();
final Point baseImageSize = new Point(bid.width, bid.height);
CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
protected void drawCompositeImage(int width, int height) {
drawImage(baseImage.getImageData(), 0, 0);
if (corner == TOP_LEFT) {
drawImage(decorator.getImageData(), 0, 0);
} else if (corner == TOP_RIGHT) {
drawImage(decorator.getImageData(), bid.width - did.width - 1, 0);
} else if (corner == BOTTOM_LEFT) {
drawImage(decorator.getImageData(), 0, bid.height - did.height - 1);
} else if (corner == BOTTOM_RIGHT) {
drawImage(decorator.getImageData(), bid.width - did.width - 1, bid.height - did.height - 1);
}
}
protected Point getSize() {
return baseImageSize;
}
};
result = compositImageDesc.createImage();
decoratedMap.put(decorator, result);
}
return result;
}
/** *//**
* Dispose all of the cached images
*/
public static void disposeImages() {
for (Iterator I = m_ClassImageMap.values().iterator(); I.hasNext();)
((Image) I.next()).dispose();
m_ClassImageMap.clear();
//
for (Iterator I = m_ImageToDecoratorMap.values().iterator(); I.hasNext();) {
HashMap decoratedMap = (HashMap) I.next();
for (Iterator J = decoratedMap.values().iterator(); J.hasNext();) {
Image image = (Image) J.next();
image.dispose();
}
}
}
/** *//**
* Dispose cached images in specified section
* @param section the section do dispose
*/
public static void disposeImages(String section) {
for (Iterator I = m_ClassImageMap.keySet().iterator(); I.hasNext();) {
String key = (String) I.next();
if (!key.startsWith(section + '|'))
continue;
Image image = (Image) m_ClassImageMap.get(key);
image.dispose();
I.remove();
}
}
//////////////////////////////
// Font support
//////////////////////////////
/** *//**
* Maps font names to fonts
*/
private static HashMap m_FontMap = new HashMap();
/** *//**
* Maps fonts to their bold versions
*/
private static HashMap m_FontToBoldFontMap = new HashMap();
/** *//**
* Returns a font based on its name, height and style
* @param name String The name of the font
* @param height int The height of the font
* @param style int The style of the font
* @return Font The font matching the name, height and style
*/
public static Font getFont(String name, int height, int style) {
return getFont(name, height, style, false, false);
}
/** *//**
* Returns a font based on its name, height and style.
* Windows-specific strikeout and underline flags are also supported.
* @param name String The name of the font
* @param size int The size of the font
* @param style int The style of the font
* @param strikeout boolean The strikeout flag (warning: Windows only)
* @param underline boolean The underline flag (warning: Windows only)
* @return Font The font matching the name, height, style, strikeout and underline
*/
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
Font font = (Font) m_FontMap.get(fontName);
if (font == null) {
FontData fontData = new FontData(name, size, style);
if (strikeout || underline) {
try {
Class logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
if (logFont != null && logFontClass != null) {
if (strikeout) {
logFontClass.getField("lfStrikeOut").set(logFont, new Byte((byte) 1)); //$NON-NLS-1$
}
if (underline) {
logFontClass.getField("lfUnderline").set(logFont, new Byte((byte) 1)); //$NON-NLS-1$
}
}
} catch (Throwable e) {
System.err.println(
"Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
font = new Font(Display.getCurrent(), fontData);
m_FontMap.put(fontName, font);
}
return font;
}
/** *//**
* Return a bold version of the give font
* @param baseFont Font The font for whoch a bold version is desired
* @return Font The bold version of the give font
*/
public static Font getBoldFont(Font baseFont) {
Font font = (Font) m_FontToBoldFontMap.get(baseFont);
if (font == null) {
FontData fontDatas[] = baseFont.getFontData();
FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_FontToBoldFontMap.put(baseFont, font);
}
return font;
}
/** *//**
* Dispose all of the cached fonts
*/
public static void disposeFonts() {
for (Iterator iter = m_FontMap.values().iterator(); iter.hasNext();)
((Font) iter.next()).dispose();
m_FontMap.clear();
}
//////////////////////////////
// CoolBar support
//////////////////////////////
/** *//**
* Fix the layout of the specified CoolBar
* @param bar CoolBar The CoolBar that shgoud be fixed
*/
public static void fixCoolBarSize(CoolBar bar) {
CoolItem[] items = bar.getItems();
// ensure that each item has control (at least empty one)
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
if (item.getControl() == null)
item.setControl(new Canvas(bar, SWT.NONE) {
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(20, 20);
}
});
}
// compute size for each item
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
Control control = item.getControl();
control.pack();
Point size = control.getSize();
item.setSize(item.computeSize(size.x, size.y));
}
}
//////////////////////////////
// Cursor support
//////////////////////////////
/** *//**
* Maps IDs to cursors
*/
private static HashMap m_IdToCursorMap = new HashMap();
/** *//**
* Returns the system cursor matching the specific ID
* @param id int The ID value for the cursor
* @return Cursor The system cursor matching the specific ID
*/
public static Cursor getCursor(int id) {
Integer key = new Integer(id);
Cursor cursor = (Cursor) m_IdToCursorMap.get(key);
if (cursor == null) {
cursor = new Cursor(Display.getDefault(), id);
m_IdToCursorMap.put(key, cursor);
}
return cursor;
}
/** *//**
* Dispose all of the cached cursors
*/
public static void disposeCursors() {
for (Iterator iter = m_IdToCursorMap.values().iterator(); iter.hasNext();)
((Cursor) iter.next()).dispose();
m_IdToCursorMap.clear();
}
}
实现后台类
package com.lusm;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StortDo extends StortGUI {
double[] sortdata =new double[7];
String[] str=new String[7];
boolean bool=true;
double[][] stri=new double[7][7];
//double[][] tmp=new double[7][7];
//选择排序算法变量
double temp=0.0;
int index=0;
//获取数据
public void getstr(String[] str){
this.str=str;
}
//数据验证
public boolean check(){
for(int i=0;i<7;i++){
if(str[i].equals("")){
bool=false;
break;
}else{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str[i]);
if(isNum.matches())
{
bool=true;
}else{
bool=false;
}
}
}
return bool;
}
//数据转换
public void StrToDou(){
try{
for(int i=0;i<7;i++){
sortdata[i]=Double.valueOf(str[i]).doubleValue();
//System.out.print(sortdata[i]+" ");
}}catch(Exception e){
System.out.println(e.getStackTrace());
}
// System.out.println();
}
//实现冒泡法
public void Stort1(){
double change;
//转换变量的值
for(int i=0;i<6;i++){
for(int j=i+1;j<7;j++){
if(sortdata[i]>sortdata[j]){
change=sortdata[i];
sortdata[i]=sortdata[j];
sortdata[j]=change;
for(int k=0;k<7;k++){
stri[k][j]=sortdata[k];
}
}
}
}
}
//获取冒泡法数据集
public double[][] getstort(){
return stri;
}
//选择排序实现
public void Srort2(){
for (int i = 0 ;i < 6 ;i++ ) {
index=i;
temp=sortdata[i];
for (int j = i + 1 ;j < 7 ;j++ ){
if(temp>sortdata[j]){
temp = sortdata[j];
index = j;
}
}
//将最小的元素交换到前面
temp = sortdata[i];
sortdata[i] = sortdata[index];
sortdata[index] = temp;
for(int k=0;k<7;k++){
stri[k][i]=sortdata[k];
}
}
}
//插入排序实现
/**//*
* 此处代码有bug请保留已经屏蔽的测试代码
* */
public void Srort3(){
int index = 1;
while (index < 7)
{
insert(sortdata, index++, sortdata[index-1]);
}
/**//*
for(int i=0;i<6;i++){
for(int j=0;j<7;j++){
//System.out.print("str"+i+" "+j+" ");
System.out.print(" str"+i+" "+j+" "+stri[j][i]);
}
System.out.println();
}*/
}
private void insert(double[] sort, int size, double s)
{
for (int i = 0 ;i < size ;i++ )
{
if (s<sort[i])
{
//如果待插入的元素小于当前元素,则把当前元素后面的元素依次后移一位
for (int j = size ;j > i ;j-- )
{
sort[j] = sort[j-1];
}
sort[i] = s;
for(int ii=0;ii<7;ii++){
//System.out.print(sortdata[ii]+" ");
stri[ii][size-1]=sortdata[ii];
//System.out.print(tmp[0][ii]+" ");
}
break;
}
}
}
}
请在eclipse+swt designer环境中配置运行 呵呵 具体工具前面的文章里有 找找
地震让大伙知道:居安思危,才是生存之道。
posted on 2007-08-07 14:56
小寻 阅读(642)
评论(0) 编辑 收藏 所属分类:
j2se/j2ee/j2me