热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

java实现科研信息管理系统

这篇文章主要为大家详细介绍了java科研信息管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

一、前言

本学期学习了JAVA语言,在学期的结束,写一个有操作界面,与数据库关联的管理系统,用来巩固自己本学习所学的知识。
用到的知识:JAVA基础,JAVA界面设计(GUI),Oracle数据库(需要掌握数据库的基本操作语句),链接数据库。
使用的开发工具:MyEclipse Professional 2014

二、设计

我们管理的属性有:项目编号,项目名称,参与人员,负责人,项目开始时间,结束时间。科研项目系统主要有四个功能,对科研项目的增加、删除、修改、查询。以及为增加系统安全性所设计的登陆模式。

2.1 增加:向数据库的表中增加科研项目的所有信息

 

添加后在控制台使用SQL语句查找,验证是否已添加至数据库中。

2.2 查询:通过具有唯一性的项目编号查找该项目的所有信息

2.3 修改:根据项目编号选中要修改的项目,并重新输入项目信息进行修改

2.4 删除:通过具有唯一性的项目编号删除对应项目的所有信息

三、窗体源码

3.1 登录界面

package 科研信息管理系统;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class LoginWindows extends Frame implements WindowListener,ActionListener 
{
 public Label lgLabel; //用户名标签
 public Label pwdLabel; //密码标签
 public TextField lgText; //用户名文本框
 public TextField pwdText; //密码文本框
 public Button lgBt;   //登录按钮
 public Button quitBt;  //退出按钮

  public LoginWindows()
  {
   super();
   this.setSize(400, 300);
   this.setTitle("科研信息管理系统");
   this.setLayout(null);

   lgLabel=new Label();
   lgLabel.setText("登录账号:");
   lgLabel.setSize(60, 30);
   lgLabel.setLocation(70,70);

   pwdLabel=new Label();
   pwdLabel.setText("密  码:");
   pwdLabel.setSize(60,30);
   pwdLabel.setLocation(70, 150);

   lgText=new TextField();
   lgText.setSize(180, 30);
   lgText.setLocation(140, 70);

   pwdText=new TextField();
   pwdText.setSize(180,30);
   pwdText.setLocation(140, 150);

   lgBt=new Button();
   lgBt.setLabel("登录");
   lgBt.setSize(60,30);
   lgBt.setLocation(120, 220);

   quitBt=new Button();
   quitBt.setLabel("退出");
   quitBt.setSize(60,30);
   quitBt.setLocation(220,220);
   quitBt.addActionListener(this);
   lgBt.addActionListener(this);
   this.addWindowListener(this);

   this.add(lgLabel);
   this.add(pwdLabel);
   this.add(lgText);
   this.add(pwdText);
   this.add(lgBt);
   this.add(quitBt);
   this.setVisible(true);

  }
  public static void main(String args[])
  {
   LoginWindows main=new LoginWindows();

  }
 @Override
 public void actionPerformed(ActionEvent e) {

  Button bt=(Button) e.getSource();
  if(bt.getLabel().equals("退出"))
  {
   System.exit(0);
  }
  else {
  if ((lgText.getText().equals(""))||(pwdText.getText().equals(""))) 
   {
    JOptionPane.showMessageDialog(this,"账号或密码为空");
   }
   else
   {
     if ((lgText.getText().equals("admin"))&&(pwdText.getText().equals("111"))) 
   //if((lgText.getText().equals(""))||(pwdText.getText().equals("")))
    {
     this.setVisible(false);
    // Sqlwindow sql=new Sqlwindow();
     WindowsView w=new WindowsView();
     w.SciencePro();

    }
    else {
     JOptionPane.showMessageDialog(this, "没有权限");
    }
   }}}






 @Override
 public void windowOpened(WindowEvent e) {
  // TODO Auto-generated method busb

 }

 @Override
 public void windowClosing(WindowEvent e) {
  // TODO Auto-generated method busb
  System.exit(0);
 }

 @Override
 public void windowClosed(WindowEvent e) {
  // TODO Auto-generated method busb

 }

 @Override
 public void windowIconified(WindowEvent e) {
  // TODO Auto-generated method busb

 }

 @Override
 public void windowDeiconified(WindowEvent e) {
  // TODO Auto-generated method busb

 }

 @Override
 public void windowActivated(WindowEvent e) {
  // TODO Auto-generated method busb

 }

 @Override
 public void windowDeactivated(WindowEvent e) {
  // TODO Auto-generated method busb

 }
}

