⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mall.java

📁 一个基于局域网的c/s模式网上购物系统,功能比较全面.数据库为Access.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
  					}
  					
 					else if(!basketStatus.getValueAt(basketStatus.getSelectedRow(),4).equals("unconfirmed"))
  					{
  						JOptionPane.showMessageDialog(null,"       该商品已处理完成!","更改失败",3);
  					}
  			
  					else
  					{
  						int i =basketStatus.getSelectedRow();
  						if(basket.cancel(i,in,out))
  						{
  							JOptionPane.showMessageDialog(null,"    已取消购入商品:"+basketStatus.getValueAt(i,1),"取消成功",1);
  							basketStatus.setValueAt("cancel",i,4);
  						}
  					}
				}
			});
			buttonPanel.add(b);
			
			contentPane.add(p1,BorderLayout.CENTER);
    		contentPane.add(buttonPanel,BorderLayout.SOUTH);
    		jd.setBounds(262,250,500,250);
    		jd.setVisible(true);
		}
	}
	
	///////////////////////开设店铺对话框////////////
	private class OpenShopDialog
	{
		private JDialog d;
		private JTextField shopName;
		private JTextArea shopInfo;
		private String shopType;
		private JComboBox cb;
		
		OpenShopDialog()
		{
			shopType = "computer";
			
			d = new JDialog(f,"申请开店",true);
			Container contentPane = d.getContentPane();
			
			GridBagConstraints gbc = new GridBagConstraints();
	     	gbc.anchor = GridBagConstraints.WEST; 
	     	gbc.insets = new Insets(2,2,2,2); 
		
			JPanel selectPanel = new JPanel();
   	 		selectPanel.setLayout(new GridLayout());
   	 		String[] type = {"computer","dress","sports","food","book","electric","game"};
   	 		cb = new JComboBox(type);
   		 	cb.setEditable(true);
   		 	ComboBoxEditor editor = cb.getEditor();
		  	cb.configureEditor(editor,"computer");
   	 		cb.addItemListener(new ItemListener(){
   	 			public void itemStateChanged(ItemEvent e)
   	 			{
   	 				if (e.getStateChange()==e.SELECTED)
  		  			{
   	 					shopType = (String)e.getItem();
   	 				}
   	 			}
      
   	 		});
   	 		
   	 		selectPanel.add(cb);

       	 	JPanel stextPanel = new JPanel();
   		  	stextPanel.setLayout(new GridBagLayout());
  
  		   	JLabel l1 = new JLabel("店铺名称:");
   		  	shopName = new JTextField(20); 
 
   		  	gbc.gridy = 0;
    	 	gbc.gridx = 0;
     		stextPanel.add(l1,gbc);
     		gbc.gridx = 1;
     		stextPanel.add(shopName,gbc);
     	
    	 	JLabel l2 = new JLabel("店铺简介:");
      		shopInfo = new JTextArea(4,20);
      		shopInfo.setLineWrap(true);
      		gbc.gridy = 1;
     		gbc.gridx = 0;
     		stextPanel.add(l2,gbc);
     		gbc.gridx = 1;
     		stextPanel.add(new JScrollPane(shopInfo),gbc);
     		shopInfo.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
     		
     		JPanel buttonPanel = new JPanel();
  			JButton b = new JButton("确定");
  			b.addActionListener(new ActionListener(){
  				public void actionPerformed(ActionEvent e)
  				{
  					boolean legal = true;
  					
  					if(shopInfo.getText().indexOf('\n')!=-1)
      	 			{
      	 			legal = false;
      	 			JOptionPane.showMessageDialog(null,"        简介中不允许回车!","填写信息不正确",2);	
       	 			}
       	 			
 					char[] temp = shopType.toCharArray();
      	 			for(int i=0;i<shopType.length();i++)
      	 			{
      	 				if(!((temp[i]>='a'&&temp[i]<='z') || (temp[i]>='A'&&temp[i]<='Z') || temp[i]==' '))
      	 				{
      	 					legal = false;
      	 					JOptionPane.showMessageDialog(null,"     店铺名填写不符合规则!","填写信息不正确",2);
      	 					return;
				 		}
      	 			}
      	 			      	 			
      	 			if(legal)
      	 			{
      	 				try
      	 				{
      	 					out.println("OPENSHOP");
      	 					out.println(customer.getId());
      	 					out.println(shopName.getText());
      	 					out.println(shopType);
           					out.println(shopInfo.getText());
           					
           					String result = in.readLine();
           						
           					if(result.equals("SUCCESS"))
           					{	
           						JOptionPane.showMessageDialog(null,"已成功开设店铺: "+shopName.getText(),"申请成功",1);
	       						d.dispose();
           					}
	
	           				else if(result.equals("SHOPFAILURE"))
   	        				{
   	        					JOptionPane.showMessageDialog(null," 该店铺名已存在,请重新选择店铺名!","申请失败",0);
   	        				}
   	        				
   	        				else
   	        				{
   	        					JOptionPane.showMessageDialog(null,"服务器更新失败!","申请失败",0);
   	        				}
   	        			}catch(Exception ex){}
   	   	 			}
      	 		}
  			});
  			buttonPanel.add(b);
  			
  			b = new JButton("取消");
  			b.addActionListener(new ActionListener(){
  				public void actionPerformed(ActionEvent e)
  				{
  					d.dispose();
  				}
  			});
  			buttonPanel.add(b);
  			
  			JPanel p = new JPanel();
  			p.setLayout(new GridBagLayout());
  		
  		
  			gbc.gridx = 0;
  			gbc.gridy = 0;
  			p.add(new JLabel("请选择店铺类型:"),gbc);
  			
	     	gbc.gridx = 1;
	     	gbc.gridwidth = GridBagConstraints.REMAINDER;
     		p.add(selectPanel,gbc);
     		gbc.gridx = 0;
     		gbc.gridy = 1;
     		p.add(stextPanel,gbc);
     		gbc.gridy = 2;
     		gbc.anchor = GridBagConstraints.CENTER;
     		p.add(buttonPanel,gbc);
     		p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
  	                "请填写店铺相关信息",TitledBorder.CENTER,TitledBorder.TOP));
     		
     		contentPane.add(p);
     		d.setBounds(347,230,330,250);
	        d.setResizable(false);
	        d.setVisible(true);
        
			}
		}
	//////////////////////构造函数///////////////////
	Mall(Customer c,final Socket socket)
	{
		this.socket = socket;
		this.customer = c;
		selectType = "all";
		shopInfo = new String[100];
		basket = new ShoppingBasket(customer.getUserName());
		
		try
    	{
    		in = 
		     new BufferedReader(
	          new InputStreamReader(
	           socket.getInputStream()));
	           
    	   	out =
	    	 new PrintWriter(
    		  new BufferedWriter(
     		   new OutputStreamWriter(
       			socket.getOutputStream())),true);

   		}catch(Exception e)
       	{
      		System.out.println(e);
       	}
       	
       	/////////////////////////////////////////////////////////////////
		//                          界面                               //
       	f = new JFrame("Shoping Mall");
       	
		Container contentPane=f.getContentPane();
       	
       	////////////////////////个人相关///////////////////////////////
       	JPanel p1 = new JPanel();
       	p1.setLayout(new GridBagLayout());
       	p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
	  	                "个人管理选项",TitledBorder.CENTER,TitledBorder.TOP));
   
       	GridBagConstraints gbc = new GridBagConstraints();
	    gbc.anchor = GridBagConstraints.WEST; 
	    gbc.insets = new Insets(5,11,5,11);
	    
	    JLabel l1 = new JLabel("用户名:");
	    gbc.gridx=0;
	    gbc.gridy=0;
	    p1.add(l1,gbc);
	    
	    user = new JTextField(6);
	    gbc.gridx=1;
	    user.setEditable(false);
	    user.setText(customer.getUserName());
	    p1.add(user,gbc);
	    
	    JButton b = new JButton("  修改个人信息  ");
	    b.addActionListener(this);
	    gbc.gridx=0;
	    gbc.gridy=3;
	    gbc.gridwidth = GridBagConstraints.REMAINDER;
	    p1.add(b,gbc);
	    
	    b = new JButton("   申  请   开  店   ");
	    b.addActionListener(this);
	    gbc.gridx=0;
	    gbc.gridy=4;
	    gbc.gridwidth = GridBagConstraints.REMAINDER;
	    p1.add(b,gbc);
	    
	    JLabel l2 = new JLabel("存款余额:");
	    gbc.gridx=0;
	    gbc.gridy=1;
	    p1.add(l2,gbc);
	    
	    amount = new JTextField(6);
	    gbc.gridx=1;
	    amount.setEditable(false);
	    amount.setText(customer.checkBalance(in,out)+"");
	    p1.add(amount,gbc);

       	b = new JButton("存款");
       	b.addActionListener(this);
       	gbc.gridx=0;
       	gbc.gridy=2;
       	p1.add(b,gbc);

       	b = new JButton("取款");
       	b.addActionListener(this);
       	gbc.gridx=1;
       	gbc.gridy=2;
       	gbc.gridwidth = GridBagConstraints.REMAINDER;
       	p1.add(b,gbc);
       	
       	/////////////////////////////大厅功能相关/////////////////////////////
       	JPanel p2 = new JPanel();
       	p2.setLayout(new GridLayout(6,1));
       	p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
	  	                "大厅功能选项",TitledBorder.CENTER,TitledBorder.TOP));
       	
       	JPanel checkPanel = new JPanel();
       	openbox = new JCheckBox("只显示正在营业的店铺",false);
       	openbox.addItemListener(this);
       	checkPanel.add(openbox);
       	
       	JPanel cbPanel = new JPanel();
       	String[] type = {"all","computer","dress","sports","food","book","electric","game"};
   	 	cb = new JComboBox(type);
   	 	cb.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.DARK_GRAY,0),
  	                "请选择店铺类型",TitledBorder.CENTER,TitledBorder.TOP));
    	cb.setEditable(false);
   	 	ComboBoxEditor editor=cb.getEditor();
	  	cb.configureEditor(editor,"all");
   	 	cb.addItemListener(this);
       	cbPanel.add(cb);
	    
	    
	    JPanel buttonPanel1 = new JPanel();
	    b = new JButton("       刷新      ");
       	b.addActionListener(this);
       	buttonPanel1.add(b);
       	
       	JPanel buttonPanel2 = new JPanel();
       	b = new JButton("  进入商店  ");
       	b.addActionListener(this);
       	buttonPanel2.add(b);
       	
       	JPanel buttonPanel3 = new JPanel();
       	b = new JButton("检查购物车");
       	b.addActionListener(this);
       	buttonPanel3.add(b);
       	
       	JPanel buttonPanel4 = new JPanel();
       	b = new JButton("       退出      ");
       	b.addActionListener(this);
       	buttonPanel4.add(b);
       	
       	p2.add(checkPanel);
       	p2.add(cbPanel);
       	p2.add(buttonPanel1);
       	p2.add(buttonPanel2);
       	p2.add(buttonPanel3);
       	p2.add(buttonPanel4);

		
		/////////////////////////////店铺列表相关/////////////////////////////
       	String[] name = {"店铺种类","店铺名","店铺主人","状态"};
       	defaultModel = new MyTable(name,0);
       	
       	table=new JTable(defaultModel);
       	table.addMouseListener(new MouseAdapter()
       	{
       		public void mouseClicked(MouseEvent e)
       		{
       			if(e.getClickCount()>=2)
       			{
       				if(table.getValueAt(table.getSelectedRow(),3).equals("closed"))
       				{
       					JOptionPane.showMessageDialog(null,"该店铺没有营业,请选择正在营业店铺!","进入错误",2);
  					}
  					
  					else
					{
						String shopName = (String)table.getValueAt(table.getSelectedRow(),1);
						new Shop(shopName);
					}
	  			}
	  			
	  			else if (e.getClickCount()==1)
	  			{
	  				setStoreInfo();
	  			}
        	}
       	});
       	
       	table.addKeyListener(new KeyListener()
       	{
       		public void keyTyped(KeyEvent e)
  			{
  				
  			}
  	
  			public void keyReleased(KeyEvent e)
  			{
  				if(e.getKeyCode()==KeyEvent.VK_UP || e.getKeyCode()==KeyEvent.VK_DOWN)
  				{
  					setStoreInfo();
  				}
  			}
  			
  			public void keyPressed(KeyEvent e)
  			{
  				if(e.getKeyCode()==KeyEvent.VK_ENTER)
  				{
  					if(table.getValueAt(table.getSelectedRow(),3).equals("closed"))
       				{
       					JOptionPane.showMessageDialog(null,"该店铺没有营业,请选择正在营业店铺!","进入错误",2);
  					}
  					
  					else
					{
						String shopName = (String)table.getValueAt(table.getSelectedRow(),1);
						new Shop(shopName);
					}
  				}
  			}
       	});
       	
       	out.println("CREATMALL");
       	
       	try
       	{
       		String info = in.readLine();
       		int x=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -