import java.util.Date;
lipse.swt.SWT;
lipse.swt.widgets.ColorDialog;
lipse.swt.widgets.Display;
lipse.swt.widgets.Event;
lipse.swt.widgets.FontDialog;
lipse.swt.widgets.Listener;
lipse.swt.widgets.Shell;
lipse.swt.widgets.ToolBar;
lipse.swt.widgets.ToolItem;
lipse.swt.custom.StyledText;
lipse.swt.events.SelectionAdapter;
lipse.swt.events.SelectionEvent;
aphics.Color;
aphics.Font;
aphics.FontData;
aphics.RGB;
import com.SimpleDateFormat;
import com.swtdesigner.SWTResourceManager;
lipse.swt.widgets.Button;
public class Notepad extends Shell {
/**
* Launch the application.
* @param args
*/
public static void main(String args[]) {
try {
Display display = Default();
Notepad shell = new Notepad(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!adAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
* @param display
*/
public Notepad(Display display) {
super(display, SWT.CLOSE | SWT.MIN | SWT.TITLE);
Image(Notepad.class, "/icons/progress/ani/3.png"));
ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
toolBar.setBounds(10, 157, 251, 32);
final ToolItem bgColorButton = new ToolItem(toolBar, SWT.NONE);
bgColorButton.setWidth(50);
bgColorButton.setText(" bgColor ");
final ToolItem forColorButton = new ToolItem(toolBar, SWT.NONE);
forColorButton.setText(" forColor ");
final ToolItem fontButton = new ToolItem(toolBar, SWT.NONE);
fontButton.setWidth(50);
fontButton.setText(" font ");
final StyledText styledText = new StyledText(this, SWT.BORDER|SWT.WRAP|SWT.V_SCROLL);
styledText.setBounds(10, 195, 251, 98);
final StyledText styledText_1 = new StyledText(this, SWT.BORDER | SWT.WRAP|SWT.V_SCROLL);
styledText_1.setEditable(false);
styledText_1.setBounds(10, 10, 251, 141);
SelectionAdapter listener_1=new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Button b=(Button)e.widget;
Text().equals("确定"))
{
SimpleDateFormat dateFormat=new SimpleDateFormat(" MM-dd hh:mm:ss");
String date=dateFormat.format(new Date());
String Text();
styledText_1.append("花蝴蝶"+date+":\n"+c+"\n");
代码编辑器怎么下载 styledText.setText("");
}
else Text().equals("清空"))
{
styledText.setText("");
}
}
};
Button button = new Button(this, SWT.NONE);
button.setBounds(10, 297, 79, 27);
button.setText("\u786E\u5B9A");
button.addSelectionListener(listener_1);
Button button_1 = new Button(this, SWT.NONE);
button_1.setBounds(181, 297, 80, 27);
button_1.setText("\u6E05\u7A7A");
button_1.addSelectionListener(listener_1);
createContents();
final Shell shell=new Shell(display);
Listener listener=new Listener(){
public void handleEvent(Event event){
if(event.widget==bgColorButton){
ColorDialog dialog=new ColorDialog(shell);
RGB rgb=dialog.open();
if(rgb!=null){
Color color=new Display(),rgb);
styledText.setForeground(color);
styledText_1.setForeground(color);
}
}
else if(event.widget==forColorButton){
ColorDialog dialog=new ColorDialog(shell);
RGB rgb=dialog.open();
if(rgb!=null){
Color color=new Display(),rgb);
styledText.setForeground(color);
styledText_1.setForeground(color);
}
}
else if(event.widget==fontButton){
FontDialog dialog=new FontDialog(shell);
FontData fontData=dialog.open();
if(fontData!=null){
Font font=new Display(),fontData);
styledText.setFont(font);
styledText_1.setFont(font);
}
}
}
};
bgColorButton.addListener(SWT.Selection,listener);
forColorButton.addListener(SWT.Selection,listener);
fontButton.addListener(SWT.Selection,listener);
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("Notepad");
setSize(277, 364);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论