第二次数据库作业--gui

  1 package gui;
  2
  3 import action.C2SAction;
  4 import action.CourseAction;
  5 import action.StudentAction;
  6 import javafx.application.Application;
  7 import javafx.geometry.Insets;
  8 import javafx.scene.Scene;
  9 import javafx.scene.control.*;
 10 import javafx.scene.layout.GridPane;
 11 import javafx.scene.layout.HBox;
 12 import javafx.stage.Stage;
 13 import model.C2S;
 14 import model.Course;
 15 import model.Student;
 16
 17 import java.sql.SQLException;
 18 import java.util.List;
 19
 20 /**
 21  * Created by yinus
 22  * Date:2016/4/16
 23  * Time:13:45
 24  */
 25 public class view extends Application {
 26     @Override
 27     public void start(Stage primaryStage) throws Exception {
 28         HBox box = new HBox();
 29         box.setSpacing(10);
 30         TextArea textArea = new TextArea("second database project\n");
 31         textArea.appendText("------version 1.0------\n");
 32         textArea.appendText("------author ycy------\n");
 33         textArea.setPrefColumnCount(50);
 34         textArea.setPrefRowCount(20);
 35         textArea.setWrapText(true);
 36         textArea.setEditable(false);
 37         ScrollPane scrollPane = new ScrollPane(textArea);
 38         GridPane gridPane = new GridPane();
 39         gridPane.setPadding(new Insets(5,5,5,5));
 40         gridPane.setHgap(10);
 41         gridPane.setVgap(10);
 42         gridPane.add(new Label("student name"),0,0);
 43         TextField sn = new TextField();
 44         sn.setMaxWidth(100);
 45         gridPane.add(sn,1,0);
 46         gridPane.add(new Label("student id"),0,1);
 47         TextField si = new TextField();
 48         si.setMaxWidth(100);
 49         gridPane.add(si,1,1);
 50         gridPane.add(new Label("course title"),0,2);
 51         TextField ct = new TextField();
 52         ct.setMaxWidth(100);
 53         gridPane.add(ct,1,2);
 54         gridPane.add(new Label("course id"),0,3);
 55         TextField ci = new TextField();
 56         ci.setMaxWidth(100);
 57         gridPane.add(ci,1,3);
 58         gridPane.add(new Label("credit"),0,4);
 59         TextField cd = new TextField();
 60         cd.setMaxWidth(100);
 61         gridPane.add(cd,1,4);
 62         RadioButton rs = new RadioButton("student");
 63         RadioButton rc = new RadioButton("course");
 64         RadioButton rcs = new RadioButton("cs");
 65         gridPane.add(rcs,0,5);
 66         gridPane.add(rc,1,5);
 67         gridPane.add(rs,2,5);
 68         ToggleGroup group = new ToggleGroup();
 69         rs.setToggleGroup(group);
 70         rc.setToggleGroup(group);
 71         rcs.setToggleGroup(group);
 72         Button add = new Button("add");
 73         Button delete = new Button("delete");
 74         Button update = new Button("update");
 75         Button query = new Button("query");
 76         Button clear = new Button("clear");
 77         gridPane.add(add,0,6);
 78         gridPane.add(delete,1,6);
 79         gridPane.add(update,0,7);
 80         gridPane.add(query,1,7);
 81         gridPane.add(clear,0,8);
 82         box.getChildren().addAll(scrollPane,gridPane);
 83         Scene scene = new Scene(box);
 84         primaryStage.setScene(scene);
 85         primaryStage.setTitle("dbproj1.0");
 86         primaryStage.show();
 87         rcs.setSelected(true);
 88         clear.setOnAction(e->{
 89             sn.clear();
 90             si.clear();
 91             ci.clear();
 92             cd.clear();
 93             ct.clear();
 94         });
 95         add.setOnAction(e->{
 96             if (rc.isSelected()){
 97                 String courseTitle = ct.getText();
 98                 int courseId = Integer.parseInt(ci.getText());
 99                 CourseAction courseAction = new CourseAction();
100                 try {
101                     courseAction.add(new Course(courseId,courseTitle));
102                     textArea.appendText("title:"+courseTitle+" id:"+courseId+ " added successfully\n" );
103
104                 } catch (SQLException e1) {
105                     e1.printStackTrace();
106                 }
107             }
108             else if (rs.isSelected()){
109                 String studentName = sn.getText();
110                 int stuId = Integer.parseInt(si.getText());
111                 StudentAction studentAction = new StudentAction();
112                 try {
113                     studentAction.add(new Student(stuId,studentName));
114                     textArea.appendText("name:"+studentName+" id:"+stuId+ " added successfully\n" );
115
116                 } catch (SQLException e1) {
117                     e1.printStackTrace();
118                 }
119             }
120             else if (rcs.isSelected()){
121                 int stuid = Integer.parseInt(si.getText());
122                 int couid = Integer.parseInt(ci.getText());
123                 double cr = Double.parseDouble(cd.getText());
124                 C2SAction c2SAction = new C2SAction();
125                 try {
126                     c2SAction.add(new C2S(stuid,couid,cr));
127                     textArea.appendText("student id:"+stuid+" course id:"+couid+" credit"+ cr + " added successfully\n" );
128
129                 } catch (SQLException e1) {
130                     e1.printStackTrace();
131                 }
132             }
133         });
134
135         delete.setOnAction(e->{
136             if (rc.isSelected()){
137                 int i = Integer.parseInt(ci.getText());
138                 CourseAction courseAction = new CourseAction();
139                 try {
140                     courseAction.delete(i);
141                     textArea.appendText("delete successfully\n");
142                 } catch (SQLException e1) {
143                     e1.printStackTrace();
144                 }
145             }
146             else if (rs.isSelected()){
147                 int i = Integer.parseInt(si.getText());
148                 StudentAction studentAction = new StudentAction();
149                 try {
150                     studentAction.delete(i);
151                     textArea.appendText("delete successfully\n");
152                 } catch (SQLException e1) {
153                     e1.printStackTrace();
154                 }
155             }
156             else if (rcs.isSelected()){
157                 int c = Integer.parseInt(ci.getText());
158                 int s = Integer.parseInt(si.getText());
159                 C2SAction cs = new C2SAction();
160                 try {
161                     cs.delete(s,c);
162                     textArea.appendText("delete successfully\n");
163                 } catch (SQLException e1) {
164                     e1.printStackTrace();
165                 }
166             }
167         });
168
169         update.setOnAction(e->{
170             if (rc.isSelected()){
171                 String courseTitle = ct.getText();
172                 int courseId = Integer.parseInt(ci.getText());
173                 CourseAction courseAction = new CourseAction();
174                 try {
175                     Course course = courseAction.queryById(courseId);
176                     course.setTitle(courseTitle);
177                     courseAction.update(course);
178                     textArea.appendText("title:"+courseTitle+" id:"+courseId+ " updated successfully\n" );
179                 } catch (SQLException e1) {
180                     e1.printStackTrace();
181                 }
182             }
183             else if (rs.isSelected()){
184                 String studentName = sn.getText();
185                 int stuId = Integer.parseInt(si.getText());
186                 StudentAction studentAction = new StudentAction();
187                 try {
188                     Student student = studentAction.queryById(stuId);
189                     student.setName(studentName);
190                     studentAction.update(student);
191                     textArea.appendText("name:"+studentName+" id:"+stuId+ " updated successfully\n" );
192                 } catch (SQLException e1) {
193                     e1.printStackTrace();
194                 }
195
196             }
197             else if (rcs.isSelected()){
198                 int stuid = Integer.parseInt(si.getText());
199                 int couid = Integer.parseInt(ci.getText());
200                 double cr = Double.parseDouble(cd.getText());
201                 C2SAction c2SAction = new C2SAction();
202                 try {
203                     C2S s = c2SAction.query(stuid, couid);
204                     s.setCredit(cr);
205                     c2SAction.update(s);
206                     textArea.appendText("student id:"+stuid+" course id:"+couid+" credit"+ cr + " updated successfully\n" );
207                 } catch (SQLException e1) {
208                     e1.printStackTrace();
209                 }
210             }
211         });
212
213         query.setOnAction(e->{
214             CourseAction courseAction = new CourseAction();
215             if (rc.isSelected()){
216                 if (!ci.getText().equals("")) {
217                     try {
218                         int id = Integer.parseInt(ci.getText());
219                         Course course = courseAction.queryById(id);
220                         if (course == null)
221                             textArea.appendText("null\n");
222                         else
223                             textArea.appendText(course.toString());
224                     } catch (SQLException e1) {
225                         e1.printStackTrace();
226                     } catch (NumberFormatException ee) {
227                         ee.printStackTrace();
228                     }
229                 }
230                 else if (!ct.getText().equals("")){
231                     String courseTitle = ct.getText().trim();
232                     try {
233                         List<Course> courses = courseAction.queryByName(courseTitle);
234                         courses.forEach(course -> textArea.appendText(course.toString()));
235                     } catch (SQLException e1) {
236                         e1.printStackTrace();
237                     }
238                 }
239             }
240             else if (rs.isSelected()){
241                 StudentAction studentAction = new StudentAction();
242                 if (!si.getText().equals("")){
243                     int i = Integer.parseInt(si.getText());
244                     try {
245                         Student student = studentAction.queryById(i);
246                         textArea.appendText(student.toString());
247                     } catch (SQLException e1) {
248                         e1.printStackTrace();
249                     }
250                 }
251                 else if (!sn.getText().equals("")){
252                     try {
253                         List<Student> students = studentAction.queryByName(sn.getText());
254                         students.forEach(student -> textArea.appendText(student.toString()));
255                     } catch (SQLException e1) {
256                         e1.printStackTrace();
257                     }
258                 }
259             }
260             else if (rcs.isSelected()){
261                 int stuid = Integer.parseInt(si.getText());
262                 int couid = Integer.parseInt(ci.getText());
263                 C2SAction cs = new C2SAction();
264                 try {
265                     C2S c2S = cs.query(stuid, couid);
266                     textArea.appendText(c2S.toString());
267                 } catch (SQLException e1) {
268                     e1.printStackTrace();
269                 }
270             }
271         });
272     }
273     public static void main(String[] args) {
274             Application.launch(args);
275     }
276 }
时间: 2024-10-06 11:55:07

