Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 24th, 2009, 10:24 AM
cblue cblue is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 1 cblue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 30 sec
Reputation Power: 0
Question Problem with my animation applet

hello,

I am trying to simulate a network protocol with java.
There is a sender row and a receiver row. Sender has a window which packets inside that are ready to be sent.
I don't have problem with algorithm and these kind of staffs. I can work them out if I the graphic thing works.

I will put a brief version of program here (other things are not necessary to be posted). The main problem is that I can not access packets in sender array. The line which I commented if I uncomment it the paint method won't work!!!!

Code:


import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class test extends Applet implements ActionListener, Runnable
{
    Button start=new Button("Start");
    Button stop=new Button("Stop"); 
    int base;
    int nextSeq;
    int windowSizeValue = 5;
    int messageSizeValue = 12;

    int packetHeight = 15;
    int packetWidth = 15;
    int senderX = 100;
    int senderY = 150;
    int recieverY = 300;
    int interval;
    Packet sender[];
    Thread animThread;
    Dimension offD;
    Image offImage;
    Graphics offG;
    boolean keepDrawing = false;
    String message;
    public void init()
    {

        
        try
        {

        }
        catch (Exception e)
        {
        }
        

        add(start);
        start.addActionListener(this);
        add(stop);
        stop.addActionListener(this);

        base = 0;
        nextSeq = 0;
        Thread animThread = null;
        sender = new Packet[windowSizeValue];
    }
     public void actionPerformed(ActionEvent e)
     {
         if (e.getSource() == start)
         {
                          
             start.setEnabled(false);

             repaint();
             this.startAnim();
            }
         else if (e.getSource() == stop)
         {              
           start.setEnabled(true);
           this.stopAnim();
         }
    }

        public void startAnim()
        {
            if (animThread == null)
            animThread = new Thread(this);
            keepDrawing = true;
            animThread.start();
            for (int i=0; i<messageSizeValue; i++)
            {
                sender[i] = new Packet(0 , 0);
            }
            
            
            
        }
        public void stopAnim() {

            if ( animThread != null && animThread.isAlive())
            keepDrawing = false;
            animThread = null;         
        }


        public void run()
        {

             while (keepDrawing)
              {

                    while (base<messageSizeValue-windowSizeValue) 
                    {base+=1;

                    repaint();
                    try
                    {
                        animThread.sleep(1000); //sleep a little to slow it down
                    }
                    catch (InterruptedException e) {}
                }

         }
    }

        
        
        public void paint(Graphics g)
        {
            update(g);
        }
        
        public void update(Graphics g)
        {
            Dimension d = getSize();
            
            offD = d;
            offImage = createImage(getWidth(), getHeight());
            offG = offImage.getGraphics();
            
            offG.setColor(Color.WHITE);
            offG.fillRect(0,0,getWidth(), getHeight());

            for (int i = 0 ; i < messageSizeValue; i++)
            {


//                 if (sender[i].getStatus() == 0)
//                 {
                    offG.setColor(Color.BLACK);
                    offG.drawRect(senderX+20*i, 150, 15, 15);
                    offG.drawRect(senderX+20*i, 300, 15, 15);
//                 }

            }
            

            offG.setColor(Color.BLACK);

            offG.drawRect(senderX+base*20-3, 146, windowSizeValue*20+1, 23);
            


            g.drawImage(offImage, 0, 0, this);

            
        }
    }


and this one is packet class:

Code:
class Packet
{
    int status;
    int position;
    
    Packet()
    {
        this.status = 0;
        this.position = 0;
    }
    
    Packet (int pStatus, int pPosition)
    {
        status = pStatus;
        position = pPosition;
        /*
         * 0 = null
         * 1 = ready
         * 2 = on the way
         * 3 = acknowledge
         * 4 = on the way ack
         * 5 = recieved
         * 6 = unacknowledge
         */
    }
    public int getStatus() {return status;}
    public int getPosition() {return position;}
    public void setStatus(int s)
    {
        this.status = s;
    }
    public void setPosition(int p)
    {
        this.position = p;
    }
}



anyone has any suggestion?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Problem with my animation applet


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek