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

📄 pickgui.java

📁 这是一个买卖系统,一个模拟的系统,根据下订单,看订单,买,等功能
💻 JAVA
字号:
package Clients;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import Catalogue.*;

import Middle.*;


/**
 * Implements the GUI for the Pick up Client.
 * @author 
 * @version 2.0 February 2008
 */

class PickGUI
{
 
  private static final String GETPICK   = "Get to Pick";
  private static final String PICKED ="Picked";
 
  private static final int H = 680;       // Height of window pixels
  private static final int W = 400;       // Width  of window pixels

  private JLabel      theAction  = new JLabel();
  private JButton     theBtGetPick = new JButton(GETPICK);
  
  private JLabel	  lblOrderNo = new JLabel();
  private JTextField  theInput   = new JTextField();
  private JTextArea   theOutput  = new JTextArea();
  
  private JScrollPane theSP      = new JScrollPane();
  
  private JButton     theBtPicked = new JButton(PICKED);
  
  private JLabel      theShow  = new JLabel();
  private JScrollPane theSPShow      = new JScrollPane();
  private JTextArea   theOutputShow  = new JTextArea();
  private Transaction     theCB        = new Transaction();
  private StockReadWriter theStock     = null;
  private OrderProcessing theOrder     = null;

 
  public PickGUI(  RootPaneContainer rpc, MiddleFactory mf  )
  {
    try                                           
    {      
      theStock = mf.makeStockReadWriter();        // DataBase access
      theOrder = mf.makeOrderProcessing();        // Process order
    } catch ( Exception e )
    {
      System.out.println("Exception: " + e.getMessage() );
    }
    Container cp         = rpc.getContentPane();    // Content Pane
    Container rootWindow = (Container) rpc;         // Root Window
    cp.setLayout(null);                             // No layout manager
    rootWindow.setSize( W, H );                     // Size of Window

    Font f = new Font("Monospaced",Font.PLAIN,12);  // Font f is

    theAction.setBounds( 80, 0 , 300, 60 );       // Message area
    theAction.setText( "" );                        // Blank
    cp.add( theAction );                            //  Add to canvas
    
    theBtGetPick.setBounds( 30, 25+60*0, 100, 40 );    // Check Button
    theBtGetPick.addActionListener( theCB );          // Listener
    cp.add( theBtGetPick );                           //  Add to canvas

   
    theSP.setBounds( 30, 80, 310, 200 );          // Scrolling pane
    theOutput.setText( "" );                        //  Blank
    theOutput.setFont( f );                         //  Uses font  
    cp.add( theSP );                                //  Add to canvas
    theSP.getViewport().add( theOutput );           //  In TextArea
    
    
    lblOrderNo.setBounds(30, 300, 60, 40);			//Order Number label
    lblOrderNo.setText("Order No :");				//default message
    cp.add(lblOrderNo);								//Add to canvas					
    
    theInput.setBounds( 100, 300, 150, 40 );         // Input Area
    theInput.setText("");                           // Blank
    cp.add( theInput );                             //  Add to canvas
    
    theBtPicked.setBounds( 260, 300, 80, 40 );   	// Clear Button
    theBtPicked.addActionListener( theCB );         //  Listener
    cp.add( theBtPicked );                          //  Add to canvas
    
    Font g = new Font("Monospaced",Font.BOLD, 16);    //text font

    theShow.setBounds( 80, 340 , 250, 60 );        	// Message area
    theShow.setText( "Waiting to be Picked Orders" );		//default message
    theShow.setFont( g ); 
    cp.add( theShow );                             		 //  Add to canvas
      
    theSPShow.setBounds(30, 390, 310, 250 );          // Scrolling pane
    theOutputShow.setText( "" );                        //  Blank
    theOutputShow.setFont( f );                         //  Uses font  
    cp.add( theSPShow );                                //  Add to canvas
    theSPShow.getViewport().add( theOutputShow );           //  In TextArea

    
    rootWindow.setVisible( true );                  // Make visible
  }			//end of constructor


  class Transaction implements ActionListener       // Listener
  {
    public void actionPerformed( ActionEvent ae )   // Interaction
    {
      if ( theStock == null )						//check connection
      {
        theAction.setText("No connection");
        return;                                     // No connection
      }
      String actionIs = ae.getActionCommand();      // For Button
      try
      {
   
        if ( actionIs.equals( GETPICK ) )             // Button Get To Pick
        { 
        	
    	    	SoldBasket sb = theOrder.getOrderToPick();  // get the first Order needed to pick.
    	    	
    	         
            theOutput.setText( "" );                 //  clear
            if (sb==null)
            {							//No order is waiting to be picked            
            	theOutput.append ("No Waiting Orders!!");         	//message
            }
            else
            {			//there are orders waiting to be picked
            theOutput.append( sb.details());  //  Display order details
            int sbNo = sb.orderNo();		//get order number
            String preInput ="";	//convert integer to String
	        preInput +=sbNo;	
            theInput.setText((preInput) );		//set the picked number input area text
            }
     
        }	//end of if (GETPICK)	
   
        if ( actionIs.equals( PICKED ) )             // Button Picked
        { 
            
        	String pn = theInput.getText().trim();		//get order number in the input area
        	if(!pn.equals(""))							//order no is not empty
        	{			
        	int inputOrderNo = Integer.parseInt(pn);
            theOutput.setText( "" );                 //  clear
            theOutput.append (theOrder.informOrderPicked(inputOrderNo));
            theInput.setText("");   //clear Input text field
        	}
        	
        	else
        	{
        	theOutput.setText("");		//clear
        	theOutput.append("Please enter a valid Order No.");  //request input
        	theInput.setText("");    //clear 
        	}
        }	//end of if (PICKED)
        	 theInput.requestFocus();                     // theInput has Focus
        
      }   //end of try
   
      catch ( OrderException e )                     // Error
      {                                              //  Of course
        theOutput.append( "Fail Order process:" +    //   Should not
                            e.getMessage() + "\n" ); //  happen
      }
    }	//end of method actionPerformed		
  }		//end of class Transaction
  
  public void createThread(){		//create a thread  
		Thread tr = new Thread ( new ShowPick());
		tr.start();			//start thread and wait to run
		
	}
		
			
public class ShowPick implements Runnable {    	//thread action
			
	 		public void run(){
	 		 try{	
					while (true)  //keep running
					{	
						theOutputShow.setText("");
						SoldBasket sb = theOrder.getOrderToPick();  //get the first waiting order 
						if(sb==null){  							//no waiting to pick order
							theOutputShow.append(" No waiting to be picked orders!!");   //message
						}
						else{									//there is at least one order waiting to be picked
						theInput.setText("");					//clear
						theOutputShow.setText("");				//clear
						theOutputShow.setText(theOrder.getWaitingList());    //display all waiting to be picked order no.
						
						theOutputShow.append(("\n"+sb.details()));		//display the first order details

			            String s ="";
			            int sNo = (theOrder.getOrderToPick()).orderNo();
			            s +=sNo;
			            theInput.setText(s); 		//set input area to the first waiting to be picked order no. 
			           
 	 					
						}
 	 					Thread.sleep(1*1000);  //sleep for 1 second to let other threads have chance to run
						//update information at least every 1 second
	 				}
				  }
			   
				
	 			catch(Exception ex){
	 				ex.printStackTrace();
	 			}
	 		}	//end of method run 
	}	//end of class ShowPick
 
}		//end of class PickGUI

⌨️ 快捷键说明

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