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

📄 conceptapl2.java

📁 《Java网络程序设计.rar》包括三个网络程序的源代码。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
 * @param g  the specified Graphics window
 * @see #update
 */
        
public void paint(Graphics g) {
	super.paint(g);

	// insert code to paint the applet here
}
	/**
	 * Read the input from the servlet.  <b>
	 *
	 * The servlet will return a serialized vector containing
	 * concept entries.
	 *
	 */
	protected Vector readConceptVector(ObjectInputStream theInputFromServlet)
	{
		Vector theConceptVector = null;
		ConceptstrModel cstrmdl = null;
		try
		{	        
			// read the serialized vector of concepts objects from
			// the servlet
			//
	        log("Reading data...");
	        theConceptVector = (Vector) theInputFromServlet.readObject();
                //cstrmdl = (ConceptstrModel) theInputFromServlet.readObject();
                //Vector theCstrVector = (Vector) theInputFromServlet.readObject();
                while (cstrmdl!=null)
                {
                log("OBJECT READ" + cstrmdl.getName()+ "get conceptlist...");
                //cstrmdl = (ConceptstrModel)theCstrVector.get(0);
                //theConceptVector = new Vector(cstrmdl.getConceptlist());
                }
	        log("Finished reading data.  " + theConceptVector.size() + " concepts returned");
                
	        theInputFromServlet.close();
		}
		catch (IOException e)
		{
			log(e.toString());    
		}
		catch (ClassNotFoundException e)
		{
			log(e.toString());                
		}
		catch (Exception e)
		{
			System.out.println(e);                		
		}
		
		return theConceptVector;
	}
	/**
	 *  Reads a response from the servlet.
	 */
	protected void readServletResponse(URLConnection servletConnection)
	{
		BufferedReader inFromServlet = null;
		
		try
		{
	        // now, let's read the response from the servlet.
	        // this is simply a confirmation string
	        inFromServlet = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
	        
			String str;
			while (null != ((str = inFromServlet.readLine())))
			{
				log("Reading servlet response: " + str);
			}
			
			inFromServlet.close();
		}
		catch (IOException e)
		{
		  log(e.toString());    
		}
	}
        