3.2主窗体源码

package 科研信息管理系统;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

import javax.swing.event.*;
import javax.swing.tree.*;

public class WindowsView implements TreeSelectionListener,ActionListener //窗口类
{
 JFrame main;
 JPanel leftPa;
 JPanel upPa;
 JPanel downPa;

 ///查询用控件
 JLabel numLa; //通过项目编号查询
 JTextField numTxt;
 JButton numBt;

 JTextField nameTxt; //显示项目名称的文本框
 JTextField peopleTxt; //显示参与人员
 JTextField principalTxt; //显示主要负责人
 JTextField timeStartTxt; //显示开始时间的文本框
 JTextField timeEndTxt; //显示预期结束时间的文本框

 //增加用控件
 JLabel anumLa; 
 JLabel anameLa;
 JLabel apeopleLa;
 JLabel aprincipalLa;
 JLabel atimeStartLa;
 JLabel atimeEndLa;

 JTextField anumTxt;
 JTextField anameTxt;
 JTextField apeopleTxt;
 JTextField aprincipalTxt;
 JTextField atimeStartTxt;
 JTextField atimeEndTxt;
 JButton addBt;
 JTable showTable;

 //删除用控件
 JLabel dnumLa; 
 JButton dnumBt;
 JTextField dnumTxt;

 //修改用控件
 JLabel alnumLa; 
 JTextField allnumTxt;
 JButton alseBt;
 JButton alBt;

 JLabel allnumLa; 
 JLabel alnameLa;
 JLabel alpeopleLa;
 JLabel alprincipalLa;
 JLabel altimeStartLa;
 JLabel altimeEndLa;
 JTextField alnumTxt;
 JTextField alnameTxt;
 JTextField alpeopleTxt;
 JTextField alprincipalTxt;
 JTextField altimeStartTxt;
 JTextField altimeEndTxt;

 public void SciencePro()
 {
  main=new JFrame();
  main.setSize(800,800);
  main.setTitle("科研信息管理");
  main.setLayout(null);


  leftPa=new JPanel();
  leftPa.setSize(150, 600);
  leftPa.setLocation(0, 0);
  leftPa.setBackground(Color.white);
  initLeftPanel();
  main.add(leftPa);

  upPa=new JPanel();
  upPa.setSize(650, 400);
  upPa.setLocation(150, 0);
  upPa.setBackground(Color.gray);
  main.add(upPa);

  downPa=new JPanel();
  downPa.setSize(650, 400);
  downPa.setLocation(150, 400);
  downPa.setBackground(Color.orange);
  main.add(downPa);


  main.setVisible(true);
 }

 private void initLeftPanel()
 {
  String[] strs={"查询","增加","删除","修改"};
  JTree tree=new JTree(strs);
  tree.addTreeSelectionListener(this);
  leftPa.add(tree);
 }

 public void valueChanged(TreeSelectionEvent e)
 {
  JTree tree=(JTree)e.getSource();
  DefaultMutableTreeNode selectiOnNode=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
  String str=selectionNode.toString();
  if(str.equals("查询"))
  {
   initUpDownPaWhenSearch();
  }
  if(str.equals("增加"))
  {
   initUpDownPaWhenAdd();
  }
  if(str.equals("删除"))
  {
   initUpDownPaWhenDelete();
  }
  if(str.equals("修改"))
  {
   initUpDownPaWhenAlert();
  }
 }