第二次数据库作业--gui的相关文章

第二次数据库作业--action

package action; import dao.C2SDao; import model.C2S; import java.sql.SQLException; import java.util.List; /** * Created by yinus * Date:2016/4/6 * Time:18:43 */ public class C2SAction { public void add(C2S c) throws SQLException { C2SDao cd = new C2S

第二次数据库作业--Main

import dao.CourseDao; import model.Course; import view.C2SView; import view.CourseView; import view.StudentView; import java.sql.SQLException; import java.util.List; import java.util.Scanner; /** * Created by yinus * Date:2016/4/8 * Time:16:09 */ pub

第二次数据库作业--view

package view; import action.C2SAction; import action.CourseAction; import action.StudentAction; import model.C2S; import model.Course; import model.Student; import java.sql.SQLException; import java.util.List; import java.util.Scanner; import java.ut

第二次数据库作业--model

package model; import java.util.Date; /** * Created by yinus * Date:2016/4/6 * Time:18:44 */ public class C2S { private int stu_id; private int cou_id; private double credit; private Date create_time; private Date update_time; public C2S() { } public

第二次数据库作业--dao

package dao; import model.C2S; import utils.Dbtuil; import java.sql.*; import java.util.ArrayList; import java.util.List; /** * Created by yinus * Date:2016/4/6 * Time:18:44 */ public class C2SDao { public void add(C2S cs) throws SQLException { Conne

SDN第二次上机作业

SDN第二次上机作业 1.安装floodlight 参考链接:http://www.sdnlab.com/19189.html 2.生成拓扑并连接控制器floodlight,利用控制器floodlight查看图形拓扑 拓扑如图所示 提交要求:控制器floodlight所示可视化图形拓扑的截图,及主机拓扑连通性检测截图 3.利用字符界面下发流表,使得'h1'和'h2' ping 不通 参考链接:http://www.sdnlab.com/19394.html 提交要求:流表截图,及拓扑连通性截图

数据库作业14——综合练习(二) 反馈情况

数据库作业14--综合练习(二) 反馈情况 一.作业要求复述 1.创建数据库CPXS,保存于E盘根目录下以自己学号+姓第一个字母(阿拉伯数字+大写字母)方式创建的文件夹中,初始大小5MB,最大20MB,以10%方式增长,日志文件存于同一文件夹,初始大小2MB,最大5MB,以1MB方式增长: 2.创建表CP,CPBH为主键,8位数字,CPMC,长度12个字符,JG为精确到小数点后2位,KCL为整数,除了KCL,其他都不能为空: 3.使用INSERT输入数据,具体数据如下: '10001100',

Oracle 用脚本安装第二个数据库

安装第二个数据库: 登录oracle用户进入家目录,添加配置环境变量: vi .bash_profier ORACLE_SID=prod2 临时环境变量: $export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 $export ORACLE_SID=prod2 创建第二个数据库文件目录: $mkdir -p /u01/app/oracle/oradata/prod2 创建sys用户密码文件: $cd /u01/app/oracle/prod

第二次阅读作业--12061161 赵梓皓

阅读笔记之No Silver Bullet 本文中,作者的观点是没有任何一项技术或方法可使软件工程的生产力在十年内提高十倍(1986) 作者列举的原因是 代码的完成分为两部分: 抽象(建模)和 代码实现.根据我个人的理解,就是 设计和实现的过程.作者认为实现过程的速度相对来说比较好的提高,但是 设计的过程很难提高.而根据设计过程在整个项目中占的比例要大于1/10,所以得出结论没有任何一项技术或方法可使软件工程的生产力在十年内提高十倍. 我认为,作者的见解相对来说是比较合理的.实现的过程是人与机器