版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
试验报告课程名称试验名称姓名
Java面对对象程序设计检查危急品吴超益 学号 202324134114 专业年级 14物联网本试验的目的是让学生把握 try-catch语句二、试验内容:车站检查危急品的设施,假设觉察危急品就会发出警示。编写Exception 的子类DangeException Machine类办理异样主类main方法中的try-catch办理machine 类的实例调用三、试验步骤试验源代码:importjava.io.*;import.*;importjava.util.*;publicclassClient{publicstaticvoidmain(Stringagrs[]){Scannerscanner=newScanner(System.in);Socketmysocket=null;ObjectInputStreaminObject=null;ObjectOutputStreamoutObject=null;Threadthread;ReadWindowreadWindow=null;try{mysocket=newSocket;readWindow=newReadWindow;thread=newThread(readWindow);System.out.println(“输入效劳器的IP“);StringIP=scanner.nextLine;System.out.println(“输入端口号:“);intport=scanner.nextInt;if(mysocket.isConnected){}1/43else{
InetAddressaddress=InetAddress.getByName(IP);InetSocketAddresssocketAddress=newInetSocketAddress(address,port);mysocket.connect(socketAddress);InputStreamin=mysocket.getInputStream;OutputStreamout=mysocket.getOutputStream;inObject=newObjectInputStream(in);outObject=newObjectOutputStream(out);readWindow.setObjectInputStream(inObject);thread.start;}}catch(Exceptione){System.out.println(““+e);}}}classReadWindowimplementsRunnable{ObjectInputStreamin;publicvoidsetObjectInputStream(ObjectInputStreamin){this.in=in;}publicvoidrun{doubleresult=0;while(true){try{}
javax.swing.JFramewindow=(javax.swing.JFrame)in.readObject;window.setTitle(“这是从效劳器上读入的窗口“);window.setVisible(true);window.requestFocusInWindow;window.setSize(600,800);catch(Exceptione){System.out.println(““+e);break;2/43}}}}///*Exception当你要抛出的自定义的异样类,确定继承Exception,不然错误catch捕获抛出的异样*/publicclassDangerExceptionextendsException{Stringmessage;publicDangerException{message= }publicvoidtoShow{System.out.print(message+““);}}publicclassGoods{publicbooleanisDanger;Stringname;publicvoidsetIsDanger(booleanboo){isDanger=boo;}publicbooleanisDanger{returnisDanger;}publicvoidsetName(Strings){name=s;}publicStringgetName{returnname;}}3/43/*异样的办理和抛出throws,申明异样的实例throws异样类名exp:throwsDangerExeption申明异样后应当在调用者里面对 捕获的异样办理throw,抛出异样throw异样实例exp:thrownewDangerException假设捕获到申明的异样。直接跳转相应的catch 语句能够申明多个异样类,并用多重catch 语句捕获*/publicclassMachine{publicvoidcheckBag(Goodsgood)throwsDangerException{if(good.isDanger==true){thrownewDangerException;}else{System.out.print(good.getName+“ “);}}}四、试验结果五、总结经过此次试验,熟习了try_catch 语句,对此后学习java打下好的根底,对java能更为熟习4/43试验报告课程名称 Java面对对象程序设计试验名称 比较日期姓名 吴超益 学号 202324134114 专业年级 14物联网一、试验目的:目的是让学生把握 Data类以及Calendar 类的常用方法二、试验内容:java应用程序,用户从输入对话框输入两个日期,程序将推断两个日期的大小关系,以及两个日期之间的间隔天数三、试验步骤试验源代码:package ;importjava.sql.Date;importjava.util.Calendar;importjava.util.Scanner;publicclassCompareDate{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannerscanner=newScanner(System.in);System.out.println(““);System.out.println(““);shortyearOne=scanner.nextShort;System.out.println(“输入月份“);bytemonthOne=scanner.nextByte;System.out.println(“输入日期“);bytedayOne=scanner.nextByte;System.out.println(“输入其次年,月,日数据“);System.out.println(“输入年份“);shortyearTwo=scanner.nextShort;System.out.println(“输入月份“);bytemonthTwo=scanner.nextByte;System.out.println(“输入日期“);bytedayTwo=scanner.nextByte;Calendarcalendar=Calendar.getInstance;5/43calendar.set(yearOne,monthOne-1,dayOne);longtimeOne=calendar.getTimeInMillis;calendar.set(yearTwo,monthTwo-1,dayTwo);longtimeTwo=calendar.getTimeInMillis;Datedate1=newDate(timeOne);Datedate2=newDate(timeTwo);if(date2.equals(date1)){System.out.println(“两个日期的年,月,日完整同样“);}elseif(date2.after(date1)){System.out.println(“您输入的其次个日期大于第一个日期“);}elseif(date2.before(date1)){System.out.println(“您输入其次个日期毛毛雨第一个日期“);}longday=Math.abs(timeTwo-timeOne)/(1000*60*60*24);System.out.println(yearOne+“ “+yearTwo+““+monthTwo+““+dayTwo+“日相隔“+day+““);}}四、试验结果五、总结此次试验熟习了Java 应用程序,并将Data类以及Calendar 类的常用方法把握,对此后学习java打下好的根底,对 java能更为熟习。6/43试验报告课程名称 Java面对对象程序设计试验名称姓名
华容道吴超益学号 202324134114 专业年级 14物联网一、试验目的:学习焦点、鼠标和键盘大事二、试验内容:GUI程序,用户经过键盘和鼠标大事来实现曹操、关羽等人物的挪动。三、试验步骤试验源代码:package 华容道;importjava.awt.*;importjava.awt.event.*;publicclasshuanrongdao{publicstaticvoidmain(Stringargs[]){newHua_Rong_Road;}}classPersonextendsButtonimplementsFocusListener{intnumber;Colorc=newColor(255,245,170);publicPerson(finalintnumber,finalStrings){super(s);setBackground(c);this.number=number;c=getBackground;addFocusListener(this);7/43}publicvoidfocusGained(finalFocusEvente){setBackground(Color.red);}publicvoidfocusLost(finalFocusEvente){setBackground(c);}}classHua_Rong_RoadextendsFrameimplements MouseListener,KeyListener,ActionListener{Personperson[]=newPerson[10];Buttonleft,right,above,below;Buttonrestart=newButton(“ “);publicHua_Rong_Road{init;setBounds(100,100,320,360);setVisible(true);validate;addWindowListener(newWindowAdapter{publicvoidwindowClosing(WindowEvente){System.out.println(0);}});}publicvoidinit{setLayout(null);add(restart);restart.setBounds(100,320,120,25);restart.addActionListener(this);Stringname[]={““,““,““,““,““};for(intk=0;k<name.length;k++){person[k]=newPerson(k,name[k]);person[k].addMouseListener(this);person[k].addKeyListener(this);add(person[k]);}person[0].setBounds(104,54,100,100);person[1].setBounds(104,154,100,50);person[2].setBounds(54,154,50,100);8/43person[3].setBounds(204,154,50,100);person[4].setBounds(54,54,50,100);person[5].setBounds(204,54,50,100);person[6].setBounds(54,254,50,50);person[7].setBounds(204,254,50,50);person[8].setBounds(104,204,50,50);person[9].setBounds(154,204,50,50);person[9].requestFocus;left=newButton;right=newButton;above=newButton;below=newButton;add(left);add(right);add(above);add(below);left.setBounds(49,49,5,260);right.setBounds(254,49,5,260);above.setBounds(49,49,210,5);below.setBounds(49,304,210,5);validate;}publicvoidkeyTyped(KeyEvente){}publicvoidKeyReleased(KeyEvente){}publicvoidKeyPressed(KeyEvente){Personman=(Person)e.getSource;if(e.getKeyCode==KeyEvent.VK_DOWN){go(man,below);}if(e.getKeyCode==KeyEvent.VK_UP){go(man,above);}if(e.getKeyCode==KeyEvent.VK_LEFT){go(man,left);}if(e.getKeyCode==KeyEvent.VK_RIGHT){go(man,right);}}publicvoidmousePressed(MouseEvente){Personman=(Person)e.getSource;intx=-1,y=-1;x=e.getX;9/43y=e.getY;intw=man.getBounds.width;inth=man.getBounds.height;if(y>h/2){go(man,below);}if(y<h/2){go(man,above);}if(x<w/2){go(man,left);}if(x>w/2){go(man,right);}}publicvoidmouseReleased(MouseEvente){}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseClicked(MouseEvente){}publicvoidgo(Personman,Buttondirection){booleanmove=true;RectanglemanRect=man.getBounds;intx=man.getBounds.x;inty=man.getBounds.y;if(direction==below)y=y+50;elseif(direction==above)y=y-50;elseif(direction==left)x=x-50;elseif(direction==right)x=x+50;manRect.setLocation(x,y);RectangledirectionRect=direction.getBounds;for(intk=0;k<10;k++){RectanglepersonRect=person[k].getBounds;if((manRersects(personRect))&&(man.number!=k))10/43{move=false;}}if(manRersects(directionRect)){move=false;}if(move==true){man.setLocation(x,y);}}publicvoidactionPerformed(ActionEvente){dispose;newHua_Rong_Road;}publicvoidkeyPressed(KeyEventarg0){}publicvoidkeyReleased(KeyEventarg0){}}四、试验结果11/43五、总结此次试验让我生疏了焦点、鼠标和键盘大事,此后学习java 打下好的根底,对java 能更为熟习12/43试验报告课程名称 Java面对对象程序设计试验名称 汉字输入练习姓名 吴超益 学号 202324134114 专业年级 14物联网一、试验目的:把握Thread 的子类创立线程二、试验内容:java应用程序,在主线程序中再创立两个线程,第一个负责给出某个汉字,其次个线程负责让用户在命令行输入第一线程给出的汉字import
三、试验步骤试验源代码:java.util.Scanner;public
class
TepyChinese{public
static
main(String args[]){System.out.println(System.out.println(Chinesehanzi;hanzi =newChinese;GiveChineseThreadInputChineseThread
“输入汉字练习〔输入 #完毕程序〕“);“输入显示的汉字〔回车〕“);giveHanzi ;typeHanzi ;giveHanzigiveHanzigiveHanzitypeHanzi
=newGiveChineseThread;.setChinese( hanzi );.setSleepLength(6000);=newInputChineseThread;typeHanzigiveHanzi
.setChinese(.start;
hanzi );try}
{Thread.
sleep (200);catch typeHanzi
exp){.start;}}}class Chinese{charpublic
c=”\0”void
;setChinese( char c){13/43this .c=c;}public char getChinese{return c;}}class GiveChineseThread extends Thread{Chinesechar
hanzi startChar
=(char )22909,
endChar =(char )(startChar +100);intpublic
sleepLengthvoid
=5000;setChinese(Chinese hanzi ){this .hanzi =hanzi ;}public void setSleepLength( int n){sleepLength}
=n;publicchar
void run{c=startChar ;while (true ){hanzi .setChinese(System. out.printf(try {
c);“显示的汉字:%c\n“ ,hanzi .getChinese);Thread. sleep (sleepLength );}catch c=(char )(c+1);if (c>endChar )
e){}c=startChar ;}}}class InputChineseThread extends Thread{ScannerChinese
reader ;hanzi ;int score =0;InputChineseThread{reader =newScanner(System.
in);}public
void setChinese(Chinese hanzi ){this .hanzi =hanzi ;}publicwhile
void run{( true ){14/43Stringchar
str=reader c=str.charAt(0);if (c==hanzi score ++;System. out .printf( “\t\t 输入对了,当前分数%d\n“ ,score );}elseSystem. out .printf( “\t\t 输入错了,当前分数%d\n“ ,score );if (c==”#” )System. exit (0);}}}四、试验结果五、总结此次试验熟习了Java 应用程序,并将Thread 的子类的常用方法把握,对此后学习java打下好的根底,对 java能更为熟习。15/43试验报告课程名称 Java面对对象程序设计试验名称 读取效劳器端文件姓名 吴超益 学号 202324134114 专业年级 14物联网一、试验目的:学习使用URL二、试验内容:URLURLURL所包括的资源文件三、试验步骤试验源代码:packageone;importjava.awt.BorderLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.io.IOException;importjava.io.InputStream;import.MalformedURLException;import.URL;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextArea;importjavax.swing.JTextField;publicclassReadURLSource{publicstaticvoidmain(String[]args){newNetWin;}}classNetWinextendsJFrameimplementsActionListener,Runnable{JButtonbutton;URLurl;JTextFieldinputURLText;JTextAreaarea;16/43byteb[]=newbyte[118];Threadthread;publicNetWin{//TODOAuto-generatedconstructorstubinputURLText=newJTextField(20);area=newJTextArea(12,12);button=newJButton(“ button.addActionListener(this);thread=newThread(this);JPanelp=newJPanel;p.add(newJLabel(“ 请输入网址:“));p.add(inputURLText);p.add(button);add(area,BorderLayout.CENTER);add(p,BorderLayout.NORTH);setBounds(60,60,560,300);setVisible(true);validate;setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoidactionPerformed(ActionEvente){if(!(thread.isAlive)){thread=newThread(this);}try{thread.start;}catch(Exceptionee){inputURLText.setText(“ 我正在读取“+url);}}publicvoidrun{try{intn=-1;area.setText(null);Stringname=inputURLText.getText.trim;url=newURL(name);StringhostName=url.getHost;inturlPortNumber=url.getPort;StringfileName=url.getFile;InputStreamin=url.openStream;area.append(“\n 主机:“+hostName+“ 端口:“+urlPortNumber+“ 包括的文件名17/43字:“+fileName);area.append(“\n 文件的内容以下:“);while((n=in.read(b))!=-1){Strings=newString(b,0,n);area.append(s);}}catch(MalformedURLExceptione1){inputURLText.setText(““+e1);return;}catch(IOExceptione1){inputURLText.setText(““+e1);return;}}}四、试验结果五、总结学习使用URL,此后学习java打下好的根底,对 java能更为熟习18/43试验报告课程名称 Java面对对象程序设计试验名称 读取效劳器端的窗口姓名 吴超益 学号 202324134114 专业年级 14物联网一、试验目的:学会使用套接字读取效劳器端的对象二、试验内容:客服端利用套接字连结将效劳器端的JFram 对象读取到客服端。第一将效劳器端的程序编译经过,并运转起来,等候恳求套接字连结三、试验步骤试验源代码://Client.javapackageclient;importjava.io.*;import.*;importjava.util.*;publicclassClient{publicstaticvoidmain(Stringagrs[]){Scannerscanner=newScanner(System.in);Socketmysocket=null;ObjectInputStreaminObject=null;ObjectOutputStreamoutObject=null;Threadthread;ReadWindowreadWindow=null;try{mysocket=newSocket;readWindow=newReadWindow;thread=newThread(readWindow);System.out.println(“StringIP=scanner.nextLine;输入效劳器的IP“);System.out.println(“intport=scanner.nextInt;输入端口号:“);if(mysocket.isConnected){19/43}else{
InetAddressaddress=InetAddress.getByName(IP);InetSocketAddresssocketAddress=newInetSocketAddress(address,port);mysocket.connect(socketAddress);InputStreamin=mysocket.getInputStream;OutputStreamout=mysocket.getOutputStream;inObject=newObjectInputStream(in);outObject=newObjectOutputStream(out);readWindow.setObjectInputStream(inObject);thread.start;}}catch(Exceptione){System.out.println(“}}
效劳器已经断开“+e);}classReadWindowimplementsRunnable{ObjectInputStreamin;publicvoidsetObjectInputStream(ObjectInputStreamin){this.in=in;}publicvoidrun{doubleresult=0;while(true){try{window=(javax.swing.JFrame)in.readObject;window.setTitle(“window.setVisible(true);
这是从效劳器上读入的窗口 “);window.requestFocusInWindow;window.setSize(600,800);}catch(Exceptione)20/43{System.out.println(“ 效劳器已经断开“+e);break;}}}}// Server.javapackage client;importjava.io.*;import.*;importjava.util.*;importjava.awt.*;importjavax.swing.*;publicclassServer{@SuppressWarnings(“resource“)publicstaticvoidmain(String[]args){ServerSocketserver=null;ServerThreadthread;Socketyou=null;while(true){try{server=newServerSocket(4331);}catch(IOExceptione1){System.out.println(“try{you=server.accept;
“);}System.out.println(“ 客户的地点:“+you.getInetAddress);}catch(IOExceptione){System.out.println(“if(you!=null){newServerThread(you).start;
正在等候客户“);}}}}}classServerThreadextendsThread{Socketsocket;ObjectInputStreamin=null;ObjectOutputStreamout=null;JFramewindow;JTextAreatext;ServerThread(Sockett){socket=t;21/43try{}
out=newObjectOutputStream(socket.getOutputStream);in=newObjectInputStream(socket.getInputStream);catch(IOExceptione){}window=newJFrame;text=newJTextArea;for(inti=1;i<=20;i++){text.append(“}
你好,我是效劳器上的文件区组件 \n“);text.setBackground(Color.yellow);window.add(text);window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoidrun{try{out.writeObject(window);}catch(IOExceptione){System.out.println(“}}}
客户走开“);四、试验结果五、总结学会使用套接字读取效劳器端的对象,为 此后学习java打下好的根底,对 java能更为熟习22/43试验报告课程名称 Java面对对象程序设计试验名称 酒店治理系统工程实训姓名 吴超益 学号 202324134114 专业年级 14物联网一、试验目的:综合所学的学问,设计出简洁的酒店治理系统二、试验内容:业务需求功能登录模块:实现登录功能的数据办理用户治理模块:使用用户账号登录,实现房间查问和预约的功能,能够下订单和查问订单治理员治理模块:实现房间信息和用户信息的增、删、改、查2〕数据库关系模块商品〔商品编号,商品名字,商品价钱,产地,种类,数目〕客户〔种类,用户编号,密码〕订单〔订单编号,订单数目,订单日期,价钱,状态,房间编号,用户编号〕三、试验步骤试验源代码:数据库连结packageindex;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassConnectionDB{privateResultSetrs;privateConnectioncon;// 连结privateStatementstmt;// 用来履行对数据库的操作//结果集用来存放查问结果publicConnectionDB{//1.加载驱动程序try{//捕获异样Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver“);23/43}catch(ClassNotFoundExceptione){e.printStackTrace;}//2.创立连结try{con=DriverManager.getConnection(“jdbc:odbc:RoomManage“);}catch(SQLExceptione){e.printStackTrace;}//3.创立用于履行静态try{
SQL语句并返回它所生成结果的对象stmt=con.createStatement;}catch(SQLExceptione){e.printStackTrace;}}//4.对数据库进展查问操作publicvoidinquery(Stringsql){try{rs=stmt.executeQuery(sql);}catch(SQLExceptione){e.printStackTrace;}}publicvoidquery(Stringsql){try{stmt.execute(sql);}catch(SQLExceptione){e.printStackTrace;}}//5.rsget方法publicResultSetgetRs{returnrs;}publicvoidclose{try{stmt.close;}catch(SQLExceptione){e.printStackTrace;}try{con.close;}catch(SQLExceptione){24/43e.printStackTrace;}}}packageindex;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.GridLayout;importjava.awt.HeadlessException;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.Date;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTabbedPane;importjavax.swing.JTextField;importjavax.swing.border.LineBorder;importjavax.swing.border.TitledBorder;publicclassLoginextendsJFrameimplementsActionListener{privateJTextFieldjtpSearch=newJTextField(10);privateJTextFieldjtpUser=newJTextField(10);privateJPasswordFieldjtpPsw=newJPasswordField(10);privateJButtonjbSearch=newJButton(“ 检索“);privateJButtonjbLoad=newJButton(“ 登录“);privateJButtonjbRestart=newJButton(“ 重填“);privateJButtonjbCancel=newJButton(“ 撤消“);privateConnectionDBcon;privateResultSetrs;inti=0;Login{25/43draw;}publicvoiddraw{//整体this.setSize(800,600);this.setTitle(“星宇酒店房间治理系统“);Containert=this.getContentPane;t.setLayout(newBorderLayout);JPanelpNorth=newJPanel;JPanelpCenter=newJPanel;JPanelpEast=newJPanel;JPanelpSouth=newJPanel;t.add(pNorth,BorderLayout.NORTH);t.add(pCenter,BorderLayout.CENTER);t.add(pEast,BorderLayout.EAST);t.add(pSouth,BorderLayout.SOUTH);pNorth.setBorder(newLineBorder(newColor(81,147,253),2));pCenter.setBorder(newTitledBorder(“ 房间信息“));pEast.setBorder(newLineBorder(newColor(81,147,253),1));pSouth.setBorder(newLineBorder(newColor(81,147,253),2));//北边pNorth.setLayout(newBorderLayout);JPanelpNorth1=newJPanel;JPanelpNorth2=newJPanel;JPanelpNorth3=newJPanel;JPanelpNorth4=newJPanel;pNorth.add(pNorth1,BorderLayout.CENTER);pNorth.add(pNorth2,BorderLayout.WEST);Datenow=newDate;pNorth2.setLayout(newGridLayout(2,1));//pNorth2.add(newJLabel(“ 站内收索,欢送使用!!“));pNorth2.add(pNorth3);pNorth3.setLayout(newFlowLayout(FlowLayout.CENTER));//pNorth3.add(jtpSearch);26/43//pNorth3.add(jbSearch);pNorth4.setBackground(newColor(80,113,255));pNorth2.setBackground(newColor(80,113,255));pNorth3.setBackground(newColor(80,113,255));pNorth1.setBackground(newColor(80,113,255));//东边pEast.setLayout(newGridLayout(3,1));JPanelpEast1=newJPanel;JPanelpEast2=newJPanel;JPanelpEast3=newJPanel;JPanelpEast4=newJPanel;JPanelpEast5=newJPanel;JPanelpEast6=newJPanel;JPanelpEast7=newJPanel;pEast.add(pEast2);pEast.add(pEast7);pEast.add(pEast1);pEast1.setLayout(newBorderLayout);pEast1.setBorder(newTitledBorder(“ pEast1.add(pEast3,BorderLayout.CENTER);pEast1.add(pEast4,BorderLayout.SOUTH);pEast3.setLayout(newGridLayout(2,1));pEast3.add(pEast5);pEast3.add(pEast6);pEast5.setLayout(newFlowLayout(FlowLayout.LEFT));pEast6.setLayout(newFlowLayout(FlowLayout.LEFT));pEast5.add(newJLabel(“ “));pEast5.add(jtpUser);pEast6.add(newJLabel(“ pEast6.add(jtpPsw);
码“));pEast4.setLayout(newFlowLayout(FlowLayout.CENTER));pEast4.add(jbLoad);pEast4.add(jbRestart);pEast4.add(jbCancel);pEast2.setLayout(newGridLayout(4,1));27/43pEast2.setBorder(newTitledBorder(“ JLabeljl=newJLabel(“ 欢送您“);jl.setForeground(newColor(81,147,253));JLabeljl1=newJLabel(“ 度假休闲的好选择“);jl1.setForeground(newColor(81,147,253));JLabeljl2=newJLabel(“ 出差工作的好选择“);jl2.setForeground(newColor(81,147,253));JLabeljl3=newJLabel(“ 完善的酒店预定系统,让您预定酒店客房更为轻松快捷“);jl3.setForeground(newColor(81,147,253));pEast2.add(jl);pEast2.add(jl1);pEast2.add(jl2);pEast2.add(jl3);pEast7.setLayout(newGridLayout(4,1));JLabeljl71=newJLabel(“ “);JLabeljl72=newJLabel(“1 、您预定了N间房,请您供给很多于 N位的入住客人姓名;“);JLabeljl73=newJLabel(“2 、依据酒店规定:12点前入住需等房; “);JLabeljl74=newJLabel(“3、预定此酒店务必留入住客人真实姓名。jl71.setForeground(newColor(81,147,253));jl72.setForeground(newColor(81,147,253));jl73.setForeground(newColor(81,147,253));jl74.setForeground(newColor(81,147,253));pEast7.add(jl71);pEast7.add(jl72);pEast7.add(jl73);pEast7.add(jl74);
“);//南边pSouth.setLayout(newGridLayout(2,1));JPanelpSouth1=newJPanel;JPanelpSouth2=newJPanel;pSouth1.setLayout(newFlowLayout(FlowLayout.CENTER));pSouth2.setLayout(newFlowLayout(FlowLayout.CENTER));pSouth.add(pSouth1);pSouth.add(pSouth2);JLabeljl5=newJLabel(“ 星宇公司出品“);jl5.setForeground(newColor(81,147,253));pSouth1.add(jl5);//中间pCenter.setLayout(newBorderLayout);JTabbedPanejtp=newJTabbedPane;28/43pCenter.add(jtp,BorderLayout.CENTER);JPanelpCenter1=newJPanel;pCenter1.setLayout(newBorderLayout);pCenter1.add(newJLabel(newImageIcon(“src/Image/r1.jpg“)));JPanelpCenter2=newJPanel;pCenter2.setLayout(newBorderLayout);pCenter2.add(newJLabel(newImageIcon(“src/Image/r2.jpg“)));JPanelpCenter3=newJPanel;pCenter3.setLayout(newBorderLayout);pCenter3.add(newJLabel(newImageIcon(“src/Image/r3.jpg“)));JPanelpCenter4=newJPanel;pCenter4.setLayout(newBorderLayout);pCenter4.add(newJLabel(newImageIcon(“src/Image/r4.jpg“)));jtp.add(pCenter1,“ 酒店全景“);jtp.add(pCenter2,“ 标准间“);jtp.add(pCenter3,“ 商务间“);jtp.add(pCenter4,“ 豪华间“);jtp.setForeground(newColor(81,147,253));jbLoad.addActionListener(this);jbCancel.addActionListener(this);jbRestart.addActionListener(this);}publicvoidactionPerformed(ActionEventarg0){if(arg0.getSource==jbLoad){con=newConnectionDB;con.inquery(“select*fromuserInfwhereuserId=”“+jtpUser.getText.trim+“”“);rs=con.getRs;try{if(rs.next){if(rs.getString(“password“).trim.equals(jtpPsw.getText.trim)){JOptionPane.showMessageDialog(this,“ “,JOptionPane.INFORMATION_MESSAGE);Indexindex=newIndex(jtpUser.getText.trim);this.dispose;}else{JOptionPane.showMessageDialog(this,“ ,“,JOptionPane.INFORMATION_MESSAGE);29/43}}else
jtpPsw.setText(““);JOptionPane.showMessageDialog(this, “用户名错误,!“,JOptionPane.INFORMATION_MESSAGE);}catch(HeadlessExceptione){//TODOAuto-generatedcatchblocke.printStackTrace;}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace;}
}elseif(arg0.getSource==jbRestart){jtpPsw.setText(““);jtpUser.setText(““);}elseif(arg0.getSource==jbCancel)this.dispose;con.close;}publicstaticvoidmain(String[]args){Loginlogin=newLogin;login.setVisible(true);login.setDefaultCloseOperation(3);}}packageindex;importuser.*;importjavax.swing.*;importjavax.swing.border.LineBorder;importjavax.swing.border.TitledBorder;importroom.RoomManager;importroom.RoomSearch;importsole.SoleInfSearch;importjava.awt.*;importjava.sql.ResultSet;importjava.sql.SQLException;publicclassIndexextendsJFrame{privateJTabbedPanejtp=new JTabbedPane;privateJPanelpGoods=newJPanel;privateJPanelpHouse=newJPanel;30/43privateConnectionDBcon;privateResultSetrs;privateStringuser;Index(Stringuser){this.user=user;draw;}publicvoiddraw{con=new ConnectionDB;System.out.println(“select*fromuserInfwhereuserId=”“+user+“”“);con.inquery(“select*fromuserInfwhereuserId=”“+user+“”“);rs=con.getRs;this.setSize(800,600);this.setTitle(“星宇公司出品“);Containert=this.getContentPane;t.setLayout(newBorderLayout);JPanelpNorth=newJPanel;JPanelpCenter=newJPanel;JPanelpSouth=newJPanel;t.add(pNorth,BorderLayout.NORTH);t.add(pCenter,BorderLayout.CENTER);t.add(pSouth,BorderLayout.SOUTH);pNorth.setBorder(newLineBorder(newColor(81,147,253),2));pSouth.setBorder(newLineBorder(newColor(81,147,253),2));//北边pNorth.setLayout(newFlowLayout(FlowLayout.RIGHT));pNorth.add(newJLabel(newImageIcon(“Image/5.jpg“)));pNorth.setBackground(newColor(80,113,255));//中间pCenter.setLayout(newBorderLayout);pCenter.add(jtp,BorderLayout.CENTER);try{
if(rs.next){if(rs.getString(“identify“).trim.equals(“user“)){pCenter.setBorder(newTitledBorder(“ RoomSearchpGoods=newRoomSearch(user);31/43jtp.add(pGoods,“ 房间查问“);SoleInfSearchpsis=newSoleInfSearch;jtp.add(psis,“ “);}else{
pCenter.setBorder(newTitledBorder(“ “));RoomManagerpGoodsManager=newRoomManager(user);jtp.add(pGoodsManager,“ 房间治理“);UserManagerstore=newUserManager(user);jtp.add(store,“ 客户治理“);}}}catch(SQLExceptione){e.printStackTrace;}// 南边pSouth.setLayout(newGridLayout(2,1));JPanelpSouth1=newJPanel;JPanelpSouth2=newJPanel;pSouth1.setLayout(newFlowLayout(FlowLayout.CENTER));pSouth2.setLayout(newFlowLayout(FlowLayout.CENTER));pSouth.add(pSouth1);pSouth.add(pSouth2);JLabeljl5=newJLabel(“ 星宇公司出品“);jl5.setForeground(newColor(81,147,253));pSouth1.add(jl5);this.setVisible(true);}}注:由于试验代码过长,不过复制主要代码32/43四、试验结果33/4334/43五、总结综合所学的学问,设计出简洁的酒店治理系统,经过此次试验,大大提升自己的编程力气,对试验Java 有很大的帮助。35/43试验报告课程名称 Java面对对象程序设计试验名称 eclipse和MySQL连结起来姓名 吴超益 学号 202324134114 专业年级 14物联网一、试验目的:要求将eclipse 和MySQL连结起来二、试验内容:只要要把eclipse 和MySQL连结起来,且在eclipse 中要能够操作MySQL〔需要截图〕三、试验步骤〔复制试验代码到这里,打印时请把括号里的内容删除〕 :方法一代码:packageconnect;importjava.sql.*;publicclassGet_message{publicStringname;publicStringdatetime;publicintno;publicStringcontent;publicstaticvoidmain(String[]args)throwsException{Connectioncon;Statementstmt;ResultSetrs;Class.forName(“com.mysql.jdbc.Driver“);con=DriverManager.getConnection(“jdbc:mysql://localhost:3306/TestJDBC“,“root“,“123456“);stmt=con.createStatement;rs=stmt.executeQuery(“SELECT*FROMUserInfo“);while(rs.next){System.out.println(“userNname:“+rs.getString(1)+“,password:“+rs.getString(2));36/43}}}方法二的代码:packagejdbc;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassTestJDBC{privateStatementstatement;publicTestJDBC{try{Class.forName(Values.DRIVER_MYSQL);//System.out.println(“DriverLoadSuccess.“);//System.out.println(Values.URL);//System.out.println(“1“);Connectionconnection=
//JDBC驱动DriverManager.getConnection(“jdbc:mysql://localhost:3306/TestJDBC?“+“user=root&password=123456&useUnicode=true&characterEncoding=UTF8“); //创立数据库连结对象statement=connection.createStatement;}catch(Exceptione){
//创立Statement 对象//TODOAuto-generatedcatchblocke.printStackTrace;}}/*sql查问数据库,返回一个结果集输 入:SQL语句返回值:ResultSet 查问结果*/publicResultSetquery(Stringsql){37/43ResultSetresult=null;try{result=statement.executeQuery(sql);}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTra
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- LED驱动器产业链招商引资的调研报告
- 医用充气床产业链招商引资的调研报告
- 2023-2024学年辽宁省鞍山市海城市八年级上学期期中语文试题含答案
- 电驱未来:绿色出行探索-电动汽车发展与市场前景分析
- 提升排水服务品质计划
- 灵活用工劳动合同三篇
- 人事部如何支持企业可持续发展计划
- 年度目标设定的S原则计划
- 增强班级自信心的活动设计计划
- 天然气运输合同三篇
- 司法所安置帮教工作流程图
- 金融大数据课程教学大纲
- 第9课 共同弘扬中华传统美德
- 兜沙经(一)赏析中国书法赏析
- 贫困户困难补助申请书
- 桥梁养护与加固绪论课件
- 平板显示技术:TFT-LCD工艺
- 动火安全作业票填写模板2022年更新
- 外研版九年级英语上册全套ppt课件
- Matlab基本介绍
- 电大电子商务专业网页设计与制作课程汇编
评论
0/150
提交评论