Java实验报告模板
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验报告
课程名称Java 面向对象程序设计
实验名称检查危险品
姓名吴超益学号201424134114专业年级14 物联网
一、实验目的:
本实验的目的是让学生掌握try-catch 语句
二、实验内容:
车站检查危险品的设施,假如发现危险品就会发出警示。
编写 Exception 的子类 DangeException,编写 Machine 类办理异样
主类 main 方法中的 try-catch 办理 machine 类的实例调用
三、实验步骤
实验源代码:
import java.io.*;
import .*;
import java.util.*;
public class Client {
public static void main(String agrs[])
{
Scanner scanner= new Scanner (System.in);
Socket mysocket=null;
ObjectInputStream inObject=null;
ObjectOutputStream outObject=null;
Thread thread;
ReadWindow readWindow =null;
try {
mysocket =new Socket();
readWindow =new ReadWindow();
thread =new Thread(readWindow);
System.out.println("输入服务器的 IP");
String IP=scanner.nextLine();
System.out.println("输入端口号: ");
int port =scanner.nextInt();
if(mysocket.isConnected())
{
}
else
{
InetAddress address =InetAddress.getByName(IP);
InetSocketAddress socketAddress=new
InetSocketAddress(address,port);
mysocket.connect(socketAddress);
InputStream in=mysocket.getInputStream();
OutputStream out=mysocket.getOutputStream();
inObject=new ObjectInputStream(in);
outObject=new ObjectOutputStream(out);
readWindow.setObjectInputStream(inObject);
thread.start();
}
}
catch(Exception e)
{
System.out.println("服务器已经断开 "+e);
}
}
}
class ReadWindow implements Runnable
{
ObjectInputStream in;
public void setObjectInputStream( ObjectInputStream in)
{
this .in=in;
}
public void run()
{
double result =0;
while (true)
{
try{
javax.swing.JFrame window=(javax.swing.JFrame)in.readObject();
window.setTitle("这是从服务器上读入的窗口");
window.setVisible(true);
window.requestFocusInWindow();
window.setSize(600, 800);
}
catch (Exception e)
{
System.out.println("服务器已经断开 "+e);
break;
}
}
}
}
//
/*
*异样类继承 Exception
*当你要抛出的自定义的异样类,一定继承 Exception,不然错误*catch 捕获抛出的异样
*/
public class DangerException extends Exception {
String message;
public DangerException() {
message = 危"险品! ";
}
public void toShow() {
System.out.print(message + " ");
}
}
public class Goods {
public boolean isDanger;
String name;
public void setIsDanger(boolean boo) {
isDanger = boo;
}
public boolean isDanger() {
return isDanger;
}
public void setName(String s) {
name = s;
}
public String getName() {
return name;
}
}
/*
*异样的办理和抛出
*throws,申明异样的实例
*格式为: throws 异样类名
*exp:throws DangerExeption
*申明异样后应当在调用者里面对捕获的异样办理
*throw ,抛出异样
*格式为: throw 异样实例
*exp:throw new DangerException
*假如捕获到申明的异样。
直接跳转相应的 catch 语句
*能够申明多个异样类,并用多重 catch 语句捕获
*/
public class Machine {
public void checkBag(Goods good) throws DangerException
{ if (good.isDanger == true) {
throw new DangerException();
} else {
System.out.print(good.getName() + "不是危险品! ");
}
}
}
四、实验结果
五、总结
经过此次实验,熟习了 try_catch 语句,对此后学习 java 打下好的基础,对java 能更为熟习
实验报告
课程名称Java面向对象程序设计
实验名称比较日期
姓名吴超益学号201424134114 专业年级14 物联网
一、实验目的:
目的是让学生掌握Data 类以及Calendar 类的常用方法
二、实验内容:
编写一个 java 应用程序,用户从输入对话框输入两个日期,程序将判断两个日期的大小关系,以及两个日期之间的间隔天数
三、实验步骤
实验源代码:
package 比较日期 ;
import java.sql.Date;
import java.util.Calendar;
import java.util.Scanner;
public class CompareDate {
public static void main(String[] args) {
// TODO Auto-generated method stub Scanner
scanner = new Scanner(System.in);
System.out.println("输入第一个年,月,日数据 ");
System.out.println("输入年份 ");
short yearOne = scanner.nextShort();
System.out.println("输入月份 ");
byte monthOne = scanner.nextByte();
System.out.println("输入日期 ");
byte dayOne = scanner.nextByte();
System.out.println("输入第二年,月,日数据");
System.out.println("输入年份 ");
short yearTwo = scanner.nextShort();
System.out.println("输入月份 ");
byte monthTwo = scanner.nextByte();
System.out.println("输入日期 ");
byte dayTwo = scanner.nextByte();
Calendar calendar=Calendar.getInstance();
calendar.set(yearOne , monthOne-1, dayOne);
long timeOne = calendar.getTimeInMillis();
calendar.set(yearTwo , monthTwo-1,dayTwo);
long timeTwo = calendar.getTimeInMillis();
Date date1 = new Date(timeOne);
Date date2 = new Date(timeTwo);
if (date2.equals(date1)) {
System.out.println("两个日期的年,月,日完整同样");
}
else if (date2.after(date1)) {
System.out.println("您输入的第二个日期大于第一个日期");
}else if (date2.before(date1)) {
System.out.println("您输入第二个日期毛毛雨第一个日期");
}
long day = Math.abs(timeTwo-timeOne)/(1000*60*60*24);
System.out.println(yearOne+"年 "+monthOne+"月"+dayOne+"日和 "+
yearTwo+" 年 "+monthTwo+" 月 "+dayTwo+" 日相隔"+day+" 天 ");
}
}
四、实验结果
五、总结
此次实验熟习了 Java 应用程序,并将Data类以及Calendar类的常用方法掌握,对此后学习java 打下好的基础,对java 能更为熟习。
实验报告
课程名称Java 面向对象程序设计
实验名称华容道
姓名吴超益学号201424134114专业年级14 物联网
一、实验目的:
学习焦点、鼠标和键盘事件
二、实验内容:
编写 GUI 程序,用户经过键盘和鼠标事件来实现曹操、关羽等人物的挪动。
三、实验步骤
实验源代码:
package 华容道 ;
import java.awt.*;
import java.awt.event.*;
public class huanrongdao {
public static void main(String args[])
{
new Hua_Rong_Road();
}
}
class Person extends Button implements FocusListener
{
int number;
Color c=new Color(255,245,170);
public Person(final int number,final String s)
{
super(s);
setBackground(c);
this.number=number;
c=getBackground();
addFocusListener(this);
}
public void focusGained(final FocusEvent e)
{
setBackground(Color.red);
}
public void focusLost(final FocusEvent e)
{
setBackground(c);
}
}
class Hua_Rong_Road extends Frame implements MouseListener,KeyListener,ActionListener {
Person person[]=new Person[10];
Button left,right,above,below;
Button restart=new Button(" 从头开始 ");
public Hua_Rong_Road()
{
init();
setBounds(100,100,320,360);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{
System.out.println(0);
}});
}
public void init()
{
setLayout(null);
add(restart);
restart.setBounds(100,320,120,25);
restart.addActionListener(this);
String name[]={" 曹操 "," 关羽 "," 张飞 "," 刘备 "," 赵云 "," 黄忠 "," 兵 "," 兵 "," 兵 ","
兵 "}; for(int k=0;k<name.length;k++)
{
person[k]=new Person(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);
person[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=new Button();right=new Button(); above=new Button();below=new Button(); 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();
}
public void keyTyped(KeyEvent e){}
public void KeyReleased(KeyEvent e){} public void KeyPressed(KeyEvent e)
{
Person man=(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);
}
}
public void mousePressed(MouseEvent e) {
Person man=(Person)e.getSource();
int x=-1,y=-1;
x=e.getX();
y=e.getY();
int w=man.getBounds().width;
int h=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);
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void go(Person man,Button direction)
{
boolean move=true;
Rectangle manRect=man.getBounds();
int x=man.getBounds().x;
int y=man.getBounds().y;
if(direction==below)
y=y+50;
else if(direction==above)
y=y-50;
else if(direction==left)
x=x-50;
else if(direction==right)
x=x+50;
manRect.setLocation(x,y);
Rectangle directionRect=direction.getBounds();
for(int k=0;k<10;k++)
{
Rectangle personRect=person[k].getBounds();
if((manRect.intersects(personRect))&&(man.number!=k))
{
move=false;
}
}
if(manRect.intersects(directionRect))
{
move=false;
}
if(move==true)
{
man.setLocation(x,y);
}
}
public void actionPerformed(ActionEvent e)
{
dispose();
new Hua_Rong_Road();
}
public void keyPressed(KeyEvent arg0) {
}
public void keyReleased(KeyEvent arg0) {
}
}
四、实验结果
五、总结
此次实验让我认识了焦点、鼠标和键盘事件,此后学习 java 打下好的基础,对 java 能更为熟习
实验报告
课程名称Java面向对象程序设计
实验名称汉字输入练习
姓名吴超益学号201424134114 专业年级14 物联网
一、实验目的:
掌握 Thread 的子类创立线程
二、实验内容:
编写一个 java 应用程序,在主线程序中再创立两个线程,第一个负责给出某个汉字,第二个线程负责让用户在命令行输入第一线程给出的汉字
三、实验步骤
实验源代码:
import java.util.Scanner;
public class TepyChinese {
public static void main(String args []){
System. out .println( " 输入汉字练习(输入#结束程序) " );
System. out .println( " 输入显示的汉字(回车) " );
Chinese hanzi ;
hanzi = new Chinese();
GiveChineseThread giveHanzi ;
InputChineseThread typeHanzi ;
giveHanzi =new GiveChineseThread();
giveHanzi .setChinese( hanzi );
giveHanzi .setSleepLength(6000);
typeHanzi =new InputChineseThread();
typeHanzi .setChinese( hanzi );
giveHanzi .start();
try {
Thread. sleep (200);
}
catch (Exception exp ){
typeHanzi.start();
}
}
}
class Chinese{
char c ='\0' public void ;
setChinese( char c ){
this . c = c ; } public char getChinese(){
return
c ;
} }
class GiveChineseThread extends
Chinese hanzi ;
char startChar =( char )22909,
int sleepLength
=5000;
public
void
setChinese(Chinese
this . hanzi = hanzi ;
Thread{
endChar =( char )( startChar
hanzi ){
+100);
} public
void setSleepLength(
int
n ){
sleepLength
= n;
} public
char
while
void run(){
c = startChar ;
( true ){
hanzi .setChinese( System. out .printf(
try {
c );
" 显示的汉字:
%c\n" , hanzi .getChinese());
Thread.
sleep
( sleepLength
);
}
catch (InterruptedException c =( char )( c +1); if ( c >endChar )
c = startChar
;
e ){}
} } }
class InputChineseThread extends Scanner reader ; Chinese hanzi ;
int
score =0;
InputChineseThread(){
reader = new Scanner(System.
Thread{
in );
} public
void setChinese(Chinese
hanzi
){
this
. hanzi = hanzi ;
} public
while
void ( run(){
true ){
String str =reader .nextLine();
char c = str .charAt(0);
if ( c == hanzi .getChinese()){
score ++;
System. out .printf( "\t\t 输入对了,当前分数%d\n" , score );
}
else
System. out .printf( "\t\t 输入错了,当前分数%d\n" , score );
if ( c == '#' )
System. exit (0);
}
}
}
四、实验结果
五、总结
此次实验熟习了Java 应用程序,并将Thread的子类的常用方法掌握,对此后学习 java 打下好的基础,对java 能更为熟习。
实验报告
课程名称Java 面向对象程序设计
实验名称读取服务器端文件
姓名吴超益学号201424134114 专业年级14 物联网
一、实验目的:
学习使用URL
二、实验内容:
创立一个使用 URL 对象,而后让 URL 对象返回输入流,经过该输入流读取 URL 所包括的资源文件
三、实验步骤
实验源代码:
package one;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import .MalformedURLException;
import .URL;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ReadURLSource {
public static void main(String[] args) {
new NetWin();
}
}
class NetWin extends JFrame implements ActionListener, Runnable
{ JButton button;
URL url;
JTextField inputURLText;
JTextArea area;
byte b[] = new byte[118];
Thread thread;
public NetWin() {
//TODO Auto-generated constructor
stub inputURLText = new JTextField(20);
area = new JTextArea(12, 12);
button = new JButton(" 确立 ");
button.addActionListener(this);
thread = new Thread(this);
JPanel p = new JPanel();
p.add(new JLabel(" 请输入网址 :"));
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);
}
public void actionPerformed(ActionEvent e) {
if (!(thread.isAlive())) {
thread = new Thread(this);
}
try {
thread.start();
} catch (Exception ee) {
inputURLText.setText(" 我正在读取 " + url);
}
}
public void run() {
try {
int n = -1;
area.setText(null);
String name = inputURLText.getText().trim();
url = new URL(name);
String hostName = url.getHost();
int urlPortNumber = url.getPort();
String fileName = url.getFile();
InputStream in = url.openStream();
area.append("\n 主机 :" + hostName + " 端口 :" + urlPortNumber + "包括的文件名
字:" + fileName);
area.append("\n 文件的内容以下:");
while ((n = in.read(b)) != -1) {
String s = new String(b, 0, n);
area.append(s);
}
} catch (MalformedURLException e1) {
inputURLText.setText("" + e1);
return;
} catch (IOException e1)
{ inputURLText.setText("" +
e1); return;
}
}
}
四、实验结果
五、总结
学习使用 URL, 此后学习 java 打下好的基础,对java 能更为熟习
实验报告
课程名称Java 面向对象程序设计
实验名称读取服务器端的窗口
姓名吴超益学号201424134114 专业年级14 物联网一、实验目的:
学会使用套接字读取服务器端的对象
二、实验内容:
客服端利用套接字连结将服务器端的 JFram 对象读取到客服端。
第一将服务器端的程序编译经过,并运转起来,等候恳求套接字连结
三、实验步骤
实验源代码:
//Client.java
package client;
import java.io.*;
import .*;
import java.util.*;
public class Client {
public static void main(String agrs[])
{
Scanner scanner= new Scanner (System.in);
Socket mysocket=null;
ObjectInputStream inObject=null;
ObjectOutputStream outObject=null;
Thread thread;
ReadWindow readWindow =null;
try {
mysocket =new Socket();
readWindow =new ReadWindow();
thread =new Thread(readWindow);
System.out.println(" 输入服务器的IP");
String IP=scanner.nextLine();
System.out.println(" 输入端口号:");
int port =scanner.nextInt();
if(mysocket.isConnected())
{
}
else
{
InetAddress address =InetAddress.getByName(IP);
InetSocketAddress socketAddress=new InetSocketAddress(address,port);
mysocket.connect(socketAddress);
InputStream in=mysocket.getInputStream();
OutputStream out=mysocket.getOutputStream();
inObject=new ObjectInputStream(in);
outObject=new ObjectOutputStream(out);
readWindow.setObjectInputStream(inObject);
thread.start();
}
}
catch(Exception e)
{
System.out.println("服务器已经断开"+e);
}
}
}
class ReadWindow implements Runnable
{
ObjectInputStream in;
public void setObjectInputStream( ObjectInputStream in)
{
this .in=in;
}
public void run()
{
double result =0;
while (true)
{
try{
window=(javax.swing.JFrame)in.readObject();
window.setTitle("这是从服务器上读入的窗口");
window.setVisible(true);
window.requestFocusInWindow();
window.setSize(600, 800);
}
catch (Exception e)
{
System.out.println(" 服务器已经断开"+e);
break;
}
}
}
}
//Server.java
package client;
import java.io.*;
import .*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Server {
@SuppressWarnings("resource")
public static void main(String[] args) {
ServerSocket server =null;
ServerThread thread;
Socket you= null;
while (true)
{
try{server = new ServerSocket(4331);}
catch (IOException e1){System.out.println(" try{you=server.accept();
System.out.println("客户的地点:catch(IOException e){System.out.println(" if(you!=null){
正在监听 ");}
"+you.getInetAddress());}
正在等候客户");}
new ServerThread(you).start();
}
}
}
}
class ServerThread extends Thread
{
Socket socket;
ObjectInputStream in=null;
ObjectOutputStream out =null;
JFrame window;
JTextArea text;
ServerThread(Socket t)
{
socket =t;
try
{
out=new ObjectOutputStream(socket.getOutputStream());
in =new ObjectInputStream(socket.getInputStream());
}
catch (IOException e){}
window =new JFrame();
text =new JTextArea();
for(int i=1;i<=20;i++)
{
text.append("你好,我是服务器上的文件区组件\n");
}
text.setBackground(Color.yellow);
window.add(text);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run(){
try{ out.writeObject(window);}
catch (IOException e){
System.out.println(" 客户走开");
}
}
}
四、实验结果
五、总结
学会使用套接字读取服务器端的对象,为此后学习 java 打下好的基础,对java 能更为熟习
实验报告
课程名称Java 面向对象程序设计
实验名称酒店管理系统项目实训
姓名吴超益学号201424134114 专业年级14 物联网一、实验目的:
综合所学的知识,设计出简单的酒店管理系统
二、实验内容:
1)业务需求功能
1.登录模块:实现登录功能的数据办理
2.用户管理模块:使用用户账号登录,实现房间查问和预约的功能,能够下
订单和查问订单
3.管理员管理模块:实现房间信息和用户信息的增、删、改、查
2)数据库关系模块
1.商品(商品编号,商品名字,商品价钱,产地,种类,数目)
2.客户(种类,用户编号,密码)
3.订单(订单编号,订单数目,订单日期,价钱,状态,房间编号,用户
编号)
三、实验步骤
实验源代码:
数据库连结
package index;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnectionDB {
private ResultSet rs;
private Connection con; // 连结
private Statement stmt;//用来履行对数据库的操作
//结果集用来寄存查问结果
public ConnectionDB() {
//1.加载驱动程序
try {// 捕获异样
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e)
{ e.printStackTrace();
}
//2.创立连结
try {
con = DriverManager.getConnection("jdbc:odbc:RoomManage");
} catch (SQLException e) {
e.printStackTrace();
}
//3.创立用于履行静态SQL 语句并返回它所生成结果的对象
try {
stmt = con.createStatement();
} catch (SQLException e)
{ e.printStackTrace();
}
}
//4.对数据库进行查问操作
public void inquery(String sql) {
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e)
{ e.printStackTrace();
}
}
public void query(String sql) {
try {
stmt.execute(sql);
} catch (SQLException e)
{ e.printStackTrace();
}
}
//5.生成 rs 属性的 get 方法
public ResultSet getRs() {
return rs;
}
public void close() {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package index;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
public class Login extends JFrame implements ActionListener { private JTextField jtpSearch = new JTextField(10);
private JTextField jtpUser = new JTextField(10);
private JPasswordField jtpPsw = new JPasswordField(10);
private JButton jbSearch = new JButton(" 检索 ");
private JButton jbLoad = new JButton(" 登录 ");
private JButton jbRestart = new JButton(" 重填 ");
private JButton jbCancel = new JButton(" 撤消 ");
private ConnectionDB con;
private ResultSet rs;
int i = 0;
Login() {
draw();
}
public void draw() {
//整体
this.setSize(800, 600);
this.setTitle(" 星宇酒店房间管理系统");
Container t = this.getContentPane();
t.setLayout(new BorderLayout());
JPanel pNorth = new JPanel();
JPanel pCenter = new JPanel();
JPanel pEast = new JPanel();
JPanel pSouth = new JPanel();
t.add(pNorth, BorderLayout.NORTH);
t.add(pCenter, BorderLayout.CENTER);
t.add(pEast, BorderLayout.EAST);
t.add(pSouth, BorderLayout.SOUTH);
pNorth.setBorder(new LineBorder(new Color(81, 147, 253), 2));
pCenter.setBorder(new TitledBorder(" 房间信息 "));
pEast.setBorder(new LineBorder(new Color(81, 147, 253), 1));
pSouth.setBorder(new LineBorder(new Color(81, 147, 253), 2));
//北边
pNorth.setLayout(new BorderLayout());
JPanel pNorth1 = new JPanel();
JPanel pNorth2 = new JPanel();
JPanel pNorth3 = new JPanel();
JPanel pNorth4 = new JPanel();
pNorth.add(pNorth1, BorderLayout.CENTER);
pNorth.add(pNorth2, BorderLayout.WEST);
Date now = new Date();
pNorth2.setLayout(new GridLayout(2, 1));
//pNorth2.add(new JLabel(" 站内收索,欢迎使用!!"));
pNorth2.add(pNorth3);
pNorth3.setLayout(new FlowLayout(FlowLayout.CENTER));
// pNorth3.add(jtpSearch);
//pNorth3.add(jbSearch);
pNorth4.setBackground(new Color(80, 113, 255));
pNorth2.setBackground(new Color(80, 113, 255));
pNorth3.setBackground(new Color(80, 113, 255));
pNorth1.setBackground(new Color(80, 113, 255));
//东边
pEast.setLayout(new GridLayout(3, 1));
JPanel pEast1 = new JPanel();
JPanel pEast2 = new JPanel();
JPanel pEast3 = new JPanel();
JPanel pEast4 = new JPanel();
JPanel pEast5 = new JPanel();
JPanel pEast6 = new JPanel();
JPanel pEast7 = new JPanel();
pEast.add(pEast2);
pEast.add(pEast7);
pEast.add(pEast1);
pEast1.setLayout(new BorderLayout());
pEast1.setBorder(new TitledBorder(" 登录 "));
pEast1.add(pEast3, BorderLayout.CENTER);
pEast1.add(pEast4, BorderLayout.SOUTH);
pEast3.setLayout(new GridLayout(2, 1));
pEast3.add(pEast5);
pEast3.add(pEast6);
pEast5.setLayout(new FlowLayout(FlowLayout.LEFT)); pEast6.setLayout(new FlowLayout(FlowLayout.LEFT));
pEast5.add(new JLabel("用户名 "));
pEast5.add(jtpUser);
pEast6.add(new JLabel("密码"));
pEast6.add(jtpPsw);
pEast4.setLayout(new FlowLayout(FlowLayout.CENTER)); pEast4.add(jbLoad);
pEast4.add(jbRestart);
pEast4.add(jbCancel);
pEast2.setLayout(new GridLayout(4, 1));
pEast2.setBorder(new TitledBorder(" 新闻 "));
JLabel jl = new JLabel(" 欢迎您 ");
jl.setForeground(new Color(81, 147, 253));
JLabel jl1 = new JLabel(" 度假休闲的好选择");
jl1.setForeground(new Color(81, 147, 253));
JLabel jl2 = new JLabel(" 出差工作的好选择");
jl2.setForeground(new Color(81, 147, 253));
JLabel jl3 = new JLabel(" 完美的酒店预定系统,让您预定酒店客房更为轻松快捷 "); jl3.setForeground(new Color(81, 147, 253));
pEast2.add(jl);
pEast2.add(jl1);
pEast2.add(jl2);
pEast2.add(jl3);
pEast7.setLayout(new GridLayout(4, 1));
JLabel jl71 = new JLabel(" 【温馨提示】 ");
JLabel jl72 = new JLabel("1 、您预定了N 间房,请您供给许多于JLabel jl73 = new JLabel("2 、依据酒店规定:12 点前入住需等房;JLabel jl74 = new JLabel("3 、预定此酒店务必留入住客人真切姓名。
N 位的入住客人姓名;");
");
");
jl71.setForeground(new Color(81, 147, 253));
jl72.setForeground(new Color(81, 147, 253));
jl73.setForeground(new Color(81, 147, 253));
jl74.setForeground(new Color(81, 147, 253));
pEast7.add(jl71);
pEast7.add(jl72);
pEast7.add(jl73);
pEast7.add(jl74);
//南边
pSouth.setLayout(new GridLayout(2, 1));
JPanel pSouth1 = new JPanel();
JPanel pSouth2 = new JPanel();
pSouth1.setLayout(new FlowLayout(FlowLayout.CENTER)); pSouth2.setLayout(new FlowLayout(FlowLayout.CENTER)); pSouth.add(pSouth1);
pSouth.add(pSouth2);
JLabel jl5 = new JLabel(" 星宇公司出品 ");
jl5.setForeground(new Color(81, 147, 253));
pSouth1.add(jl5);
//中间
pCenter.setLayout(new BorderLayout());
JTabbedPane jtp = new JTabbedPane();
pCenter.add(jtp, BorderLayout.CENTER);
JPanel pCenter1 = new JPanel();
pCenter1.setLayout(new BorderLayout());
pCenter1.add(new JLabel(new ImageIcon("src/Image/r1.jpg")));
JPanel pCenter2 = new JPanel();
pCenter2.setLayout(new BorderLayout());
pCenter2.add(new JLabel(new ImageIcon("src/Image/r2.jpg")));
JPanel pCenter3 = new JPanel();
pCenter3.setLayout(new BorderLayout());
pCenter3.add(new JLabel(new ImageIcon("src/Image/r3.jpg")));
JPanel pCenter4 = new JPanel();
pCenter4.setLayout(new BorderLayout());
pCenter4.add(new JLabel(new ImageIcon("src/Image/r4.jpg")));
jtp.add(pCenter1, " 酒店全景 ");
jtp.add(pCenter2, " 标准间 ");
jtp.add(pCenter3, " 商务间 ");
jtp.add(pCenter4, " 豪华间 ");
jtp.setForeground(new Color(81, 147, 253));
jbLoad.addActionListener(this);
jbCancel.addActionListener(this);
jbRestart.addActionListener(this);
}
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == jbLoad) {
con = new ConnectionDB();
con.inquery("select * from userInf where userId='" + jtpUser.getText().trim() + "'");
rs = con.getRs();
try {
if (rs.next()) {
if (rs.getString("password").trim().equals(jtpPsw.getText().trim()))
{ JOptionPane.showMessageDialog(this, " 登录成功 !", " 信息 ", RMA TION_MESSAGE);
Index index = new Index(jtpUser.getText().trim());
this.dispose();
} else {
JOptionPane.showMessageDialog(this, " 密码错误 , 请从头输入 !", " 信息 ", RMA TION_MESSAGE);
jtpPsw.setText("");
}
} else
JOptionPane.showMessageDialog(this,
"用户名错误,请从头输入 !", "信息", RMA TION_MESSAGE);
} catch (HeadlessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (arg0.getSource() == jbRestart) {
jtpPsw.setText("");
jtpUser.setText("");
} else if (arg0.getSource() == jbCancel)
this.dispose();
con.close();
}
public static void main(String[] args) {
Login login = new Login();
login.setVisible(true);
login.setDefaultCloseOperation(3);
}
}
package index;
import user.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import room.RoomManager;
import room.RoomSearch;
import sole.SoleInfSearch;
import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Index extends JFrame {
private JTabbedPane jtp=new JTabbedPane();
private JPanel pGoods=new JPanel();
private JPanel pHouse=new JPanel();
private ConnectionDB con;
private ResultSet rs;
private String user;
Index(String user){
er=user;
draw();
}
public void draw(){
con=new ConnectionDB();
System.out.println("select * from userInf where userId='"+user+"'");
con.inquery("select * from userInf where userId='"+user+"'");
rs=con.getRs();
this.setSize(800,600);
this.setTitle(" 星宇公司出品 ");
Container t=this.getContentPane();
t.setLayout(new BorderLayout());
JPanel pNorth=new JPanel();
JPanel pCenter=new JPanel();
JPanel pSouth=new JPanel();
t.add(pNorth,BorderLayout.NORTH);
t.add(pCenter,BorderLayout.CENTER);
t.add(pSouth,BorderLayout.SOUTH);
pNorth.setBorder(new LineBorder(new Color(81,147,253),2));
pSouth.setBorder(new LineBorder(new Color(81,147,253),2));
//北边
pNorth.setLayout(new FlowLayout(FlowLayout.RIGHT));
pNorth.add(new JLabel(new ImageIcon("Image/5.jpg")));
pNorth.setBackground(new Color(80,113,255));
//中间
pCenter.setLayout(new BorderLayout());
pCenter.add(jtp,BorderLayout.CENTER);
try {
if(rs.next()){
if(rs.getString("identify").trim().equals("user")){
pCenter.setBorder(new TitledBorder(" 订房 "));
RoomSearch pGoods=new RoomSearch(user);。