SWT学生成绩管理系统
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_1.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_2.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_3.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_4.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_6.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_7.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_8.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_9.jpg)
![](http://www.blogjava.net/p_w_picpaths/blogjava_net/tscfengkui/WindowsLiveWriter/GUI_CEC8/%E6%9C%AA%E5%91%BD%E5%90%8D_thumb_10.jpg)
package com.dr.swt.XueChengXiTong;
public class Student {
private int id;
private String name;
private float score;
private String cls;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public String getCls() {
return cls;
}
public void setCls(String cls) {
this.cls = cls;
}
}
//主程序
package com.dr.swt.XueChengXiTong;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class MainUI
{
static Table table=null;
public static void main(String args[])
{
final Display display=new Display();
final Shell shell=new Shell(display);
//创建窗体
shell.setLayout(new FillLayout());
shell.setText("学生成绩管理系统");
shell.setBounds(0,0,600,600);
shell.setVisible(true);
//创建表单
table=new Table(shell,SWT.MULTI | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
//创建列
TableColumn column1=new TableColumn(table, SWT.NONE);
column1.setText("学号");
column1.setWidth(100);
TableColumn column2=new TableColumn(table,SWT.NONE);
column2.setText("姓名");
column2.setWidth(100);
TableColumn column3=new TableColumn(table,SWT.NONE);
column3.setText("成绩");
column3.setWidth(100);
TableColumn column4=new TableColumn(table,SWT.NONE);
column4.setText("班级");
column4.setWidth(100);
//创建按钮容器
Composite post=new Composite(shell,SWT.NONE);
Button button1=new Button(post,SWT.NONE);
//创建按钮
button1.setText("添加");
button1.setBounds(30,30,100,50);
Button button2=new Button(post,SWT.NONE);
button1.setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));
button2.setText("删除");
button2.setBounds(200,30,100,50);
button2.setFont(new Font(display,"宋体",20,SWT.NONE));
Button button3=new Button(post,SWT.NONE);
button3.setText("修改");
button3.setBounds(30,150,100,50);
Button button4=new Button(post,SWT.NONE);
button3.setEnabled(true);
button4.setText("查询");
button4.setBounds(200,150,100,50);
//table初始化
new TableItem(table,SWT.LEFT).setText(new String[]{"10","张三","60","08楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"11","李四","90","09电本"});
new TableItem(table,SWT.LEFT).setText(new String[]{"12","王倩","70","08计本"});
new TableItem(table,SWT.LEFT).setText(new String[]{"13","李明","80","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"14","刘德华","50","08机电"});
new TableItem(table,SWT.LEFT).setText(new String[]{"15","范伟","40","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"16","朱元璋","70","08经贸"});
new TableItem(table,SWT.LEFT).setText(new String[]{"17","周星驰","65","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"18","李连杰","55","08楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"19","赵薇","78","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"20","林心如","70","08机械"});
new TableItem(table,SWT.LEFT).setText(new String[]{"21","周润发","88","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"22","成龙","73","08汉语言"});
new TableItem(table,SWT.LEFT).setText(new String[]{"23","赵本山","80","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"24","郭德纲","56","08小品"});
new TableItem(table,SWT.LEFT).setText(new String[]{"25","周迅","35","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"26","王络丹","49","08土木"});
new TableItem(table,SWT.LEFT).setText(new String[]{"27","刘亦菲","60","09楼宇"});
new TableItem(table,SWT.LEFT).setText(new String[]{"28","张静初","55","08建工"});
new TableItem(table,SWT.LEFT).setText(new String[]{"29","文章","78","09通信"});
new TableItem(table,SWT.LEFT).setText(new String[]{"30","王力宏","80","09楼宇"});
//为添加按钮添加事件处理
button1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
TableItem[] item=table.getItems();
for(int i=0;i<item.length;i++)
{
item[i].setBackground(new Color(display,255, 255, 255));
}
System.out.println("test");
AddStudentUI.addStuShow(display,table);
}
});
//为删除按钮添加事件处理
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
TableItem[] item=table.getItems();
for(int i=0;i<item.length;i++)
{
item[i].setBackground(new Color(display,255, 255, 255));
}
if(table.getSelectionIndex()==-1)
{
MessageBox box=new MessageBox(shell);
box.setMessage("请选择要删除的内容");
box.open();
}
else
{
int[] selInices = table.getSelectionIndices();//将选中的序号放在数组中
table.remove(selInices);
}
}
});
//为修改按钮添加事件处理
button3.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
TableItem[] item=table.getItems();
for(int i=0;i<item.length;i++)
{
item[i].setBackground(new Color(display,255, 255, 255));
}
if(table.getSelectionIndex()==-1)
{
MessageBox box=new MessageBox(shell);
box.setMessage("请选择要修改的内容");
box.open();
}
else
{
ModifyStudentUI.modifyStuShow(display, table);
}
}
});
//为查找按钮添加事件处理
button4.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
TableItem[] item=table.getItems();
for(int i=0;i<item.length;i++)
{
item[i].setBackground(new Color(display,255, 255, 255));
}
FindStuUI.findStuShow(display,table);
}
});
shell.pack();
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
}
}
//添加学生程序
package com.dr.swt.XueChengXiTong;
import java.util.ArrayList;
import java.util.List;
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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
class AddStudentUI
{
Display display=null;
Shell shell=new Shell(display);
public AddStudentUI(Display dy) {
display=dy;
}
public static void addStuShow(Display dy,Table table)
{
AddStudentUI ast=new AddStudentUI(dy);
ast.run(table);
}
private void run(final Table table) {
shell.setBounds(500,200,250,400);
shell.setText("添加学生信息");
//添加标签
Label id=new Label(shell,SWT.NONE);
id.setText("学号");
id.setBounds(40,50,60,40);
Label name=new Label(shell,SWT.NONE);
name.setText("姓名");
name.setBounds(40,100,60,40);
Label score=new Label(shell,SWT.NONE);
score.setText("成绩");
score.setBounds(40,150,60,40);
Label cls=new Label(shell,SWT.NONE);
cls.setText("班级");
cls.setBounds(40,200,60,40);
//添加文本框
final Text text1=new Text(shell,SWT.NONE);
text1.setBounds(100,45,100,25);
text1.setTextLimit(2);//学号必须是两位
final Text text2=new Text(shell,SWT.NONE);
text2.setBounds(100,95,100,25);
text2.setTextLimit(6);//姓名最多为三位
final Text text3=new Text(shell,SWT.NONE);
text3.setBounds(100,145,100,25);
final Text text4=new Text(shell,SWT.NONE);
text4.setBounds(100,195,100,25);
//添加按钮
Button button1=new Button(shell,SWT.NONE);
button1.setText("确定");
button1.setBounds(55,250,60,40);
Button button2=new Button(shell,SWT.NONE);
button2.setText("取消");
button2.setBounds(135,250,60,40);
//为确定按钮添加事件处理,添加信息
button1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
try{
Student stu=new Student();
stu.setId(Integer.parseInt(text1.getText()));
stu.setName(text2.getText());
stu.setScore(Float.valueOf(text3.getText()).floatValue());
stu.setCls(text4.getText());
new TableItem(table,0).setText(new String[] { Integer.toString(stu.getId()) ,stu.getName(),Float.toString(stu.getScore()),stu.getCls()});
shell.close();
}catch(NumberFormatException e1)
{
MessageBox box=new MessageBox(shell,0);
box.setMessage("输入信息无效");
box.open();
}
}
});
//为取消按钮添加事件处理
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
shell.close();
}
});
shell.open();
}
}
//修改学生程序
package com.dr.swt.XueChengXiTong;
import java.util.List;
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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
public class ModifyStudentUI {
Display display=null;
Shell shell=new Shell(display);
public ModifyStudentUI(Display dy) {
display=dy;
}public static void modifyStuShow(Display dy,Table table)
{
ModifyStudentUI mst=new ModifyStudentUI(dy);
mst.run(table);
}
void run( final Table table) {
shell.setBounds(500,200,250,400);
shell.setText("修改学生信息");
//添加标签
Label id=new Label(shell,SWT.NONE);
id.setText("学号");
id.setBounds(40,50,60,40);
Label name=new Label(shell,SWT.NONE);
name.setText("姓名");
name.setBounds(40,100,60,40);
Label score=new Label(shell,SWT.NONE);
score.setText("成绩");
score.setBounds(40,150,60,40);
Label cls=new Label(shell,SWT.NONE);
cls.setText("班级");
cls.setBounds(40,200,60,40);
//添加文本框
final Text text1=new Text(shell,SWT.NONE);
text1.setBounds(100,45,100,25);
text1.setText(table.getItem(table.getSelectionIndex()).getText(0));
final Text text2=new Text(shell,SWT.NONE);
text2.setBounds(100,95,100,25);
text2.setText(table.getItem(table.getSelectionIndex()).getText(1));
final Text text3=new Text(shell,SWT.NONE);
text3.setBounds(100,145,100,25);
text3.setText(table.getItem(table.getSelectionIndex()).getText(2));
final Text text4=new Text(shell,SWT.NONE);
text4.setBounds(100,195,100,25);
text4.setText(table.getItem(table.getSelectionIndex()).getText(3));
//添加按钮
Button button1=new Button(shell,SWT.NONE);
button1.setText("确定");
button1.setBounds(55,250,60,40);
Button button2=new Button(shell,SWT.NONE);
button2.setText("取消");
button2.setBounds(135,250,60,40);
//为确定按钮添加事件处理,添加信息
button1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
try{
Student stu=new Student();
stu.setId(Integer.parseInt(text1.getText()));
stu.setName(text2.getText());
stu.setScore(Float.valueOf(text3.getText()).floatValue());
stu.setCls(text4.getText());
TableItem tableitem=table.getItem(table.getSelectionIndex());
tableitem.setText(new String[] { Integer.toString(stu.getId()) ,stu.getName(),Float.toString(stu.getScore()),stu.getCls()});
shell.close();
}catch(NumberFormatException e1)
{
MessageBox box=new MessageBox(shell,0);
box.setMessage("输入信息无效");
box.open();
}
}
});
//为取消按钮添加事件处理
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
shell.close();
}
});
shell.open();
}
}
//查询学生程序
package com.dr.swt.XueChengXiTong;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
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.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
public class FindStuUI {
Display display=null;
Shell shell=new Shell(display);
public FindStuUI(Display dy)
{
this.display=dy;
}
static void findStuShow(Display dy,Table table)
{
FindStuUI fst=new FindStuUI(dy);
fst.run(table);
}
public void run(final Table table)
{
shell.setBounds(500,200,280,400);
shell.setText("查询学生信息");
//添加标签
Label shuoming=new Label(shell,SWT.NONE);
shuoming.setText("请输入所要查询的信息,至少输入一项");
shuoming.setFont(new Font(display,"宋体",10,SWT.BOLD));
shuoming.setBounds(10,30,245,20);
Label id=new Label(shell,SWT.NONE);
id.setText("请输入要查询的学号");
id.setBounds(20,70,120,40);
Label name=new Label(shell,SWT.NONE);
name.setText("请输入要查询的姓名");
name.setBounds(20,120,120,40);
Label score=new Label(shell,SWT.NONE);
score.setText("请输入要查询的成绩");
score.setBounds(20,170,120,40);
Label cls=new Label(shell,SWT.NONE);
cls.setText("请输入要查询的班级");
cls.setBounds(20,220,120,40);
//添加文本框
final Text text1=new Text(shell,SWT.NONE);
text1.setBounds(140,65,100,25);
final Text text2=new Text(shell,SWT.NONE);
text2.setBounds(140,115,100,25);
final Text text3=new Text(shell,SWT.NONE);
text3.setBounds(140,165,100,25);
final Text text4=new Text(shell,SWT.NONE);
text4.setBounds(140,215,100,25);
//添加按钮
Button button1=new Button(shell,SWT.NONE);
button1.setText("确定");
button1.setBounds(55,270,60,40);
Button button2=new Button(shell,SWT.NONE);
button2.setText("取消");
button2.setBounds(135,270,60,40);
//为确定按钮添加事件处理
button1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
boolean flag=false;
if("".equals(text1.getText())&&"".equals(text2.getText())&&"".equals(text3.getText())&&"".equals(text4.getText()))
{
MessageBox box = new MessageBox(shell);
box.setMessage("请至少输入一项信息");
box.open();
}
else
{
int count=0;
TableItem it[]=table.getItems();
for(int i=0;i<it.length;i++)
{
flag=true;
if(text1.getText().equals(it[i].getText(0)))
{
it[i].setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));flag=false;
}
else if(text2.getText().equals(it[i].getText(1)))
{
it[i].setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));flag=false;
}
else if(text3.getText().equals(it[i].getText(2)))
{
it[i].setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));flag=false;
}
else if(text4.getText().equals(it[i].getText(3)))
{
it[i].setBackground(new Color(display, SWT.COLOR_DARK_RED, 200, 20));flag=false;
}
if(flag==false)
{
count++;
}
}
if(count==0)
{
MessageBox box=new MessageBox(shell);
box.setMessage("很抱歉,没有你所要查询的信息");
box.open();
}
}
if(flag)
{
shell.close();
}
}
});
//为取消按钮添加事件处理
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
shell.close();
}
});
shell.open();
}
}
转载于:https://blog.51cto.com/tscfengkui/414050
SWT学生成绩管理系统相关推荐
- SWT学生成绩管理系统(转)
这个程序终于完完整整地做完了,虽然还不完善,但基本的功能实现了.这个程序零零散散花费了我近一个月的时间,在这一个月的时间里,通过别人的帮助和对程序的调试本人收获不小.希望通过这个博客和大家分享一下我在 ...
- c语言输入学生成绩q退出,哭诉、拜求C语言学生成绩管理系统
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 /* Note:Your choice is C IDE */ #include "stdio.h" #include "s ...
- java开发的简易学生成绩管理系统
经过1个月的紧张学习和应用,终于做出了这个简易的学生成绩管理系统. 代码如下(仅供参考学习) view包下的菜单 package com.xujulong.www.view: import java. ...
- 基于SSH实现的学生成绩管理系统
开发语言:JAVA 开发技术:spring+springmvvc+hibernate+easyui 数据库:MYSQL 开发工具:IDEA / Eclipse 该学生成绩管理系统主要包括前台用户界面的 ...
- KS006基于SSM实现学生成绩管理系统
项目简介 本系统是基于JSP+SSM+Mysql实现的学生成绩管理系统.主要实现的功能有教师管理.学生管理.课程管理.学生成绩管理. 难度等级:中等 技术栈 编辑器 Eclipse Version: ...
- php成绩管理前段模板,php学生成绩管理系统(模板).doc
. .. 计算机与通信学院 2013年春季学期 题 目:学生成绩管理系统 专业班级:软件工程基地班 姓 名:陶婷婷 学 号 目录 TOC \o "1-2" \h \u HYPERL ...
- 用链表c语言程序设计,C语言程序设计-基于链表的学生成绩管理系统
<C语言程序设计-基于链表的学生成绩管理系统>由会员分享,可在线阅读,更多相关<C语言程序设计-基于链表的学生成绩管理系统(18页珍藏版)>请在人人文库网上搜索. 1.华北科技 ...
- c语言用链表实现成绩管理系统,C语言基于单链表得学生成绩管理系统
前言 传说中讲课通俗而不庸俗,说话风流而不下流的小编又来了哦,今天的主要内容是:C语言基于单链表得学生成绩管理系统.首先给年夜家总结下为什么你们学习C语言会觉得难,尤其是对单链表这块,主要原因得是因为 ...
- python成绩管理系统界面-python实现简易版学生成绩管理系统
300来行python代码实现简易版学生成绩管理系统,供大家参考,具体内容如下 使用链表来实现 class Node(object): def __init__(self, data, pointer ...
最新文章
- python 正则表达式方法_Python正则表达式一: 基本使用方法
- Netflix 开源用于 Spring Boot的 GraphQL 服务框架DGS
- cdr文件过大导出pdf打不开_PDF快速导出JPG对应的分辨率技巧
- 如何让UTF-8能对文档XML编辑
- 使用SqlBulkCopy数据导入和复制
- matlab-高数 polar 极坐标系 绘制阿基米德线,心形线
- P1852-跳跳棋【思维,差分,二分】
- 【POJ - 1556】The Doors (计算几何,线段相交)
- 第27课 老狼老狼几点钟 《小学生C++趣味编程》
- 《Effective Objective-C 2.0 编写高质量iOS与OS X代码的52个有效方法》笔记
- Mutable和Immutable
- 将mp3格式的音频转换为采样率8k的wav
- 怎么用spss做冗余分析_【攻略】手把手教你怎么用SPSS做统计分析
- linux命令行大全第2版,Linux命令行大全(第2版)
- 【HCIE-RS】TAC诊断1
- 内存管理Memoryamp;nbsp;OC——第九天
- 苹果手表 WatchKit 应用架构简介
- 项目名前有个红色感叹号的解决办法
- 【组队学习】【36期】组队学习内容详情
- 全面发展还是术业专攻?这就是答案
热门文章
- 唐山师范学院计算机科学与技术地址,2021年唐山师范学院有几个校区,大一新生在哪个校区...
- 成员变量隐藏c语言,C语言中隐藏结构体的细节
- linux strace cpu,如何定位死循环或高CPU使用率(linux)
- cname 别名记录 解析过程_西部数码操作解析:如何为服务器创建别名地址
- Hadoop HIVE 条件控制函数
- R语言聚类算法之期望最大化聚类(Expectation Maximization Algorithm)
- 把网页放到云服务器上,怎么把网页放到云服务器上
- 系统分析师资料_软考 系统分析师考试通过总结
- linux脚本中swith,BeanShell中switch语句
- 阿里架构总监一次讲透中台架构,13页PPT精华详解,建议收藏