 private void initUpDownPaWhenSearch()
 {
  //清空上下面板上的控件
  upPa.removeAll();
  downPa.removeAll();
  //动态的加载上面板的控件
  upPa.setLayout(null);
  numLa=new JLabel();
  numLa.setText("请输入项目编号");
  numLa.setLocation(40, 60);
  numLa.setSize(100, 40);


  numTxt=new JTextField();
  numTxt.setLocation(180, 60);
  numTxt.setSize(200, 30);


  numBt=new JButton();
  numBt.setText("查询");
  numBt.addActionListener(this);
  numBt.setLocation(250, 160);
  numBt.setSize(60, 30);
  upPa.add(numLa);
  upPa.add(numTxt);
  upPa.add(numBt);
  upPa.validate();
  upPa.repaint();
  numBt.addActionListener(this);
  //动态的加载下面板的控件

  nameTxt=new JTextField();
  nameTxt.setLocation(80, 50);
  nameTxt.setSize(300, 30);

  peopleTxt=new JTextField();
  peopleTxt.setLocation(80, 100);
  peopleTxt.setSize(300, 30);

  principalTxt=new JTextField();
  principalTxt.setLocation(80, 150);
  principalTxt.setSize(300, 30);

  timeStartTxt=new JTextField();
  timeStartTxt.setLocation(80, 200);
  timeStartTxt.setSize(300, 30);

  timeEndTxt=new JTextField();
  timeEndTxt.setLocation(80,250);
  timeEndTxt.setSize(300, 30);

  downPa.setLayout(null);
  downPa.add(nameTxt);
  downPa.add(peopleTxt);
  downPa.add(principalTxt);
  downPa.add(timeStartTxt);
  downPa.add(timeEndTxt);
  downPa.validate();
  downPa.repaint();

 }

 public void actionPerformed(ActionEvent e)
 {
  JButton bt=(JButton)e.getSource();
  //bt.addActionListener(this);
  if(bt.getText().equals("查询"))
  {
   if(numTxt.getText().equals(""))
   {
    JOptionPane.showMessageDialog(null, "请输入项目编号");
   }
   else
   {
    DealSearch deal=new DealSearch();
    String inf=deal.findProByNum(Integer.parseInt(numTxt.getText().trim()));
    if((inf!=null)&&(!inf.equals("")))
    {
     String[] strs=inf.split(",");
     nameTxt.setText(strs[1]);
     peopleTxt.setText(strs[2]);
     principalTxt.setText(strs[3]);
     timeStartTxt.setText(strs[4]);
     timeEndTxt.setText(strs[5]);
    }
   }
  }
  if(bt.getText().equals("新增"))
  {
   if (anumTxt.getText().equals("")||anameTxt.getText().equals("")||apeopleTxt.getText().equals("")||aprincipalTxt.getText().equals("")||atimeStartTxt.getText().equals("")||atimeEndTxt.getText().equals(""))
   {
    JOptionPane.showMessageDialog(null, "输入中不能有空值!!");
   }
   else
   {
    ScienceProject s=new ScienceProject();
    s.SetNum(Integer.parseInt(anumTxt.getText()));
    s.SetName(anameTxt.getText());
    s.SetPeople(apeopleTxt.getText());
    s.SetLeader(aprincipalTxt.getText());
    s.SetTimeStart(atimeStartTxt.getText());
    s.SetTimeFinish(atimeEndTxt.getText());
    DealAdd deal=new DealAdd();
    deal.add(s);
   }
  }
  if(bt.getText().equals("删除"))
  {
   if(Integer.parseInt(dnumTxt.getText())==0)
   {
    JOptionPane.showMessageDialog(null, "不能删除空的项目编号!!");
   }
   else
   {
    DealDelete deal=new DealDelete();
    deal.delete(Integer.parseInt(dnumTxt.getText().trim()));
   }
  }
  if(bt.getText().equals("提交"))
  {
   if(Integer.parseInt(allnumTxt.getText())==0)
   {
    JOptionPane.showMessageDialog(null, "不能修改空的项目编号!!");
   }
   else
   {
    DealSub deal=new DealSub();
    deal.submit(Integer.parseInt(allnumTxt.getText()));
   }
  }
  if(bt.getText().equals("修改"))
  {
   if (alnameTxt.getText().equals("")||alpeopleTxt.getText().equals("")||alprincipalTxt.getText().equals("")||altimeStartTxt.getText().equals("")||altimeEndTxt.getText().equals(""))
   {
    JOptionPane.showMessageDialog(null, "输入中不能有空值!!");
   }
   else
   {
    ScienceProject s=new ScienceProject();
    s.SetNum(Integer.parseInt(allnumTxt.getText()));

    s.SetName(alnameTxt.getText());
    s.SetPeople(alpeopleTxt.getText());
    s.SetLeader(alprincipalTxt.getText());
    s.SetTimeStart(altimeStartTxt.getText());
    s.SetTimeFinish(altimeEndTxt.getText());
    DealAlter deal=new DealAlter();
    deal.alter(s);
   }
  }
 }