private URLConnection getConnectiontoServer(String connection)
{
    try{
        	        log("Connecting to servlet...");
			URL connectionURL = new URL( connection );
			URLConnection servletConnection = connectionURL.openConnection();  
	        log("Connected");

			// inform the connection that we will send output and accept input
			servletConnection.setDoInput(true);          
        	        servletConnection.setDoOutput(true);
	        
			// Don't used a cached version of URL connection.
			servletConnection.setUseCaches (false);
                log("SET REQUEST PROPERTY");         

			// Specify the content type that we will send binary data
			servletConnection.setRequestProperty
				("Content-Type", "application/octet-stream");
                        return servletConnection;
    }
    catch (Exception ex)
    {
        System.out.println(ex);
    }
    return null;
}
	/**
	 *  Register a new concept.
	 *
	 *  This is accomplished by showing a registration dialog box.  The user
	 *  enters conceptname, e-mail, proposestakeholder, etc.  This information is 
	 */
	protected void registerConcept(String aconceptID)
	{
		
	    PrintWriter outTest = null;
	    BufferedReader inTest = null;
	    ConceptModel theConcept = null;
	    URLConnection theCon = null;
            int lastIDint = Integer.valueOf(lastID).intValue();
            System.out.println("Conceptapl2: The last ID" + lastIDint);
	    // show the dialog for registering concepts
	    Addconceptdlg registerDialog = new Addconceptdlg(new javax.swing.JFrame(), true);
	    registerDialog.setVisible(true);
	    
	    // find out if user selected the register or cancel button
	    if (registerDialog.isRegisterButtonPressed())
	    {
	        theConcept = registerDialog.getConcept();
	        theConcept.setParentID(aconceptID);
	        theConcept.setConceptID(String.valueOf(lastIDint+1));
			log("Register button: " + registerDialog.isRegisterButtonPressed());
	    }
	    else
	    {
	        // the cancel button was pressed, so do nothing and return
			log("Register button: " + registerDialog.isRegisterButtonPressed());
	        return;
	    }
	    
		try
		{
			// connect to the servlet
	        // send the create concept event to the servlet using serialization
                System.out.println("new concept");
                    theCon = getConnectiontoServer(webServerConceptStr);
	        sendConceptToServlet(theCon, createAddConceptEvent("1", theConcept));
                                log("send concept to servlet");
			readServletResponse(theCon);	        
                System.out.println("update servlet");

                        
                theCon = getConnectiontoServer(webServerConceptStr );                        
	        sendConceptToServlet(theCon, createUpdateConceptEvent("1", theConcept.getConceptID()));
                                log("update servlet");
			readServletResponse(theCon);	        
                System.out.println("update concept data concept");
                        
                        
                theCon = getConnectiontoServer(webServerConceptStr );
                sendConceptToServlet(theCon, createUpdateConceptDataEvent("1", theConcept));
                                log("update to servlet");
			readServletResponse(theCon);	        
                System.out.println("update concept str");

                theCon = getConnectiontoServer(webServerConceptstrStr );
	        sendConceptToServlet(theCon, createUpdateConceptstrEvent("1"));
                                log("update conceptstr to servlet");
			readServletResponse(theCon);	        
                System.out.println("create concept str");

                        
                theCon = getConnectiontoServer(webServerConceptstrStr );
	        sendConceptToServlet(theCon, createUpdateConceptstrEvent("1"));
                                log("send concept to servlet");
			readServletResponse(theCon);	        
                         
			
			// now let's refresh the data list
			log("Refreshing the list");
			/*Vector conceptVector = getConceptList();
			displayConcepts(conceptVector); */
                       
			displayConceptTree();
			
	    }
	    catch (Exception e)
	    {
	        log(e.toString());    
                System.out.println(e.toString());
	    }
	    
	}
	/**
	 *  Sends a concept object to a servlet.  The concept object is serialized over the URL connection
	 */
	protected void sendConceptToServlet(URLConnection servletConnection, StarsEventSupport theConceptevent)
	{
		ObjectOutputStream outputToServlet = null;
		
		try
		{
	        // send the concept object to the servlet using serialization
	        log("Sending the concept to the servlet...");
	        outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
	        
	        // serialize the object
	        outputToServlet.writeObject(theConceptevent);
	        
	        outputToServlet.flush();	        
	        outputToServlet.close();
	        log("Complete.");
		}
		catch (IOException e)
		{
		  log(e.toString());    
		}
	}
        
/**
 * Insert the method's description here.
 * Creation date: (8/5/00 2:27:55 AM)
 */
public void sharePerspective(String aconceptID) 
{
	    Shareperspectivedlg registerDialog = new Shareperspectivedlg(new javax.swing.JFrame(), true);
	    registerDialog.setVisible(true);
	    
	
	}
/**
 * Called to start the applet. You never need to call this method
 * directly, it is called when the applet's document is visited.
 * @see #init
 * @see #stop
 * @see #destroy
 */
public void start() {
	super.start();

	// insert any code to be run when the applet starts here
}
/**
 * Called to stop the applet. It is called when the applet's document is
 * no longer on the screen. It is guaranteed to be called before destroy()
 * is called. You never need to call this method directly.
 * @see #init
 * @see #start
 * @see #destroy
 */
