当前位置: 代码迷 >> Eclipse >> SWT 日历的有关问题
  详细解决方案

SWT 日历的有关问题

热度:351   发布时间:2016-04-23 18:54:00.0
SWT 日历的问题
麻烦高手帮我诊断下这个代码,我的目的是从另外一个SWT界面的下拉框调用这个日历程序,返回选择的日期显示到combo里,但是这个代码有问题,麻烦一下了.还有一定要是能返回值的,谢谢!!!

------解决方案--------------------
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseEvent;

public class Scalendar extends Dialog implements MouseListener{

public Scalendar(Shell shell) {
super(shell);
// TODO 自动生成构造函数存根
}

protected static Shell shell;
private Display display = null;

private Date nowDate = null;

private String selectedDate = null;

private GridLayout gridLayout = null;
private GridData gridData = null;

private CLabel sunday = null;
private CLabel monday = null;
private CLabel tuesday = null;
private CLabel wednesday = null;
private CLabel thursday = null;
private CLabel friday = null;
private CLabel saturday = null;

private Button yearUp = null;
private Button yearNext = null;
private Button monthUp = null;
private Button monthNext = null;

private CLabel nowLabel = null;
private CLabel[] days = new CLabel[42];

/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
Scalendar window = new Scalendar(shell);
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

/**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setSize(230, 220);
shell.setText( "选择日期 ");
shell = new Shell();
shell.setSize(230, 220);
shell.setText( "选择日期 ");

gridLayout = new GridLayout();
gridLayout.numColumns = 7;
shell.setLayout(gridLayout);

gridData = new GridData(GridData.FILL_HORIZONTAL);
yearUp = new Button(shell, SWT.PUSH | SWT.FLAT);
yearUp.setText( " < ");
yearUp.setLayoutData(gridData);
yearUp.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
previousYear();
}
});

gridData = new GridData(GridData.FILL_HORIZONTAL);
monthUp = new Button(shell, SWT.PUSH | SWT.FLAT);
monthUp.setText( " < < ");
monthUp.setLayoutData(gridData);
monthUp.addSelectionListener(new SelectionAdapter() {
  相关解决方案