 private void initUpDownPaWhenAdd()
 {
  //清空上下面板上的控件
  upPa.removeAll();
  downPa.removeAll();
  //动态的加载上面板的控件
  upPa.setLayout(null);

  anumLa=new JLabel();
  anumLa.setText("请输入要增加的项目编号");
  anumLa.setLocation(30, 50);
  anumLa.setSize(150, 40);

  anumTxt=new JTextField();
  anumTxt.setLocation(200, 50);
  anumTxt.setSize(250, 30);

  anameLa=new JLabel();
  anameLa.setText("请输入要增加的项目名称");
  anameLa.setLocation(30, 100);
  anameLa.setSize(150, 40);

  anameTxt=new JTextField();
  anameTxt.setLocation(200, 100);
  anameTxt.setSize(250, 30);

  apeopleLa=new JLabel();
  apeopleLa.setText("请输入项目参与人员");
  apeopleLa.setLocation(30, 150);
  apeopleLa.setSize(150, 40);

  apeopleTxt=new JTextField();
  apeopleTxt.setLocation(200, 150);
  apeopleTxt.setSize(250, 30);

  aprincipalLa=new JLabel();
  aprincipalLa.setText("请输入项目负责人");
  aprincipalLa.setLocation(30, 200);
  aprincipalLa.setSize(150, 40);

  aprincipalTxt=new JTextField();
  aprincipalTxt.setLocation(200, 200);
  aprincipalTxt.setSize(250, 30);

  atimeStartLa=new JLabel();
  atimeStartLa.setText("请输入项目开始时间");
  atimeStartLa.setLocation(30, 250);
  atimeStartLa.setSize(150, 40);

  atimeStartTxt=new JTextField();
  atimeStartTxt.setLocation(200, 250);
  atimeStartTxt.setSize(250, 30);

  atimeEndLa=new JLabel();
  atimeEndLa.setText("请输入项目结束时间");
  atimeEndLa.setLocation(30, 300);
  atimeEndLa.setSize(150, 40);

  atimeEndTxt=new JTextField();
  atimeEndTxt.setLocation(200, 300);
  atimeEndTxt.setSize(250, 30);

  addBt=new JButton();
  addBt.setText("新增");
  addBt.addActionListener(this);
  //addBt.addMouseListener(this);
  addBt.setLocation(250, 340);
  addBt.setSize(60, 30);

  upPa.add(addBt);
  upPa.add(anumLa);
  upPa.add(anameLa);
  upPa.add(apeopleLa);
  upPa.add(aprincipalLa);
  upPa.add(atimeStartLa);
  upPa.add(atimeEndLa);
  upPa.add(anameTxt);
  upPa.add(anumTxt);
  upPa.add(apeopleTxt);
  upPa.add(aprincipalTxt);
  upPa.add(atimeStartTxt);
  upPa.add(atimeEndTxt);
  upPa.validate();
  upPa.repaint();

  downPa.validate();
  downPa.repaint();
 }

