某应用系统CS风格客户端程序结构设计实验

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

public static void executeinsert() throws SQLException { Connection con=DBUtils.getConnection(); PreparedStatement pstmt=con.prepareStatement("insert into orders values (?,?,?,?)"); pstmt.setString(1, ReceiveDemo.time); pstmt.setString(2, ReceiveDemo.person); pstmt.setString(3, ReceiveDemo.cartype); pstmt.setString(4, ReceiveDemo.price); pstmt.executeUpdate(); } public static void executeQuery(DefaultTableModel md) throws SQLException { Order order=new Order(); Connection con=DBUtils.getConnection(); PreparedStatement pstmt=con.prepareStatement("select * from orders"); ResultSet rs=pstmt.executeQuery(); while(rs.next()){ Vector v = new Vector(); order.setTime(rs.getString(1)); order.setPerson(rs.getString(2)); order.setCartype(rs.getString(3)); order.setPrice(rs.getString(4)); v.addElement(rs.getString(1)); v.addElement(rs.getString(2)); v.addElement(rs.getString(3)); v.addElement(rs.getString(4)); md.addRow(v); } } }
// 对按钮添加事件 bu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 获取文本框的值 String tf_str1 = tf1.getText().trim(); str1=tf_str1; String tf_str2 = tf2.getText().trim(); str2=tf_str2; String tf_str3 = tf3.getText().trim(); str3=tf_str3; String tf_str4 = tf4.getText().trim(); str4=tf_str4; DatagramSocket ds=null; try { ds = new DatagramSocket(); byte[] bys1 = str1.getBytes(); byte[] bys2 = str2.getBytes(); byte[] bys3 = str3.getBytes(); byte[] bys4 = str4.getBytes(); InetAddress address = InetAddress.getByName("192.168.1.111"); int port = 10086; DatagramPacket dp1 = new DatagramPacket(bys1, bys1.length, address, port); DatagramPacket dp2 = new DatagramPacket(bys2,bys2.length , address, port); DatagramPacket dp3 = new DatagramPacket(bys3,bys3.length , address, port); DatagramPacket dp4 = new DatagramPacket(bys4,bys4.length , address, port); ds.send(dp1); ds.send(dp2);
} }); bu2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { cha(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } private void cha() throws SQLException { JFrame f = new JFrame("瑞达汽车销售订单管理系 统"); f.setBounds(400, 200, 600, 500); f.setLayout(new FlowLayout()); JTable jt = new JTable(); String header[] ={"订单时间","购买者","购买车 型","总价"}; DefaultTableModel md = new DefaultTableModel(header,0); JScrollPane scrollPane = new JScrollPane(jt); jt.setModel(md); Dao.executeQuery(md); f.getContentPane().add(scrollPane,BorderLayout. f.setVisible(true); } }); } public static void zeng(){ JFrame f = new JFrame("瑞达汽车销售订单管理系统"); // 设置窗体属性和布局
Hale Waihona Puke Baidu要代码
public class SendDemo { static String str1=null; static String str2=null; static String str3=null; static String str4=null; public static void main(String[] args) throws Exception { JFrame f = new JFrame("瑞达汽车销售订单管理系统"); f.setVisible(true); f.setBounds(400, 200, 400, 300); f.setLayout(new FlowLayout()); final Button bu1 = new Button("添加订单"); final Button bu2 = new Button("查询订单"); f.add(bu1); f.add(bu2); bu1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { zeng();
应用系统C/S风格客户端程序结构 设计
目的:理解客户应用程序应提供用户与数据库交互的界面;向 数据库服务器提交用户请求并接收来自数据库服务器的信息; 利用客户应用程序对存在于客户端的数据执行应用逻辑要求。 内容:用层次图描述客户端软件结构,以说明客户端程序由哪 些模块组成,模块与模块之间的调用、被调用和顺序关系等关 系。 实验截图:
ds.send(dp3); ds.send(dp4); JOptionPane.showMessageDialog( bu, "添 加订单成功!","消息对话框",JOptionPane.WARNING_MESSAGE); } catch (Exception e2) { // TODO: handle exception }finally{ ds.close(); } } }); // 设置窗体显示 f.setVisible(true); //创建数据 } } public class ReceiveDemo { public static String time; static String person; static String cartype; static String price; public static void main(String[] args) throws IOException, SQLException { DatagramSocket ds = new DatagramSocket(10086); //byte[]bys1=new byte[1024*1000]; while(true){ byte[]bys1=new byte[1024*1000]; DatagramPacket dp =new DatagramPacket(bys1,bys1.length); ds.receive(dp);
byte []bys2=dp.getData(); String s=new String(bys2,0,dp.getLength()); byte[]bys11=new byte[1024*1000]; DatagramPacket dp1 =new DatagramPacket(bys11,bys11.length); ds.receive(dp1); byte []bys3=dp1.getData(); String s1=new String(bys3,0,dp1.getLength()); byte[]bys111=new byte[1024*1000]; DatagramPacket dp2 =new DatagramPacket(bys111,bys111.length); ds.receive(dp2); byte []bys4=dp2.getData(); String s2=new String(bys4,0,dp2.getLength()); byte[]bys1111=new byte[1024*1000]; DatagramPacket dp3 =new DatagramPacket(bys1111,bys1111.length); ds.receive(dp3); byte []bys5=dp3.getData(); String s3=new String(bys5,0,dp3.getLength()); System.out.println(s3); time=s; person=s1; cartype=s2; price=s3; System.out.println(person); Dao.executeinsert(); } } } public class Dao {
Label l1=new Label("订单时间"); f.setBounds(400, 200, 400, 300); f.setLayout(new FlowLayout()); // 创建文本框 final TextField tf1 = new TextField(20); Label l2=new Label("购买者"); final TextField tf2 = new TextField(20); Label l3=new Label("购买车型"); final TextField tf3 = new TextField(20); Label l4=new Label("总价"); final TextField tf4 = new TextField(20); // 创建按钮 final Button bu = new Button("提交订单"); // 把组件添加到窗体 f.add(l1); f.add(tf1); f.add(Box.createHorizontalStrut(30000)); f.add(l2); f.add(tf2); f.add(Box.createHorizontalStrut(30000));//换行 f.add(l3); f.add(tf3); f.add(Box.createHorizontalStrut(30000)); f.add(l4); f.add(tf4); f.add(Box.createHorizontalStrut(30000)); f.add(bu); // 设置窗体关闭 f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } });
相关文档
最新文档