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

📄 popup.java

📁 SWT开发的信息简单的信息管理软件
💻 JAVA
字号:
package dian.ikeel.swt.first;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

import dian.ikeel.yin.Shy;
import dian.ikeel.yin.*;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PopUp {
	private Shell shell;
	private Text inputname;
	private Text inputnum;
	private Button inputsexboy;
	private Button inputsexgirl;

	private Text inputclass;
	private Text inputage;
	private Text inputmajor;

	private Table studentlist;

	private Button cancelButton;
	private Button saveButton;
	private Button nextButton;
	private Button prevButton;
	private Button editButton;
	private Button deleteButton;
	private Button newButton;
	private Display display;
	private Label warning;
	private static Shy shy;
	private Student curstutent;

	//private static CommonData commondata;

	public PopUp(Display disp) {
		this.display = disp;
		this.shell = new Shell(display);
		shy = new Shy();
		//commondata = CommonData.getInstance();
	}

	public void init() {
	//	shell.setSize(650, 500);
		shell.setBounds(100, 100, 650, 500);
		shell.setText("电信系学生信息管理系统——By xxx");
		shell.setImage(new Image(null, "image/pen.jpg"));
		//shell.setBackgroundImage(new Image(null,"image/13.jpg"));

		{
			newButton = new Button(shell, SWT.NONE);
			newButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {

					clearTextAndEditable(Boolean.TRUE);
					System.out.println("New button seected.");
				}
			});
			newButton.setBounds(30, 380, 75, 35);
			newButton.setText("新建记录");
		}

		{
			deleteButton = new Button(shell, SWT.NONE);
			deleteButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					clearTextAndEditable(Boolean.FALSE);
					deleteCurrent();

				}
			});
			deleteButton.setBounds(180, 380, 75, 35);
			deleteButton.setText("删除记录");
		}

		{
			editButton = new Button(shell, SWT.NONE);
			editButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {

					saveUser();
					System.out.println("Edit button selected.");
				}
			});
			editButton.setBounds(105, 380, 75, 35);
			editButton.setText("保存修改");
		}

		{
			cancelButton = new Button(shell, SWT.NONE);
			cancelButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
                  //  cancelButton.getShell().getDisplay().getShells()[0].redraw();
					cancelButton.getShell().close();
				}
			});
			cancelButton.setBounds(520, 380, 75, 35);
			cancelButton.setText("取消");

		}

		{

			final Group group = new Group(shell, SWT.NONE);
			group.setText("详细信息");
			 group.setBounds(10, 10, 585, 355);
			 group.setBackgroundMode(SWT.NO_BACKGROUND);
			

			{
				final Label label = new Label(group, SWT.NONE);
				label.setBounds(10, 20, 135, 25);
				label.setText("学号:");
			}
			{
				final Label label = new Label(group, SWT.NONE);
				label.setBounds(10, 60, 135, 25);
				label.setText("姓名:");
			}
			{
				final Label label = new Label(group, SWT.NONE);
				label.setBounds(10, 100, 135, 25);
				label.setText("年龄:");
			}

			{
				final Label label = new Label(group, SWT.NONE);
				label.setBounds(10, 140, 135, 25);
				label.setText("性别:");
			}
			{
				final Label label = new Label(group, SWT.NONE);
				label.setBounds(10, 180, 135, 25);
				label.setText("专业");
			}

			{
				final Label label = new Label(group, SWT.NONE);
				label.setBounds(10, 220, 135, 25);
				label.setText("班级");
			}
			{
				inputnum = new Text(group, SWT.BORDER | SWT.READ_ONLY);

				inputnum.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {

						inputnum.setEditable(Boolean.FALSE);
					}
				});
				inputnum.setBounds(150, 20, 420, 25);
			}

			{
				inputname = new Text(group, SWT.BORDER | SWT.READ_ONLY);
				inputname.setToolTipText("双击可编辑");
				inputname.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {

						inputname.setEditable(Boolean.TRUE);
					}
				});
				inputname.setBounds(150, 60, 420, 25);
			}

			{
				inputage = new Text(group, SWT.BORDER | SWT.READ_ONLY);
				inputage.setToolTipText("双击可编辑");
				inputage.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {

						inputage.setEditable(Boolean.TRUE);
					}
				});
				inputage.setBounds(150, 100, 420, 25);
			}

			Group inputsex = new Group(group, SWT.NONE);
			inputsex.setBounds(150, 135, 420, 25);
			{
				inputsexboy = new Button(inputsex, SWT.RADIO);
				inputsexboy.setText("男");
				inputsexboy.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {
						inputsexboy.setEnabled(Boolean.TRUE);
						inputsexgirl.setEnabled(Boolean.TRUE);

					}
				});

				inputsexboy.setBounds(20, 1, 50, 25);
			}

			{

				inputsexgirl = new Button(inputsex, SWT.RADIO);
				inputsexgirl.setText("女");
				inputsexgirl.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {

						inputsexboy.setEnabled(Boolean.TRUE);
						inputsexgirl.setEnabled(Boolean.TRUE);

					}
				});

				inputsexgirl.setBounds(100, 1, 50, 25);
			}

			{
				inputmajor = new Text(group, SWT.BORDER | SWT.READ_ONLY);
				inputmajor.setToolTipText("双击可编辑");
				inputmajor.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {

						inputmajor.setEditable(Boolean.TRUE);
					}
				});
				inputmajor.setBounds(150, 180, 420, 25);
			}
			{
				inputclass = new Text(group, SWT.BORDER | SWT.READ_ONLY);
				inputclass.setToolTipText("双击可编辑");
				inputclass.addListener(SWT.MouseDoubleClick, new Listener()

				{
					public void handleEvent(Event event) {

						inputclass.setEditable(Boolean.TRUE);
					}
				});
				inputclass.setBounds(150, 220, 420, 25);
			}

			{

				warning = new Label(group, SWT.NONE);
				warning.setBounds(150, 255, 420, 25);
			}

		}

	}

	public void deleteCurrent() {
		Student stu=new Student();
		//stu.setUuid(getCurstudent().getUuid());
		shy.deleteStudent(getCurstudent());
	}

	public void saveUser() {
		Student stu = new Student();
		if (checkData()) {
			stu.setSerialnum(inputnum.getText());
			stu.setName(inputname.getText());

			Pattern regex = Pattern.compile("^[0-9]*$");
			Matcher isnum = regex.matcher(inputage.getText());
			if (isnum.matches()) {
				int age = Integer.valueOf(inputage.getText());
				if (age > 5 && age < 110) {
					stu.setAge(age);

					stu.setUuid();
					stu.setMajor(inputmajor.getText());
					stu.setClassNo(inputclass.getText());
					String sex;
					if (inputsexboy.getSelection())
						stu.setSex(1);
					else if (inputsexgirl.getSelection()) {
						stu.setSex(2);
					}
					// commondata.getStulist().addLast(stu);
					try {
						shy.addStudent(stu);
					} catch (Exception e) {
						e.printStackTrace();
					}

				}
				 else {
						warning.setText("年龄数值应该在5-110");
						inputage.setText("");
						return;
					}
			}
		  else {
			warning.setText("年龄必须为数值型");
			inputage.setText("");
			return;
		   }
		}
	}

	public boolean checkData() {
		if (inputnum.getText().trim() == ""
				|| inputname.getText().trim() == ""
				|| inputage.getText().trim() == ""
				|| inputmajor.getText().trim() == ""
				|| inputclass.getText().trim() == ""
				|| (!inputsexboy.getSelection() && !inputsexgirl.getSelection())) {

			warning.setText("信息未填写完整!");
			warning.setForeground(display.getSystemColor(SWT.COLOR_RED));
			return false;
		}
		return true;
	}

	public void clearText() {

		inputnum.setText("");
		inputname.setText("");
		inputage.setText("");
		inputsexboy.setSelection(Boolean.FALSE);
		inputsexgirl.setSelection(Boolean.FALSE);
		inputmajor.setText("");
		inputclass.setText("");
	}

	public void clearTextAndEditable(boolean editable) {
		clearText();
		inputnum.setEditable(editable);
		inputname.setEditable(editable);
		inputage.setEditable(editable);
		inputsexboy.setEnabled(editable);
		inputsexgirl.setEnabled(editable);
		inputmajor.setEditable(editable);
		inputclass.setEditable(editable);
	}

	public void Display(Student stu) {
		if (stu.getUuid() != null) {
			inputnum.setText(stu.getSerialnum());
			inputname.setText(stu.getName());
			inputage.setText(String.valueOf(stu.getAge()));
			{
				String sex = String.valueOf(stu.getSex());
				if (sex.equals("1"))
				{
					inputsexboy.setSelection(Boolean.TRUE);
					inputsexgirl.setSelection(Boolean.FALSE);
				}
				else if (sex.equals("2"))
				{
					inputsexgirl.setSelection(Boolean.TRUE);
					inputsexboy.setSelection(Boolean.FALSE);
				}

			}

			inputmajor.setText(stu.getMajor());
			inputclass.setText(stu.getClassNo());
		}

	}

	public void open(Student stu) {

		setCurstudent(stu);
		init();
		Display(stu);
		shell.open();
	}

	public Student getCurstudent() {
		return  this.curstutent;
	}
	
	public void setCurstudent(Student stu)
	{
		this.curstutent=stu;
	}

}

⌨️ 快捷键说明

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