⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 besttimedialog.java

📁 模仿windows的扫雷游戏 SWT编写的 需要log4j 1.2.4
💻 JAVA
字号:
package cn.pandaoen.game.minesweeper;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import cn.pandaoen.game.minesweeper.res.Resources;

/**
 * @author pan
 */
public class BestTimeDialog extends Dialog {

	public BestTimeDialog(Shell parent) {
		super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		setText(Resources.res.getString("BestTimeDialog")); //$NON-NLS-1$
	}

	public void open() {
		// Create the dialog window
		Shell shell = new Shell(getParent(), getStyle());
		shell.setText(getText());

		createContents(shell);

		shell.setImage(Resources.res.getImage("app.gif")); //$NON-NLS-1$
		shell.pack();
		shell.open();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Creates the dialog's contents
	 * 
	 * @param shell the dialog window
	 */
	private void createContents(final Shell shell) {
		BestTime bestTime = BestTime.loadBestTime();

		GridLayout gridLayout = new GridLayout(3, true);
		gridLayout.horizontalSpacing = 10;
		gridLayout.verticalSpacing = 5;
		gridLayout.marginLeft = 15;
		gridLayout.marginTop = 15;
		shell.setLayout(gridLayout);

		final Label[] labels = new Label[6];

		Label label = new Label(shell, SWT.NONE);
		label.setText(Resources.res.getString("BestTimeDialog.Beginner")); //$NON-NLS-1$
		labels[0] = new Label(shell, SWT.NONE);
		labels[1] = new Label(shell, SWT.NONE);

		label = new Label(shell, SWT.NONE);
		label.setText(Resources.res.getString("BestTimeDialog.Intermediate")); //$NON-NLS-1$
		labels[2] = new Label(shell, SWT.NONE);
		labels[3] = new Label(shell, SWT.NONE);

		label = new Label(shell, SWT.NONE);
		label.setText(Resources.res.getString("BestTimeDialog.Expert")); //$NON-NLS-1$
		labels[4] = new Label(shell, SWT.NONE);
		labels[5] = new Label(shell, SWT.NONE);

		setLabels(bestTime, labels);
		
		Composite composite = new Composite(shell, SWT.NONE);
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 3;
		composite.setLayoutData(gridData);

		RowLayout rowLayout = new RowLayout();
		rowLayout.justify = true;
		composite.setLayout(rowLayout);

		Button button = new Button(composite, SWT.PUSH);
		button.setText(Resources.res.getString("BestTimeDialog.ResetScores")); //$NON-NLS-1$
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				BestTime bestTime = new BestTime();
				BestTime.saveBestTime(bestTime);
				setLabels(bestTime, labels);
			}
		});

		button = new Button(composite, SWT.PUSH);
		button.setText(Resources.res.getString("BestTimeDialog.OK")); //$NON-NLS-1$
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.dispose();
			}
		});
	}

	private void setLabels(BestTime bestTime, Label[] labels) {
		labels[0].setText(bestTime.beginnerName);
		labels[1].setText(bestTime.beginnerTime + ""); //$NON-NLS-1$
		labels[2].setText(bestTime.intermediateName);
		labels[3].setText(bestTime.intermediateTime + ""); //$NON-NLS-1$
		labels[4].setText(bestTime.expertName);
		labels[5].setText(bestTime.expertTime + ""); //$NON-NLS-1$
		
		for(int i = 0; i < labels.length; i++)
			labels[i].pack();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -