




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.s
2、wing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class LogOn public static void main(String args)throws SQLExceptionfinal JFrame jfrmlogin=new JFrame("
3、系统登录");jfrmlogin.setSize(400,280);Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();jfrmlogin.setLocation(int) (screenSize.width-400)/2,(int)(screenSize.height-300)/2);/设置框出现的位置JPanel p1=new JPanel();p1.add(new JLabel("用户名:");final JTextField jtxtuser=new JTextField(14)
4、;JPanel p2=new JPanel();p2.add(new JLabel("密 码:");final JPasswordField jspwd=new JPasswordField(14);JPanel p3=new JPanel();final JButton jbtUser=new JButton("登 录");final JButton jbtreg=new JButton("注 册");JButton jbtexit=new JButton("退 出");p1.add(jtxtuser);p2.a
5、dd(jspwd);p3.add(jbtUser);p3.add(jbtreg);p3.add(jbtexit); jbtUser.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) Connection conn=null; ResultSet rs=null; Statement stmt=null; if(e.getSource()=jbtUser) try Class.forName("oracle.jdbc.driver.OracleDriver"); c
6、onn = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "system", "123"); stmt=conn.createStatement(); String USER_NAME=jtxtuser.getText(); rs = stmt.executeQuery("select * from TICKET_USERS where USER_NAME='"+jtxtuser.getText()+"
7、9;and USER_PWD='"+jspwd.getText()+"'"); if(rs.next() if(USER_NAME.equals("admin")=false) MainUser mf=new MainUser(); mf.setVisible(true); jfrmlogin.dispose(); else MainFrame mf=new MainFrame(); mf.setVisible(true); jfrmlogin.dispose(); else JOptionPane.showMessageDia
8、log(null,"用户名或密码不一致,请重新输入!","系统提示",JOptionPane.ERROR_MESSAGE); jtxtuser.setText(""); jspwd.setText(""); catch (Exception ex) JOptionPane.showMessageDialog(null,"用户名或密码不一致,请重新输入!","系统提示",JOptionPane.ERROR_MESSAGE); jtxtuser.setText("&qu
9、ot;); jspwd.setText(""); );jbtreg.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) Connection conn=null; ResultSet rs=null; Statement stmt=null; if(e.getSource()=jbtreg) try Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.get
10、Connection("jdbc:oracle:thin:localhost:1521:orcl", "system", "123"); stmt=conn.createStatement(); rs = stmt.executeQuery("insert into TICKET_USERS(USER_NAME,USER_PWD) values('"+jtxtuser.getText()+"','"+jspwd.getText()+"')");
11、 if(rs.next() JOptionPane.showMessageDialog(null,"你已成功注册!可以登录了!","系统提示",JOptionPane.INFORMATION_MESSAGE); jtxtuser.setText(""); jspwd.setText(""); else JOptionPane.showMessageDialog(null,"用户注册失败!","系统提示",JOptionPane.ERROR_MESSAGE); jtxtuser
12、.setText(""); jspwd.setText(""); catch (Exception ex) JOptionPane.showMessageDialog(null,"用户注册失败!","系统提示",JOptionPane.ERROR_MESSAGE); jtxtuser.setText(""); jspwd.setText(""); ); jbtexit.addActionListener(new ActionListener() public void act
13、ionPerformed(ActionEvent e) System.exit(0); ); jfrmlogin.getContentPane().setLayout(new GridLayout(3,1); jfrmlogin.getContentPane().add(p1);jfrmlogin.getContentPane().add(p2); jfrmlogin.getContentPane().add(p3); jfrmlogin.setVisible(true);import java.sql.*; public class ConnectOracle public static v
14、oid connection(String args) throws SQLException /Connection conn=null; /Statement stmt=null; /ResultSet rs=null; /JDBC 直连Oracle数据库 加载驱动 try System.out.println("正在连接数据库."); Class.forName("oracle.jdbc.driver.OracleDriver"); /*conn =*/ DriverManager.getConnection("jdbc:oracle:t
15、hin:localhost:1521:orcl", "system", "123"); System.out.println("已经连接到数据库."); /stmt=conn.createStatement(); /stmt.executeQuery("insert into student(STUID,STUNAME,SEX,AGE)values(0001,'李华','男',20)");/rs=stmt.executeQuery("select * from S
16、TUDENT"); /System.out.println(" stuID "+" StuName " + " Sex " + " Age");/while(rs.next() /int STUID=rs.getInt("STUID"); /String STUNAME=rs.getString("STUNAME"); /String SEX=rs.getString("SEX");/int AGE=rs.getInt("AGE&quo
17、t;);/System.out.println(" "+STUID+" "+STUNAME+" "+SEX+" "+AGE); /System.out.println(" STUID "+STUID+" STUNAME "+STUNAME+"SEX"+SEX+"AGE"+AGE); / catch (Exception ex) /System.out.println("出现的异常为" + ex); import ja
18、va.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.
19、JPanel;import javax.swing.JTextField;public class AddTicket extends JPanel implements ActionListenerConnection con;Statement st;JLabel jLabel1=new JLabel("票 单 价:");JLabel jLabel2=new JLabel("票 日 期:");JTextField jTextField1=new JTextField();JTextField jTextField2=new JTextField();
20、JButton jButton1=new JButton("确定增加");public AddTicket()tryjbInit();catch(Exception exception)exception.printStackTrace();private void jbInit() throws ExceptionClass.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521
21、:orcl", "system", "123"); this.setLayout(null);jLabel1.setBounds(new Rectangle(40,40,64,24);jLabel2.setBounds(new Rectangle(40,100,53,22);jTextField1.setBounds(new Rectangle(102,40,200,30);jTextField2.setBounds(new Rectangle(102,100,200,30);jButton1.setBounds(new Rectangle(1
22、20,220,150,32);jButton1.addActionListener(this);this.add(jLabel1);this.add(jTextField1);this.add(jLabel2);this.add(jTextField2);this.add(jButton1);ResultSet rs=null;st=con.createStatement();rs = st.executeQuery("select * from TICKET_TRANSCRIPT");if(rs.next() jTextField1.setText(rs.getStrin
23、g("TICKET_PRICE");public void actionPerformed(ActionEvent e)tryst=con.createStatement();st.executeUpdate("delete from TICKET");st.executeUpdate("delete from TICKET_ORDER_FORM");st.executeUpdate("insert into TICKET select * from TICKET_TRANSCRIPT"); st.executeU
24、pdate("update TICKET set TICKET_DATE='"+jTextField2.getText()+"'"); st.executeUpdate("update TICKET set TICKET_PRICE='"+jTextField1.getText()+"'");JOptionPane.showMessageDialog(this,"票增加成功!");jTextField1.setText("");jTextFie
25、ld2.setText("");catch(Exception ex)JOptionPane.showMessageDialog(this,"票增加失败!");ex.printStackTrace();import javax.swing.*;import javax.swing.table.JTableHeader;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.*;publi
26、c class AdminInquireTicket extends JFrameConnection con;Statement st; private JScrollPane scpDemo; private JTableHeader jth; private JTable tabDemo; private JButton btnShow; private JButton btnShow1; public AdminInquireTicket() super("华清池售票系统"); this.setSize(430,400); this.setLayout(null);
27、 this.setLocation(500,180); this.scpDemo = new JScrollPane(); this.scpDemo.setBounds(10,50,390,270); this.btnShow = new JButton("显示票信息"); this.btnShow.setBounds(10,10,390,30); this.btnShow1 = new JButton("返 回"); this.btnShow1.setBounds(260,330,120,30); JLabel jLabel1=new JLabel(&
28、quot;余票总数:"); JTextField jTextField1=new JTextField(); jLabel1.setBounds(new Rectangle(20,330,100,30); jTextField1.setBounds(new Rectangle(90,330,70,30); add(this.scpDemo); add(this.btnShow); add(this.btnShow1); this.add(jLabel1);this.add(jTextField1); this.setVisible(true); try Class.forName(&
29、quot;oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "system", "123"); ResultSet rs=null; int n = 0; st=con.createStatement(); rs = st.executeQuery("select * from TICKET"); while(rs.next() n+; j
30、TextField1.setText(""+n+""); catch(Exception exception)exception.printStackTrace(); this.btnShow1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) MainFrame mu=new MainFrame(); mu.setVisible(true); dispose(); ); this.btnShow.addActionListener(new
31、ActionListener() public void actionPerformed(ActionEvent ae) btnShow_ActionPerformed(ae); ); public void btnShow_ActionPerformed(ActionEvent ae) try Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl&quo
32、t;, "system", "123"); String sql = "select * from TICKET" PreparedStatement pstm = con.prepareStatement(sql); ResultSet rs = pstm.executeQuery(); int count = 0; while(rs.next() count+; rs = pstm.executeQuery(); Object info = new Objectcount4; count = 0; while(rs.next()
33、infocount0 = rs.getString("TICKET_NUM"); infocount1 = rs.getString("TICKET_DATE"); infocount2 = rs.getString("TICKET_PRICE"); count+; String title = "票号","日期","票价" this.tabDemo = new JTable(info,title); this.jth = this.tabDemo.getTableHeade
34、r(); this.scpDemo.getViewport().add(tabDemo); catch(ClassNotFoundException cnfe) JOptionPane.showMessageDialog(null,"查询失败!","错误",JOptionPane.ERROR_MESSAGE); catch(SQLException sqle) JOptionPane.showMessageDialog(null,"查询失败!","错误",JOptionPane.ERROR_MESSAGE); im
35、port java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax
36、.swing.JPanel;import javax.swing.JTextField;public class BuyTicket extends JPanel implements ActionListenerConnection con;Statement st;JLabel jLabel1=new JLabel("用 户 名:");JLabel jLabel2=new JLabel("票 编 号:");JLabel jLabel3=new JLabel("票 单 价:");JLabel jLabel4=new JLabel(&
37、quot;票 日 期:");JTextField jTextField1=new JTextField();JTextField jTextField2=new JTextField();JTextField jTextField3=new JTextField();JTextField jTextField4=new JTextField();JButton jButton1=new JButton("确定购买");public BuyTicket()tryjbInit();catch(Exception exception)exception.printSta
38、ckTrace();private void jbInit() throws ExceptionClass.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "system", "123"); this.setLayout(null);jLabel1.setBounds(new Rectangle(40,40,64,24);jLab
39、el2.setBounds(new Rectangle(40,100,53,22);jLabel3.setBounds(new Rectangle(40,160,61,27);jLabel4.setBounds(new Rectangle(40,220,61,27);jTextField1.setBounds(new Rectangle(102,40,200,30);jTextField2.setBounds(new Rectangle(102,100,200,30);jTextField3.setBounds(new Rectangle(102,160,200,33);jTextField4
40、.setBounds(new Rectangle(102,220,200,33);jButton1.setBounds(new Rectangle(120,300,150,32);jButton1.addActionListener(this);this.add(jLabel1);this.add(jTextField1);this.add(jLabel2);this.add(jTextField2);this.add(jLabel3);this.add(jTextField3);this.add(jLabel4);this.add(jTextField4);this.add(jButton1
41、);ResultSet rs=null;st=con.createStatement();rs = st.executeQuery("select * from (select rownum num, a.* from TICKET a)where num = (select count(1) from TICKET)");if(rs.next()jTextField2.setText(rs.getString("TICKET_NUM");jTextField3.setText(rs.getString("TICKET_PRICE")
42、;jTextField4.setText(rs.getString("TICKET_DATE");public void actionPerformed(ActionEvent e)if(e.getSource()=jButton1) tryst.executeUpdate("insert into TICKET_ORDER_FORM values('"+jTextField1.getText()+"','"+jTextField2.getText()+"','"+jText
43、Field4.getText()+"','"+jTextField3.getText()+"')");st.executeUpdate("delete from TICKET where TICKET_NUM='"+jTextField2.getText()+"'");JOptionPane.showMessageDialog(this,"购票成功!");jTextField1.setText("");jTextField2.setTe
44、xt("");jTextField3.setText("");jTextField4.setText("");catch(Exception ex)JOptionPane.showMessageDialog(this,"购票失败!");ex.printStackTrace();import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connecti
45、on;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;public class InquireTicket extends JPanel implements ActionListenerConnection con;Statement st;JLabel jLabel1=new JLabel("余 票 数:
46、");JTextField jTextField1=new JTextField();JLabel jLabel2=new JLabel("票 价:");JTextField jTextField2=new JTextField();JLabel jLabel3=new JLabel("日 期:");JTextField jTextField3=new JTextField();public InquireTicket()tryjbInit();catch(Exception exception)exception.printStackTrac
47、e();private void jbInit() throws ExceptionClass.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "system", "123"); this.setLayout(null); jLabel1.setBounds(new Rectangle(40,50,64,24);jTextFiel
48、d1.setBounds(new Rectangle(102,50,200,30);jLabel2.setBounds(new Rectangle(40,100,64,24);jTextField2.setBounds(new Rectangle(102,100,200,30);jLabel3.setBounds(new Rectangle(40,150,64,24);jTextField3.setBounds(new Rectangle(102,150,200,30);this.add(jLabel1);this.add(jTextField1);this.add(jLabel2);this
49、.add(jTextField2);this.add(jLabel3);this.add(jTextField3);ResultSet rs=null;int count = 0;st=con.createStatement();rs = st.executeQuery("select * from TICKET");while(rs.next()jTextField2.setText(rs.getString("TICKET_PRICE");jTextField3.setText(rs.getString("TICKET_DATE"
50、);count+;jTextField1.setText(""+count+"");public void actionPerformed(ActionEvent e)import java.awt.Dimension;import java.awt.Font;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JFrame;im
51、port javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;public class MainFrame extends JFrame implements ActionListener JPanel contentPane;JMenuBar jMenuBar1=new JMenuBar();JMenu jMenu0=new JMe
52、nu("系统");JMenuItem jMenuItem0=new JMenuItem("退出");JMenu jMenu1=new JMenu("增加票");JMenuItem jMenuItem1=new JMenuItem("增加票");JMenu jMenu2=new JMenu("修改票");JMenuItem jMenuItem2=new JMenuItem("修改票");JMenu jMenu3=new JMenu("查询票");JMenuItem jMenuItem3=new JMenuItem("查询票");JLabel jLabel1=new JLabel(" 华清池售票系统(管理员)");JLabel jLabel2=new JLabel(" 延安大学软件12课程设计"
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论