 private void initUpDownPaWhenDelete()
 {
  //清空上下面板上的控件
  upPa.removeAll();
  downPa.removeAll();
  //动态的加载上面板的控件
  upPa.setLayout(null);
  numLa=new JLabel();
  numLa.setText("请输入要删除的项目编号");
  numLa.setLocation(40, 60);
  numLa.setSize(150, 40);

  dnumTxt=new JTextField();
  dnumTxt.setLocation(200, 60);
  dnumTxt.setSize(250, 30);

  dnumBt=new JButton();
  dnumBt.setText("删除");
  dnumBt.addActionListener(this);
  dnumBt.setLocation(270, 170);
  dnumBt.setSize(60, 30);

  upPa.add(numLa);
  upPa.add(dnumTxt);
  upPa.add(dnumBt);
  upPa.validate();
  upPa.repaint();

  downPa.validate();
  downPa.repaint();
 }

 private void initUpDownPaWhenAlert()
 {
  //清空上下面板上的控件
  upPa.removeAll();
  downPa.removeAll();
  //动态的加载上面板的控件
  upPa.setLayout(null);
  alnumLa=new JLabel();
  alnumLa.setText("请输入要修改的项目编号");
  alnumLa.setLocation(40, 60);
  alnumLa.setSize(150, 40);

  alseBt=new JButton();
  alseBt.setText("提交");
  alseBt.addActionListener(this);
  alseBt.setLocation(270, 170);
  alseBt.setSize(60, 30);

  allnumTxt=new JTextField();
  allnumTxt.setLocation(200, 60);
  allnumTxt.setSize(200, 30);

  upPa.add(alnumLa);
  upPa.add(alseBt);
  upPa.add(allnumTxt);
  upPa.validate();
  upPa.repaint();

  alBt=new JButton();
  alBt.setText("修改");
  alBt.addActionListener(this);
  alBt.setLocation(450, 170);
  alBt.setSize(60, 30);

 /*  allnumLa=new JLabel();
  allnumLa.setText("请输入修改后的项目编号");
  allnumLa.setLocation(30, 00);
  allnumLa.setSize(150, 40);

  alnumTxt=new JTextField();
  alnumTxt.setLocation(180, 00);
  alnumTxt.setSize(250, 30);*/

  alnameLa=new JLabel();
  alnameLa.setText("请输入修改后项目名称");
  alnameLa.setLocation(30, 50);
  alnameLa.setSize(150, 40);

  alnameTxt=new JTextField();
  alnameTxt.setLocation(180, 50);
  alnameTxt.setSize(250, 30);

  alpeopleLa=new JLabel();
  alpeopleLa.setText("请重设参与人员");
  alpeopleLa.setLocation(30, 100);
  alpeopleLa.setSize(150, 40);

  alpeopleTxt=new JTextField();
  alpeopleTxt.setLocation(180, 100);
  alpeopleTxt.setSize(250, 30);

  alprincipalLa=new JLabel();
  alprincipalLa.setText("请重设项目负责人");
  alprincipalLa.setLocation(30, 150);
  alprincipalLa.setSize(150, 40);

  alprincipalTxt=new JTextField();
  alprincipalTxt.setLocation(180, 150);
  alprincipalTxt.setSize(250, 30);

  altimeStartLa=new JLabel();
  altimeStartLa.setText("请重设项目开始时间");
  altimeStartLa.setLocation(30, 200);
  altimeStartLa.setSize(150, 40);

  altimeStartTxt=new JTextField();
  altimeStartTxt.setLocation(180, 200);
  altimeStartTxt.setSize(250, 30);

  altimeEndLa=new JLabel();
  altimeEndLa.setText("请重设项目结束时间");
  altimeEndLa.setLocation(30, 250);
  altimeEndLa.setSize(150, 40);

  altimeEndTxt=new JTextField();
  altimeEndTxt.setLocation(180, 250);
  altimeEndTxt.setSize(250, 30);
  downPa.add(alBt);
  //downPa.add(allnumLa);
  downPa.add(alnameLa);
  downPa.add(alpeopleLa);
  downPa.add(alprincipalLa);
  downPa.add(altimeStartLa);
  downPa.add(altimeEndLa);
  downPa.add(alnameTxt);
  //downPa.add(alnumTxt);
  downPa.add(alpeopleTxt);
  downPa.add(alprincipalTxt);
  downPa.add(altimeStartTxt);
  downPa.add(altimeEndTxt);
  downPa.setLayout(null);
  downPa.validate();
  downPa.repaint();
 }
}