public void stop() {
	super.stop();

	// insert any code to be run when the applet is stopped here
}
public void treeDoubleClick(int aselRow, TreePath aselPath)
{
	System.out.println("doubleclick"+String.valueOf(aselRow));
	
}
public void treeRightClick(int aselRow, TreePath aselPath)
{

	System.out.println("RightClick"+String.valueOf(aselRow));
	
	/*Addconceptdlg registerDialog = new Addconceptdlg(new javax.swing.JFrame(), true);
	registerDialog.setVisible(true);*/
	Conceptnode clickedpnode = (Conceptnode)aselPath.getLastPathComponent();
	String theconceptid = clickedpnode.getConceptID();

	System.out.println("the right clicked concept id = "+theconceptid); 

	Rightcdlg rightcdlg = new Rightcdlg(new javax.swing.JFrame(), true);
	rightcdlg.setVisible(true);

	if(rightcdlg.addtochildclicked==true)
		{
			System.out.println("to add new process");
		    registerConcept(theconceptid);
		}
	else if(rightcdlg.addperspectiveclicked==true)
		{
			System.out.println("to add new perspective");
		    addPerspective();
		}

	else if(rightcdlg.shareperspectiveclicked==true)
		{
			System.out.println("to add new perspective");
		    sharePerspective(theconceptid);
		}
		
	
}
public void treeSingleClick(int aselRow, TreePath aselPath)
{

	System.out.println("SingleClick"+String.valueOf(aselRow));
}

    public ConceptEvent createAddConceptEvent(String cstrID, ConceptModel acptm) {
        ConceptEvent event = new ConceptEvent();
        System.out.println("inside createAddConceptEvent");
        event.setInfo(event.CREATE_CONCEPT, ClientUtil.getRequestID(), cstrID, acptm);       
        return event;
    }
 
    public ConceptEvent createUpdateConceptEvent(String cstrID, String conceptID) {
        ConceptEvent event = new ConceptEvent();
        System.out.println("inside createUpdateConceptEvent");
        event.setInfo(event.UPDATE_CONCEPT, cstrID, conceptID);
        return event;
    }    
    
    public ConceptEvent createUpdateConceptDataEvent(String cstrID, ConceptModel acptm) {
        ConceptEvent event = new ConceptEvent();
        System.out.println("inside createUpdateConceptDataEvent");
        event.setInfo(event.UPDATE_CONCEPT_DATA, ClientUtil.getRequestID(), cstrID, acptm);       
        return event;
    }

    public ConceptEvent createDeleteConceptEvent(String cstrID, ConceptModel acptm) {
        ConceptEvent event = new ConceptEvent();
        System.out.println("inside createAddConceptEvent");
        event.setInfo(event.DELETE_CONCEPT, ClientUtil.getRequestID(), cstrID, acptm);       
        return event;
    }
//concept structure events    
    
    public ConceptstrEvent createAddConceptstrEvent(String cstrID, ConceptstrModel cstrmdl) {
        ConceptstrEvent event = new ConceptstrEvent();
        System.out.println("inside createAddConceptstrEvent");
        event.setInfo(event.CREATE_CONCEPTSTR, cstrID, cstrmdl);       
        return event;
    }
    public ConceptstrEvent createUpdateConceptstrEvent(String cstrID) {
        ConceptstrEvent event = new ConceptstrEvent();
        System.out.println("inside createUpdateConceptstrEvent");
        event.setInfo(event.UPDATE_CONCEPTSTR, cstrID);       
        return event;
    }
    public ConceptstrEvent createUpdateConceptstrDataEvent(String cstrID, ConceptstrModel cstrmdl) {
        ConceptstrEvent event = new ConceptstrEvent();
        System.out.println("inside createUpdateConceptstrDataEvent");
        event.setInfo(event.UPDATE_CONCEPTSTR_DATA, cstrID, cstrmdl);       
        return event;
    }

    public ConceptstrEvent createDeleteConceptstrEvent(String cstrID) {
        ConceptstrEvent event = new ConceptstrEvent();
        System.out.println("inside createAddConceptstrEvent");
        event.setInfo(event.DELETE_CONCEPTSTR, cstrID);       
        return event;
    }
    
    public ConceptstrEvent createRestructConceptstrEvent(String cstrID) {
        ConceptstrEvent event = new ConceptstrEvent();
        System.out.println("inside createRestructConceptstrEvent");
        event.setInfo(event.RESTRUCT_CONCEPTSTR, cstrID);       
        return event;
    }
    
    public ConceptstrEvent createRestructConceptstrDataEvent(String cstrID, String aupdateConceptID, Collection aupdateConceptList) {
        ConceptstrEvent event = new ConceptstrEvent();
        System.out.println("inside createAddConceptstrEvent");
        event.setInfo(event.RESTRUCT_CONCEPTSTR_DATA, cstrID, aupdateConceptID, aupdateConceptList);       
        return event;
    }    
}

⌨️ 快捷键说明

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