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

📄 collectgui.java

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

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


/**
 * Implements the GUI for the Collection desk Client.
 * @author  
 * @version 1.0
 */

class CollectGUI
{
 
  private static final String COLLECTED ="Collected";
 
  private static final int H = 360;       // Height of window pixels
  private static final int W = 430;       // Width  of window pixels

  private JLabel      theAction  = new JLabel(); 
  private JLabel	  lblOrderNo = new JLabel();
  private JTextField  theInput   = new JTextField();
  private JTextArea   theOutput  = new JTextArea();
  private JScrollPane theSP      = new JScrollPane();
  private JButton     theBtCollected = new JButton(COLLECTED);

  private Transaction     theCB        = new Transaction();
  private StockReadWriter theStock     = null;
  private OrderProcessing theOrder     = null;

 
  public CollectGUI(  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
    Font g = new Font ("Monospaced", Font.BOLD, 18);
   
    theAction.setBounds( 85, 10 , 270, 20 );       // Message area
    theAction.setText( "" );  						// Blank
    theAction.setFont(g);
    cp.add( theAction );                            //  Add to canvas
    
    theSP.setBounds( 75, 100, 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(5, 40, 60, 40);			//Order no label
    lblOrderNo.setText("Order No :");				//text
    cp.add(lblOrderNo);								//Add to canvas
    
    
    theInput.setBounds( 75, 40, 180, 40 );         // Input Area
    theInput.setText("");                           // Blank
    cp.add( theInput );                             //  Add to canvas
    
    theBtCollected.setBounds( 295, 40, 90, 40 );   // Clear Button
    theBtCollected.addActionListener( theCB );         //  Listener
    cp.add( theBtCollected );                          //  Add to canvas

    
    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
      } 	//end if
      String actionIs = ae.getActionCommand();      // Button
      try
      {
           
        if ( actionIs.equals( COLLECTED ) )             // Button Collect
        { 
        	
            String pn = theInput.getText().trim();		//get order no from input
            if(!pn.equals(""))
            {						//input is not empty
        	int inputOrderNo = Integer.parseInt(pn);	//convert string to integer
       
            theOutput.setText( "" );                 //  clear
            theOutput.append (theOrder.informOrderColected(inputOrderNo));	//display message
            theInput.setText("");   //clear Input text field
            }
            else		//input is empty
            {
            	theOutput.setText("");			//clear
            	theOutput. append("Please enter order No.");  //request input orde no.
            	theInput.setText("");			//clear input area
            }
        }
  
        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

}	//end of CollectGUI

⌨️ 快捷键说明

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