3.3 组织SQL语句,链接数据库部分

package 科研信息管理系统;
import java.sql.*;
import java.util.Scanner;

public class Sql {
 public void AddScienceProject(ScienceProject scienceProject)
 {
  try
  {
   Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
   String cOnStr="jdbc:oracle:thin:@localhost:1521:XE";
   Connection con=DriverManager.getConnection(conStr,"system","1");
   StringBuffer sql=new StringBuffer("insert into science values("+scienceProject.GetNum()+",'"+scienceProject.GetName()+"','"+scienceProject.GetPeople()+"','"+scienceProject.GetLeader()+"','"+scienceProject.GetTimeStart()+"','"+scienceProject.GetTimeFinish()+"')");

   Statement st=con.createStatement();
   st.execute(sql.toString());
   st.close();
   con.close(); 
  } 
  catch (Exception e) 
  {
  // TODO: handle exception

  System.out.println(e.toString());
  }
 }
 public void DelScienceProject(ScienceProject scienceProject)
 {
  try 
  {
  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
  String cOnStr="jdbc:oracle:thin:@localhost:1521:XE";
  Connection con=DriverManager.getConnection(conStr,"system","1");
  StringBuffer sql=new StringBuffer("delete from science where num="+scienceProject.GetNum()+""); 
  Statement st=con.createStatement();
  st.execute(sql.toString());
  st.close();
  con.close();
  } 
  catch (Exception e) 
  {
  // TODO: handle exception
  System.out.println(e.toString());
  }

 }
 public void UpdScienceProject(ScienceProject scienceProject)
 {
  try 
  {
  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
  String cOnStr="jdbc:oracle:thin:@localhost:1521:XE";
  Connection con=DriverManager.getConnection(conStr,"system","1");
  StringBuffer sql =new StringBuffer("update science set name='"+scienceProject.GetName()+"',workpeople='"+scienceProject.GetPeople()+"',manager='"+scienceProject.GetLeader()+"',timestart='"+scienceProject.GetTimeStart()+"',timeend='"+scienceProject.GetTimeFinish()+"' where num="+scienceProject.GetNum()+"");
  Statement st=con.createStatement();
  st.execute(sql.toString());
  st.close();
  con.close();
  }
  catch (Exception e) 
  {
  // TODO: handle exception
   System.out.println("修改异常");
  System.out.println(e.toString());
  }
 }
 public ScienceProject Findbynum(int num)
 {
  ScienceProject scienceProject=new ScienceProject();
  try 
  {
   Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
   String cOnStr="jdbc:oracle:thin:@localhost:1521:XE";
   Connection con=DriverManager.getConnection(conStr,"system","1");
   StringBuffer sql=new StringBuffer("select * from science where num="+num+"");
   Statement st=con.createStatement();
   ResultSet rs=st.executeQuery(sql.toString());
   while(rs.next())
   {
    scienceProject.SetNum(rs.getInt(1));
    scienceProject.SetName(rs.getString(2));
    scienceProject.SetPeople(rs.getString(3));
    scienceProject.SetLeader(rs.getString(4));
    scienceProject.SetTimeStart(rs.getString(5));
    scienceProject.SetTimeFinish(rs.getString(6));
   }
   st.close();
   con.close();
  } 
  catch (Exception e) {
  // TODO: handle exception
  System.out.println(e.toString());
  }
 return scienceProject; 
 }
 public ScienceProject Look()
 {
  ScienceProject scienceProject=new ScienceProject();
  try
   {
   Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
   String cOnStr="jdbc:oracle:thin:@localhost:1521:XE";
   Connection con=DriverManager.getConnection(conStr,"system","1");
   StringBuffer sql=new StringBuffer("select *from science");
   Statement st=con.createStatement();
   ResultSet rs=st.executeQuery(sql.toString());
   while(rs.next())
   { 
    scienceProject.SetNum(rs.getInt(1));
    scienceProject.SetName(rs.getString(2));
    scienceProject.SetPeople(rs.getString(3));
    scienceProject.SetLeader(rs.getString(4));
    scienceProject.SetTimeStart(rs.getString(5));
    scienceProject.SetTimeFinish(rs.getString(6));
   }
   st.close();
   con.close();
 } 
  catch (Exception ex) 
  {
  // TODO: handle exception
  System.out.println(ex.toString());
  }
 return scienceProject;
 }
 public static void main(String args[])
 {

 }
}

3.4 增删查改对应处理的源码

//处理增加
package 科研信息管理系统;

import javax.swing.JOptionPane;

public class DealAdd 
{
 public DealAdd()
 {}
 public void add(ScienceProject s)
 {
  Sql sql=new Sql();
  if(sql.Findbynum(s.GetNum()).GetNum()!=0)
  {
   JOptionPane.showMessageDialog(null, "该项目已存在,请重新输入!");
  }
  else
  {

   sql.AddScienceProject(s);
   JOptionPane.showMessageDialog(null,"增加成功");
  }
 }
}

由设计部分可以看到,删除时需要先提交项目编号,所以,需要处理提交事件

//处理提交
package 科研信息管理系统;

import javax.swing.JOptionPane;

public class DealSub
{
 DealSub()
 {}
 public void submit(int num)
 {
  Sql sql =new Sql();
  if(sql.Findbynum(num).GetNum()==0)
  {
   JOptionPane.showMessageDialog(null, "不存在该项目");
  }
  else
  {
   JOptionPane.showMessageDialog(null, "请在下方填写修改后的项目信息");
  }
 }
}
//处理删除
package 科研信息管理系统;

import javax.swing.JOptionPane;

public class DealDelete
{
 public DealDelete()
 {}
 public void delete(int num)
 {
  ScienceProject s=new ScienceProject();
  Sql sql=new Sql();
  if(sql.Findbynum(num).GetNum()==0)
  {
   JOptionPane.showMessageDialog(null, "不存在该项目~");
  }
  else
  {
   s=sql.Findbynum(num);
   sql.DelScienceProject(s);
   JOptionPane.showMessageDialog(null, "删除成功~");
  }
 }
}
//处理修改
package 科研信息管理系统;

import javax.swing.JOptionPane;

public class DealAlter 
{
 public DealAlter()
 {}
 public void alter(ScienceProject s)
 {
  Sql sql=new Sql();
  sql.UpdScienceProject(s);
  JOptionPane.showMessageDialog(null,"修改成功");
 }
}
//处理查询
package 科研信息管理系统;

public class DealSearch //处理查询事件
{
 public DealSearch() 
 {}
 public String findProByNum(int num)//通过项目编号查询
 {
  String result="";
  ScienceProject s=new ScienceProject();
  Sql sql=new Sql();
  s=sql.Findbynum(num);
  result=s.GetNum()+","+s.GetName()+","+s.GetPeople()+","+s.GetLeader()+","+s.GetTimeStart()+","+s.GetTimeFinish();
  return result;
 }
}


3.5 主函数调用登录窗口

