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

📄 mall.java

📁 一个基于局域网的c/s模式网上购物系统,功能比较全面.数据库为Access.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
       		while(!info.equals("OVER"))
       		{
       			defaultModel.addRow(new Vector());
       			for(int i=0;i<4;i++)
       			{
       				table.setValueAt(info,x,i);
       				info = in.readLine();
       			}
       			shopInfo[x] = info;
       			info = in.readLine();
       			
       			x++;
       		}
       	}catch(IOException e){}
       	

       	table.setPreferredScrollableViewportSize(new Dimension(300, 80));
       	table.setBackground(new Color(170,210,255));
        JScrollPane sp = new JScrollPane(table);
        sp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK,2),
  	                "店铺列表",TitledBorder.CENTER,TitledBorder.TOP));
  	                
  	                
  	    broadcast = new JTextArea(5,50);
  	    broadcast.setEditable(false);
  	    broadcast.setLineWrap(true);
  	    broadcast.setBackground(new Color(238,238,238));
  	    JScrollPane sp1 = new JScrollPane(broadcast);
        sp1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.red,2),
  	                "系统公告",TitledBorder.CENTER,TitledBorder.TOP));
  	                

       	JPanel storePanel = new JPanel();
       	storePanel.setLayout(new GridBagLayout());
    	gbc.anchor = GridBagConstraints.WEST; 
    	gbc.insets = new Insets(2,2,2,2); 
    	
		storePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2),
		  	                "店铺信息:",TitledBorder.CENTER,TitledBorder.TOP));
		
		s0 = new JLabel("       店铺状态");
		JLabel s1 = new JLabel("店铺名:");        
		JLabel s2 = new JLabel("店主:");   
		JLabel s3 = new JLabel("店铺类型:");   
		JLabel s4 = new JLabel("店铺简介:");   
	   
    	storeName = new JTextField(12);
    	storeName.setEditable(false);
		storeOwner = new JTextField(12);
		storeOwner.setEditable(false);
		storeType = new JTextField(12);
		storeType.setEditable(false);
			
		storeInfo = new JTextArea(10,12);
		storeInfo.setBackground(new Color(238,238,238));
		storeInfo.setLineWrap(true);
		storeInfo.setEditable(false);

		gbc.gridy=0;		
		gbc.gridx=0;
		storePanel.add(s0,gbc);
		gbc.gridy=1;
	    storePanel.add(s1,gbc);
	    gbc.gridy=2;
	    storePanel.add(storeName,gbc);
   		gbc.gridy=3;
		storePanel.add(s2,gbc);
  		gbc.gridy=4;
 		storePanel.add(storeOwner,gbc);
 		gbc.gridy=5;
 		storePanel.add(s3,gbc);
  		gbc.gridy=6;
 		storePanel.add(storeType,gbc);
		gbc.gridy=7;
		storePanel.add(s4,gbc);
		gbc.gridy=8;
		storePanel.add(new JScrollPane(storeInfo),gbc);
       	
       	
       	JPanel info = new JPanel();
       	info.setLayout(new BorderLayout());
       	info.add(sp,BorderLayout.CENTER);
       	info.add(storePanel,BorderLayout.EAST);
       	
       	JPanel right = new JPanel();
       	right.setLayout(new BorderLayout());
       	right.add(info,BorderLayout.CENTER);
       	right.add(sp1,BorderLayout.NORTH);
       	
       	JPanel left = new JPanel();
       	left.setLayout(new BorderLayout());
       	left.add(p1,BorderLayout.NORTH);
       	left.add(p2,BorderLayout.CENTER);
       	
       	JPanel center = new JPanel();
       	center.setLayout(new BorderLayout());
       	
       	center.add(left,BorderLayout.WEST);
       	center.add(right,BorderLayout.CENTER);
       	
       	JLabel pic = new JLabel(new ImageIcon(".\\pic.jpg"));
       	        
       	contentPane.add(pic,BorderLayout.NORTH);
       	contentPane.add(center,BorderLayout.CENTER);
       	f.setBounds(0,0,1024,740);

       	f.setVisible(true);
       	f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
       	f.addWindowListener(new WindowAdapter(){
   	   		public  void windowClosing(WindowEvent e){
 			try
 			{
  	 			if(basket.allDisposed())
  	 			{
  	 				
 					logout();
 					in.close();
 					out.close();
 					socket.close();
 					f.dispose();
 				}
 				
 				else
 				{
 					JOptionPane.showMessageDialog(null,"尚有没有确认过的定单,请处理完后再退出","退出失败",2);
 					new BasketConfirm();
 				}
 				
 			}catch(IOException ex){} 	   	
   	   		}	
     	});
     	
     	new SystemBroadcast();

	}
	
	//////////////////////事件处理//////////////////
	public void actionPerformed(ActionEvent e)
	{
		String cmd=e.getActionCommand();
  	
  		if (cmd.equals("存款"))
  		{
  			String str = JOptionPane.showInputDialog(null,"请输入存款额:","0.0");
  			if(str!=null)
  			{
  				try
  				{
  					double Amount = Double.parseDouble(str);
  					if(Amount<99999)
  					{
  						customer.deposit(Amount,in,out);
  						amount.setText(customer.checkBalance(in,out)+"");
  					}
  					else
  					{
  						JOptionPane.showMessageDialog(null,"虽说这是虚拟的,但您也太贪了吧-_-","失败",2);
  					}
  				}
  				catch(Exception ex)
  				{
  					JOptionPane.showMessageDialog(null,"             存款失败","失败",2);
  				}
  			}
  	 	}
  	 	
  	 	else if (cmd.equals("取款"))
  		{
  			String str = JOptionPane.showInputDialog(null,"请输入取款额:","0.0");
  			if(str!=null)
  			{
  				try
  				{
  					double Amount = Double.parseDouble(str);
  					if(Amount<=Double.parseDouble(amount.getText()))
  					{
  						customer.withdraw(Amount,in,out);
  						amount.setText(customer.checkBalance(in,out)+"");
  					}
  					else
  					{
  						JOptionPane.showMessageDialog(null,"          您的余额不足!","失败",2);
  					}
  				}
  				catch(Exception ex)
  				{
  					JOptionPane.showMessageDialog(null,"             取款失败","失败",2);
  				}
  			}
  	 	}
  	 	
  	 	else if(cmd.equals("  修改个人信息  "))
  	 	{
  	 		new UserEditDialog(f,customer,in,out);
  	 		
  	 		try
  	 		{
  	 			out.println("VIEW");
  	 			out.println(customer.getId());
  	 			customer.setUserName(in.readLine());
  	 			customer.setPassword(in.readLine());
  	 			customer.setAccount(Integer.parseInt(in.readLine()));
  	 			user.setText(customer.getUserName());
  	 		}catch(Exception ex){}
  	 	}
  	 	
  	 	else if(cmd.equals("   申  请   开  店   "))
  	 	{
  	 		if(!customer.isMerchant())
  	 		{
  	 			new OpenShopDialog();
  	 		}
  	 		
  	 		else
  	 		{
  				JOptionPane.showMessageDialog(null,"   您已经拥有一个店铺了!","申请失败",0);
  			}
  	 	}
  	 	
  	 	else if (cmd.equals("       刷新      "))
  	 	{
  	 		reflash();
  	 	}
  	 	
  	 	
  	 	else if (cmd.equals("  进入商店  "))
  	 	{
  	 		if(table.getSelectedRow()==-1)
  			{
  				JOptionPane.showMessageDialog(null,"请从右侧的列表中选择一家店铺!","进入错误",2);
  			}
  			
  			else
  			{
  				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 (cmd.equals("检查购物车"))
  	 	{
  	 		new BasketConfirm();
  	 	}
  	 	
  	 	else if (cmd.equals("       退出      "))
  	 	{
  	 		try
 			{
  	 			if(basket.allDisposed())
  	 			{
  	 				
 					logout();
 					in.close();
 					out.close();
 					socket.close();
 					f.dispose();
 					System.exit(0);
 				}
 				
 				else
 				{
 					JOptionPane.showMessageDialog(null,"尚有没有确认过的定单,请处理完后再退出","退出失败",2);
 					new BasketConfirm();
 				}
 				
 			}catch(IOException ex){} 
  	 	}
	}
	
	public void itemStateChanged(ItemEvent e)
    {
  		  if(e.getSource()==cb)
  		  {
  		  	if(e.getStateChange() == e.SELECTED)
  		  	{
  		  		selectType = (String)e.getItem();
  		  		reflash();
  		  	}
  		  }
  	  		  
  		  else if (e.getSource()==openbox)
  		  {
  		  	if(openbox.isSelected())
  		  	{
  		  		open = true;
  		  		reflash();
  		  	}
  		  	else 
  		  	{
  		  		open = false;
  		  		reflash();
  		  	}
  		  }
  	}
	
	public void logout()
	{
		try
		{	out.println("LOGOUT");
			out.println(customer.getUserName());
			out.println(customer.getId());
			
			out.println("END");
			
			in.close();
			out.close();
			this.socket.close();
		}catch(IOException e){}
	}
	
	public void setStoreInfo()
	{
		storeName.setText((String)table.getValueAt(table.getSelectedRow(),1));
	  	storeOwner.setText((String)table.getValueAt(table.getSelectedRow(),2));
	  	storeType.setText((String)table.getValueAt(table.getSelectedRow(),0));
	  	storeInfo.setText(shopInfo[table.getSelectedRow()]);
	  	
	  	if(table.getValueAt(table.getSelectedRow(),3).equals("open"))
	  	{
	  		s0.setText("       店铺状态:营业中!");
	  		s0.setForeground(Color.red);
	  		storeName.setForeground(Color.BLACK);
	  		storeOwner.setForeground(Color.BLACK);
	  		storeType.setForeground(Color.BLACK);
	  		storeInfo.setForeground(Color.BLACK);
	  	}
	  	else
	  	{
	  		s0.setText("       店铺状态:关闭");
	  		s0.setForeground(Color.LIGHT_GRAY);
	  		storeName.setForeground(Color.LIGHT_GRAY);
	  		storeOwner.setForeground(Color.LIGHT_GRAY);
	  		storeType.setForeground(Color.LIGHT_GRAY);
	  		storeInfo.setForeground(Color.LIGHT_GRAY);
	  	}
	}
	
	public void reflash()
	{
		while(defaultModel.getRowCount()!=0)
  	 		{
  	 			defaultModel.removeRow(0);
  	 		}
 	 		
			out.println("CREATMALL");
       	
       		try
       		{
       			String info = in.readLine();
       			int x=0;
       			while(!info.equals("OVER"))
       			{
       				if(info.equals(this.selectType) || this.selectType.equals("all"))
       				{
       					defaultModel.addRow(new Vector());
       					for(int i=0;i<4;i++)
       					{
       						table.setValueAt(info,x,i);
       						info = in.readLine();
       					}
       					shopInfo[x] = info;
		       			info = in.readLine();
       					
       					String status = (String)table.getValueAt(x,3);
       					if(status.equals("closed") && open)
       					{
       						defaultModel.removeRow(x);
       						x--;
       					}
       					x++;
       				}
       				else
       				{
       					for(int i=0;i<5;i++)
       					{
       						info = in.readLine();
       					}
       				}
       			}
       		}catch(IOException ex){}
       			
       			table.revalidate();
	}
}

⌨️ 快捷键说明

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