1。序文
私は今学期にJava言語を学びました。学期の終わりに、私は操作インターフェイスを備えた管理システムを書き、データベースに関連付けて、この研究で学んだ知識を統合しました。
使用されている知識:Java Basics、Java Interface Design(GUI)、Oracle Database(データベースの基本操作ステートメントをマスターする必要があります)、およびリンクデータベース。
使用される開発ツール:Myeclipse Professional 2014
2。デザイン
私たちが管理する属性は、プロジェクト番号、プロジェクト名、参加者、担当者、プロジェクトの開始時間、および終了時間です。科学研究プロジェクトシステムには、科学研究プロジェクトの追加、削除、修正、および質問の4つの主要な機能があります。システムセキュリティを増やすために設計されたログインモード。
2.1追加:科学研究プロジェクトに関するすべての情報をデータベースのテーブルに追加する
追加した後、SQLステートメントを使用してコンソールで検索して、データベースに追加されたことを確認します。
2.2クエリ:一意のプロジェクト番号でプロジェクトに関するすべての情報を見つける
2.3変更:プロジェクト番号に従って変更するプロジェクトを選択し、プロジェクト情報を再入力して変更します
2.4削除:一意のプロジェクト番号を使用して、対応するプロジェクトのすべての情報を削除する
3.フォームソースコード
3.1ログインインターフェイス
パッケージ科学研究情報管理システム;インポートjava.awt。*;インポートjava.awt.event。*; import javax.swing。 //ユーザー名タグpublicラベルpwdlabel; //パスワードタグpublic textfield lgtext; //ユーザー名テキストボックスパブリックテキストフィールドpwdtext; //パスワードテキストボックスパブリックボタンLGBT; //ログインボタンパブリックボタンQuitbt; // [exit button 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( "password:"); 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( "login"); lgbt.setsize(60、30); lgbt.setlocation(120、220); quitbt = new button(); quitbt.setlabel( "exit"); 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(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( "exit")){system.exit(0); } else {if((lgtext.getText()。equals( ""))||(pwdtext.getText()。equals( ""))){joptionpane.showmessageialog(this、 "account or password is veatt"); } else {if((lgtext.getText()。equals( "admin"))&&(pwdtext.getText()。equals( "111")))//if( lgtext.getText()。 // sqlwindow sql = new sqlwindow(); WindowsView w = new WindowsView(); w.sciencepro(); } else {joptionpane.showmessagedialog(これ、「許可なし」); }}}} @Override public void windowpeened(windowevent e){// dodo auto-fide method busb} @override public void windowclosing(windowevent e){// dodo auto-enerated method busb system.exit(0); } @Override public void windowclosed(windowevent e){// todo auto-enerated method busb} @Override public void windowconified(windowevent e){// todo auto-enerated method busb} Windowactivated(windowevent e){// todo auto-fideated method busb} @override public void windowdeactivated(windowevent e){// todo auto-feenated method busb}}}3.2メインフォームソースコード
パッケージ科学研究情報管理システム。 javax.swing。*;インポートjava.awt。*;インポートjava.awt.event。*; import javax.swing.event。 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; Jlabel Allnumla; 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); uppa.setbackground(color.gray); main.add(uppa); downpa = new JPanel(); downpa.setsize(650、400);ダウンパ。セットロケーション(150、400);ダウンパ。セットバックグラウンド(Color.Orange); main.add(downpa); main.setVisible(true); } private void initleftpanel(){string [] strs = {"query"、 "add"、 "delete"、 "modify"}; 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( "query")){initupdownpawhensearch(); } if(str.equals( "add")){initupdownpawhenadd(); } if(str.equals( "delete")){initupdownpawhendelete(); } if(str.equals( "Modify")){initupdownPawhenalert(); }} private void initupdownpawhensearch(){// clear 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( "query"); 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(これ); if(bt.getText()。equals( "query")){if(numtxt.getText()。equals( "")){joptionpane.showmessageialog(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( "new")){if (anumtxt.getText()。equals( "")|| anametxt.getText()。equals( "")|| apeopletxt.getText() cipaltxt.getText()。equals( "")|| atimestarttxt.getText()。equals( "")|| atimeendtxt.getText()。 {joptionpane.showmessagedialog(null、 "入力にnull値はありません!!"); } else {scienceProject s = new ScienceProject(); s.setnum(integer.parseint(anumtxt.getText())); S.SetName(nametxt.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( "delete")){if(integer.parseint(dnumtxt.getText())== 0){joptionpane.showmessagealog(null、 "空のアイテム番号を削除できません!!"); } else {dealdelete deal = new dealdelete(); deal.delete(integer.parseint(dnumtxt.getText()。trim())); }} if(bt.getText()。equals( "submit")){if(integer.parseint(allnumtxt.getText())== 0){joptionpane.showMessageAlog(null、 "空のプロジェクト番号は変更できません!!"); } else {dealsub deal = new dealsub(); deal.submit(integer.parseint(allnumtxt.getText())); }} if(bt.getText()。equals( "Modify")){if (alnametxt.getText()。equals( "")|| alpeopletxt.getText()。equals( "")|| alprincipaltxt.getText()。 joptionpane.showmessagedialog(null、 "入力に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(){// clear 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( "new"); addbt.AddActionListener(this); //addbt.addmouseListener(this); addbt.setlocation(250、340); addbt.setsize(60、30); uppa.add(addbt); uppa.add(anumla); uppa.add(namela); uppa.add(apeoplela); uppa.add(aprincipalla); uppa.add(atimestartla); uppa.add(atimeendla); uppa.add(atimetxt); uppa.add(anumtxt); uppa.add(apeopletxt); uppa.add(aprincipaltxt); uppa.add(atimestarttxt); uppa.add(atimeendtxt); uppa.validate(); uppa.repaint(); downpa.validate(); downpa.repaint(); downpa.repaint(); } private void initupdownpawhendelete(){// clear 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( "delete"); 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(){//上下のパネルのclear 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( "submit"); 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( "Modify"); 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(altimetxt); //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ステートメントを整理し、データベースパーツをリンクします
パッケージ科学研究情報管理システム。 import java.sql。*; Import java.util.scanner; public class sql {public void addScienceProject(ScienceProjectScienceProject){try {class.forname( "oracle.jdbc.driver.oracledriver")。newinstance();文字列const = "jdbc:oracle:thin:@localhost:1521:xe";接続con = drivermanager.getConnection(connt、 "system"、 "1"); stringbuffer sql = new StringBuffer( "科学への挿入values( "+scienceproject.getnum()+"、 '"+scienceproject.getName()+"'、 '"+scienceproject.getPeople()+"'、 ''+scienceproject.getLeader()+"'、'"+scienceproject.getimestart() '' '' '+scienceproject.get.gettimefinish ";";ステートメントst = con.createstatement(); St.Execute(sql.toString()); St.Close(); con.close(); } catch(Exception E){// TODO:例外System.out.println(e.toString()); }} public void delscienceProject(ScienceProject ScienceProject){try {class.forname( "oracle.jdbc.driver.oracledriver")。newInstance();文字列const = "jdbc:oracle:thin:@localhost:1521:xe";接続con = drivermanager.getConnection(connt、 "system"、 "1"); stringbuffer sql = new StringBuffer( "delete from Science Where num ="+scienceproject.getnum()+"");ステートメントst = con.createstatement(); St.Execute(sql.toString()); St.Close(); con.close(); } catch(Exception E){// TODO:例外System.out.println(e.toString()); }} public void updScienceProject(ScienceProject ScienceProject){try {class.forname( "oracle.jdbc.driver.oracledriver")。newInstance();文字列const = "jdbc:oracle:thin:@localhost:1521:xe";接続con = drivermanager.getConnection(connt、 "system"、 "1"); StringBuffer SQL = new StringBuffer( "科学セットを更新しますname = '"+scienceproject.getName()+"'、workpeople = '"+scienceproject.getpeople()+"'、manager = '"+scienceproject.getLeader()+"'、timestart = '" num = "+scienceproject.getnum()+" ");ステートメントst = con.createstatement(); St.Execute(sql.toString()); St.Close(); con.close(); } catch(例外e){// todo:例外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();文字列const = "jdbc:oracle:thin:@localhost:1521:xe";接続con = drivermanager.getConnection(connt、 "system"、 "1"); stringbuffer sql = new StringBuffer( "Select * from Science Where num ="+num+"");ステートメントst = con.createstatement(); resultet 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:例外System.out.println(e.toString()); } scienceProjectを返します。 } public ScienceProject Look(){ScienceProject ScienceProject = new ScienceProject(); try {class.forname( "oracle.jdbc.driver.oracledriver")。newInstance();文字列const = "jdbc:oracle:thin:@localhost:1521:xe";接続con = drivermanager.getConnection(connt、 "system"、 "1"); stringbuffer sql = new StringBuffer( "Select *From Science");ステートメントst = con.createstatement(); resultet 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:例外System.out.println(ex.toString()); } scienceProjectを返します。 } public static void main(string args []){}}3.4対応するソースコードを追加、削除、検索、変更
//パッケージ科学研究情報管理システムの追加のトラブルシューティング。 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.showmessageialog(null、 "このプロジェクトは既に存在します、再入力してください!"); } else {sql.addscienceproject(s); joptionpane.ShowMessageDialog(null、 "addsuccess"); }}}設計部分からわかるように、プロジェクト番号を削除するときに最初に送信する必要があるため、提出イベントを処理する必要があります。
//提出パッケージ科学研究情報管理システムの処理。 javax.swing.joptionpane; public class dealsub {dealsub(){} public void submit(int num){sql sql = new sql(); if(sql.findbynum(num).getnum()== 0){joptionpane.showmessageialog(null、 "このプロジェクトは存在しません"); } else {joptionpane.showmessagedialog(null、 "以下の変更されたプロジェクト情報を入力してください"); }}} //削除パッケージの処理科学研究情報管理システム。 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.showmessageialog(null、 "プロジェクトは存在しません〜"); } else {s = sql.findbynum(num); sql.delscienceproject(s); joptionpane.showmessageialog(null、 "delete ressuletly〜"); }}} //パッケージ科学研究情報管理システムを処理および変更します。 javax.swing.joptionpaneをインポートします。 Public Class Dealalter {public dealalter(){} public void alter(scienceproject s){sql sql = new sql(); sql.updscienceProject(s); joptionpane.showmessageialog(null、 "修正"); }} //科学研究情報管理システムのハンドルとクエリのパッケージ。 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();返品結果; }}3.5メイン関数呼び出しログインウィンドウ
パッケージ科学研究情報管理システム。 public class test {public static void main(string [] args){loginWindows v = new loginWindows(); }}4。概要
まだいくつかの欠陥があります。科学研究プロジェクトに不慣れであるため、一部の属性は不合理であり、考慮されていない多くのことがあります。さらに、GUIに不慣れであることは、ウィンドウ上のデザインも制限します。また、プロジェクトのプロパティとウィンドウの観点から変更する必要があります。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。