package 科研信息管理系统;

public class Test {

 public static void main(String[] args)
 {
  LoginWindows v=new LoginWindows();

 }

}

四、总结

还是有一些的缺陷存在的,由于对科研项目的不熟悉,有些属性设计得不合理,还有很多没有考虑到的地方,另外对GUI的不熟悉也限制了我们在窗口上的设计。还需要在项目属性及窗口等方面进行修改。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
  • 项目运行环境配置及可行性分析
    本文介绍了项目运行环境配置的要求,包括Jdk1.8、Tomcat7.0、Mysql、HBuilderX等工具的使用。同时对项目的技术可行性、操作可行性、经济可行性、时间可行性和法律可行性进行了分析。通过对数据库的设计和功能模块的设计,确保系统的完整性和安全性。在系统登录、系统功能模块、管理员功能模块等方面进行了详细的介绍和展示。最后提供了JAVA毕设帮助、指导、源码分享和调试部署的服务。 ... [详细]
  • 本文介绍了adg架构设置在企业数据治理中的应用。随着信息技术的发展,企业IT系统的快速发展使得数据成为企业业务增长的新动力,但同时也带来了数据冗余、数据难发现、效率低下、资源消耗等问题。本文讨论了企业面临的几类尖锐问题,并提出了解决方案,包括确保库表结构与系统测试版本一致、避免数据冗余、快速定位问题等。此外,本文还探讨了adg架构在大版本升级、上云服务和微服务治理方面的应用。通过本文的介绍,读者可以了解到adg架构设置的重要性及其在企业数据治理中的应用。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • MyBatis错题分析解析及注意事项
    本文对MyBatis的错题进行了分析和解析,同时介绍了使用MyBatis时需要注意的一些事项,如resultMap的使用、SqlSession和SqlSessionFactory的获取方式、动态SQL中的else元素和when元素的使用、resource属性和url属性的配置方式、typeAliases的使用方法等。同时还指出了在属性名与查询字段名不一致时需要使用resultMap进行结果映射,而不能使用resultType。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • 本文讨论了在数据库打开和关闭状态下,重新命名或移动数据文件和日志文件的情况。针对性能和维护原因,需要将数据库文件移动到不同的磁盘上或重新分配到新的磁盘上的情况,以及在操作系统级别移动或重命名数据文件但未在数据库层进行重命名导致报错的情况。通过三个方面进行讨论。 ... [详细]
  • 如何实现JDK版本的切换功能,解决开发环境冲突问题
    本文介绍了在开发过程中遇到JDK版本冲突的情况,以及如何通过修改环境变量实现JDK版本的切换功能,解决开发环境冲突的问题。通过合理的切换环境,可以更好地进行项目开发。同时,提醒读者注意不仅限于1.7和1.8版本的转换,还要适应不同项目和个人开发习惯的需求。 ... [详细]
  • 模块化区块链生态系统的优势概述及其应用案例
    本文介绍了相较于单体区块链,模块化区块链生态系统的优势,并以Celestia、Dymension和Fuel等模块化区块链项目为例,探讨了它们解决可扩展性和部署问题的方案。模块化区块链架构提高了区块链的可扩展性和吞吐量,并提供了跨链互操作性和主权可扩展性。开发人员可以根据需要选择执行环境,并获得奖学金支持。该文对模块化区块链的应用案例进行了介绍,展示了其在区块链领域的潜力和前景。 ... [详细]
  • 本文介绍了在Ubuntu 11.10 x64环境下安装Android开发环境的步骤,并提供了解决常见问题的方法。其中包括安装Eclipse的ADT插件、解决缺少GEF插件的问题以及解决无法找到'userdata.img'文件的问题。此外,还提供了相关插件和系统镜像的下载链接。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 本文介绍了通过mysql命令查看mysql的安装路径的方法,提供了相应的sql语句,并希望对读者有参考价值。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
author-avatar
沉睡森林
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有