

import java.awt.*;
import java.awt.Event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Random;

import javax.swing.JTextPane;
import javax.swing.text.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.*;
import javax.swing.event.*;

import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.QuadCurve2D;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DateFormat;
import java.awt.geom.*;
import java.awt.image.*;
import java.lang.Math;
/*
<applet code="StopAndWait" width=1000 height=600>
</applet>
*/

public class csma extends JApplet implements MouseListener,ActionListener,ItemListener,ChangeListener//,Runnable//,TableCellRenderer
{	
	
	 JComponent container1;
	
	 JButton btnPlay, btnStop,btnPause;  
	 Thread animator;
	 Graphics g;
	
	 //    csmacd
	 private Image     myOffScreenImage = null;

	  private Graphics  myOffScreenGraphics = null;

	  private boolean   myResized = true;

	  

	  Network myNetwork;

	  public static Timer myTimer;

	  int clicked=0;

	  Button mySetSizeButton;

	  Button stopButton;

	  Button addButton;

	  Button clearButton;

	  

	  TextField mySizeTextField;

	  TextField posTextField;

	  int start;

	  int posArray[] = new int[10];

	  int count=0;

	  
	 
	 //csmacd
	 
	 
	 
	//aruna
	JTextPane jtp1,jtp2;
	Cursor handCursor,normalCursor;
	TextArea ta = null;
	TextArea th = null;
	TextArea ins = null;
	JLabel lbl,lbl1;
	JLabel info,info1;
	
	JFrame glos,hel,frl1;
	
	volatile Thread current = null;
	boolean paused = true;
	
	boolean animationrunning = false,stopf1=false,clearScreen = false;
	
	
	Dimension d;		
	/*  variable declaration  */
	
	int counter = 0,flagC = 0,flagC1=0;
	
	
	
	 
	
	
	
	JLabel lbl_subject,lbl_topic,lbl_oscar_image,lbl_home,lbl_openingscreen; //for Header part
	JButton but_Theory,but_Demo,but_Interaction,but_Glossary,but_Exercise,but_Help,but_Links,but_Analogy,but_credits,but_home; //Different tabs
	JButton but_go_links,but_go1_links,but_close_links; //for FurtherReadingTab
	JButton fr_exercise_but1,fr_exercise_but2,fr_exercise_but3,fr_exercise_but4,fr_exercise_but5; //for ExerciseTab
	JFrame fr_credits,fr_links; //Now not using
	JLabel fr_links_Message,fr_links_Message1,fr_links_Message2;//for Furtherreading tab
	JLabel fr_help_head,fr_help_Message; //for HelpTab
	JLabel fr_exercise_Message,fr_exercise_Message1;//for Exercise[Questionare]Tab
	JLabel lblHeader_glossary,lblMessage_glossary;//For GlossaryTab
	JTable tblLeftIndex_glossary;//for Glossarytable tab
	HashMap map = null; //For Glossarytab
	JTextPane txtPaneDescription_glossary; //For Glossarytab
	JTable table_help; //for HelpTab
	
	JTextPane txtPane_explanation,txtPane_credits,txtPane_theory,txtPane_Analogy,txtPane_interaction,opening_screen,opening_screen1,opening_screen_message,txtPane_theory1 ;//Display Area of Demo,credits,theory,interaction etc.
	JTextPane txtPane_Exercise1,txtPane_Exercise2,txtPane_Exercise3,txtPane_Exercise4,txtPane_Exercise5,fr_exercise_answer,txtPane_ref,theoryC;//For Questions and Answer for QuestionareTab
	
	ButtonGroup group1;// for InteractivityTab.[Table --putting all 0 to 7 buttons into one group]
	JRadioButton q11,q12,q13,q14,q21,q22,q23,q24,q31,q32,q33,q34,q41,q42,q43,q44,q51,q52,q53,q54;
	ButtonGroup q1,q2,q3,q4,q5;//For ExerciseTab.[Answer choices]
	
	JButton but_Pause,but_Resume; // for DemoTab
	
	JLabel fr_credits_author,fr_credits_mentor,fr_credits_developer,fr_credits_designer; //for Credits Tab

	JLabel lbl_Analogy,demo_image1,l,l1,l2,l3; //For Anlogy tab
	JTable table; //For Interactivity Tab[radioButton including]
	
	ImageIcon im_play,im_pause,im_theory,im_demo,im_interaction,im_analogy,im_glossary,im_help,im_exercise,im_reference,im_credits,im_home,im_reset;//images for tabs
	JPanel panel1,panel2,panel3,panel4,panel5,opening_screen_logo;//for ExerciseTab[includes question and answer choices ---not answer.]
	JPanel paneltemp,lbl_opening_screen_left,demo_selection_panel;
	JPanel theory1,theory2,theory3;
	JButton theory_button1,theory_button2,theory_button3;
	JScrollPane theory1_scrollPane,theory2_scrollPane,theory3_scrollPane;
	
	//for HelpTab.
	String colnames_help[]={"Button","Description"};
	
	boolean blhome=true,blPHY_MEMcheck=false,blPAGETABLEcheck=false,blSEC_MEMcheck=false;
	
	int nAppRowHeight = 24;
	int x = (nAppRowHeight/2);
	

	
	Color yellow = new Color(238,211,65);
	Color yellow_dark = new Color(174,152,49);
	Color grey = new Color(108,108,107);
	Color color1 = new Color(255,204,204);
	Color color2 = new Color(204,255,204);
	Color color3 = new Color(153,153,153);
	
	Color color4 = new Color(149,181,242);
	Color color5 = new Color(0,153,153);
	Color color6 = new Color(255,228,225);
	Color color7 = new Color(0,255,255);
	Color color8 = new Color(244,164,96);
	
	Color color9 = new Color(228,175,61);
	
	Color color10 = new Color(158,205,51);
	Color color11 = new Color(100,100,255);
	Color color12=new Color(227,207,87);
	Color orange1=new Color(102,0,51);
	Color help_color=new Color(236,167,167);
	Color links_color=new Color(125,164,198);
	Color exercise_color=new Color(179,156,132);
	Color glossary_color=new Color(250, 162, 73);
	Color analogy_color=new Color(228,177,203);
	
	Color theory_color=new Color(227, 177, 202);
	Color lightgrey = new Color(200,200,200);
	
	Color demo_color = new Color(133, 157, 217);
	Color demo_color_new = new Color(102,153,204);
	Color interaction_color = new Color(166,223,244);
	
	Color home_color = new Color(204, 222, 138);
	// for interaction screen color
	Color transmiter = new Color(193,167,134);
	
	Color transtext = new Color(238,111,77);
	Color receiver = new Color(218,201,157);
	
	Color recetext = new Color(244,194,0);
	Color buttonPanel = new Color(196,209,181);
	Color textPanel = new Color(132,156,104);
	Color timingBox = new Color(228,228,190);
	Color playbut = new Color(132,156,104);
	
	Color timeoutBox = new Color(226,234,226);
	Color frame1 = new Color(123,115,173);
	Color frame2 = new Color(156,99,99);
	Color frame3 = new Color(156,148,99);
	Color frame4 = new Color(115,148,173);
	Color new_head_color = new Color(58, 58, 58);
	
	Color header_color = new Color(58,58,58);

	Border thickBorder_theory = new LineBorder(theory_color, 6);
	Border thickBorder_demo = new LineBorder(demo_color, 6);
	Border thickBorder_interaction = new LineBorder(interaction_color, 6);
	Border thickBorder_analogy = new LineBorder(analogy_color, 6);
	Border thickBorder_glossary = new LineBorder(glossary_color, 6);
	Border thickBorder_exercise = new LineBorder(exercise_color, 6);
	Border thickBorder_links = new LineBorder(links_color, 6);
	Border thickBorder_help = new LineBorder(help_color, 6);
	Border thickBorder_home = new LineBorder(new Color(0xFFAA73), 6);
	
	Border theoryBorder = new LineBorder(color2,2);
	Border interactionBorder = new LineBorder(yellow_dark,1);
	
	Border line_border = BorderFactory.createLineBorder(Color.black,2);
	
	boolean exercise=false,demo=false,demo_zero=false,demo_first=false,demo_second=false,demo_third=false,demo_forth=false,demo_fifth=false,demo_sixth=false,demo_seventh=false,demo_eighth=false,demo_nineth=false,demo_tenth=false,demo_eleventh=false,demo_twelvth=false,demo_thirteenth=false,demo_forteenth=false;
	boolean demo_fifteenth=false,demo_sixteenth=false,demo_seventeenth=false,demo_eighteenth=false,demo_nineteenth=false,demo_twentieth=false;
	boolean demo_21=false,demo_22=false,demo_23=false,demo_24=false,demo_25=false,demo_26=false,demo_27=false,demo_28=false,demo_29=false,demo_30=false,demo_31=false,demo_32=false;
	boolean interaction_first=false,interaction_second=false,interaction_third=false,interaction_forth=false,interaction_fifth=false;
	boolean blTheory=false,blAnalogy=false,blInteraction=false,blGlossary=false,blExercise=false,blHelp=false,blLinks=false;
	boolean stopf=false;
	boolean flag=false;
	int demo_incr=-1,interaction_incr=0;
	int demo_sleeptime=3000;
	int interaction_sleeptime=3000;


	class mypaint extends JPanel
	{
		private static final long serialVersionUID = 1L;
		
		public void paintComponent(Graphics g)
		{
			try
			{
				
				g.setColor(header_color);
				g.fillRect(2,2,998,75);	
				
				g.setColor(grey);//Applet panel
				g.drawRect(2,77,998,503);			
				
				g.setColor(grey);//footer
				g.fillRect(2,580,998,20);
				g.setColor(Color.white);
				g.drawString("The contents in this page are licensed under Creative Commons Attribution-NonCommercial-ShareAlike 2.5 India license.",5,592);
				
				/*if(blInteraction==true)
				{	hex to rgb color code
					
					
					
					
				}//end of if interaction
				*/
				//show here analogy
				if(blAnalogy==true)
				{
					
				}//end of analogy
				
				
			/*	if(blGlossary==true)
				{
					Graphics2D g2d = (Graphics2D)g;
				    Color s1 = glossary_color;
				    Color e = Color.white;
				    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
				    g2d.setPaint(gradient);
					g.fillRect(2,77,998,10);
					g.fillRect(2,77,10,500);
					g.fillRect(990,77,10,500);
				}*/
				
				if(blLinks==true)
				{
					Graphics2D g2d = (Graphics2D)g;
				    Color s1 = links_color;
				    Color e = Color.white;
				    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
				    g2d.setPaint(gradient);
					g.fillRect(2,77,998,10);
					g.fillRect(2,77,10,500);
					g.fillRect(990,77,10,500);
				}
			
				if(blExercise==true)
				{
					Graphics2D g2d = (Graphics2D)g;
				    Color s1 = exercise_color;
				    Color e = Color.white;
				    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
				    g2d.setPaint(gradient);
					g.fillRect(2,77,998,10);
					g.fillRect(2,77,10,500);
					g.fillRect(990,77,10,500);			
				}
				if(blHelp==true)
				{
					Graphics2D g2d = (Graphics2D)g;
				    Color s1 = help_color;
				    Color e = Color.white;
				    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
				    g2d.setPaint(gradient);
					g.fillRect(2,77,998,10);
					g.fillRect(2,77,10,500);
					g.fillRect(990,77,10,500);				
			
				}
				if(blhome==true)
				{
					
					  Graphics2D g2d = (Graphics2D)g;
				      Color s1 = home_color;
				      Color e = Color.white;
				      GradientPaint gradient = new GradientPaint(2,77,s1,7,450,e,true);
				      g2d.setPaint(gradient);
				      g.fillRect(2,77,998,10);
				      g.fillRect(2,77,10,500);
				      g.fillRect(990,77,10,500);	
			
				}
				if(blTheory==true)
				{
					Graphics2D g2d = (Graphics2D)g;
				    Color s1 = theory_color;
				    Color e = Color.white;
				    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
				    g2d.setPaint(gradient);
					g.fillRect(2,77,998,10);
					g.fillRect(2,77,10,500);
					g.fillRect(990,77,10,500);
													
				}
						
				//if demo button is pressed
				//if(stopf==false)
				//{			
				if(blInteraction==true){
					
					Graphics2D g2d = (Graphics2D)g;
				    Color s1 = interaction_color;
				    Color e = Color.white;
				    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
				    g2d.setPaint(gradient);
					g.fillRect(2,77,998,10);
					g.fillRect(2,77,10,500);
					g.fillRect(990,77,10,500);
					
					g.setColor(demo_color_new);
					g.fillRect(12,87,980,40);
					g.setColor(Color.WHITE);
					g.setFont(new Font("Arial",Font.BOLD,20));
					
					
					g.setFont(new Font("Arial",Font.PLAIN,12));
					g.setColor(demo_color_new);	
					
					g.drawLine(705,125,705,580);
					// to display text or instructions
					g.setColor(demo_color_new);
					g.drawLine(705,365,989,365);
					g.setColor(Color.black);
					g.setFont(new Font("Times",Font.BOLD,14));
					g.drawString("Explanation", 800, 385);
					g.setFont(new Font("Times",Font.PLAIN,12));
					
					
					
					
					
				

			      	if (!clearScreen){
						//System.out.println(" inside repaint function------==-----");
						
					}
					else {
						System.out.println(" in clear ------------");
						g.setColor(Color.white);
						//g.fillRect(12,330, 690,249);
						// text pannel
						g.fillRect(706,330,283,249);
						// line seperater between three stages in left side
						//g.drawLine(10,275,599,275);// 1st divider
						//g.drawLine(10,425,599,425);// second divider
						
						g.setColor(Color.gray);
						
						//clearScreen=false;
					}
				}	// interaction		
				
				else if(demo==true)
			{	
			
				Graphics2D g2d = (Graphics2D)g;
			    Color s1 = demo_color;
			    Color e = Color.white;
			    GradientPaint gradient = new GradientPaint(2,77,s1,7,550,e,true);
			    g2d.setPaint(gradient);
				g.fillRect(2,77,998,10);
				g.fillRect(2,77,10,500);
				g.fillRect(990,77,10,500);
				
				
				
				 
				g.setColor(demo_color_new);
				g.fillRect(12,87,980,40);
				g.setColor(Color.WHITE);
				g.setFont(new Font("Arial",Font.BOLD,17));
				g.drawString("Please enter number between 1 and 99 and press AddStation button to create stations", 15, 115);
				
				g.setFont(new Font("Arial",Font.PLAIN,12));
				g.setColor(demo_color_new);	
				
				g.drawLine(705,125,705,580);
				// to display text or instructions
				g.setColor(demo_color_new);
				g.drawLine(705,320,989,320);
				g.setColor(Color.black);
				g.setFont(new Font("Times",Font.BOLD,14));
				g.drawString("Explanation", 800, 340);
				
				
				// draw horizontal line
				 
				 Integer time = new Integer(myTimer.myTime);

				  // draw time

			    g.setColor(Color.black);

//			    g.drawString("Time:   "+time.toString(),80,10); 

				  // draw network

				  myNetwork.paint(g); 

				     

				
				
				
					      	if (!clearScreen){
								//System.out.println(" inside repaint function------==-----");
								
							}
							else {
								System.out.println(" in clear ------------");
								g.setColor(Color.white);
								//g.fillRect(12,330, 690,249);
								// text pannel
								g.fillRect(706,330,283,249);
								// line seperater between three stages in left side
								//g.drawLine(10,275,599,275);// 1st divider
								//g.drawLine(10,425,599,425);// second divider
								
								g.setColor(Color.gray);
								
								//clearScreen=false;
							}
			}//end of if demo
			
			}
			catch(Exception e)
			{
				
			}//end of catch
		}
		
	}

	

public void init()
	{
		d = getSize();
		container1 = new mypaint();
		container1.setBounds(0, 0, d.width, d.height);
		setContentPane(container1);
		container1.setLayout(null);		
		
		// Glossary Tab ........START............
		
		TableModel tblLeftIndexModel = new DefaultTableModel(new String[][] {
				{ "Signal " }, { " Signal Transformation "  }, { " Shifting " },{" Delaying "},
				{ " Advancing " }, {"Scaling"}, {"Compression"},{"Expansion"},{"Reversal"} },
				new String[] { "Index Index Index" });
		
		tblLeftIndex_glossary = new JTable();
		tblLeftIndex_glossary.setModel(tblLeftIndexModel);
		tblLeftIndex_glossary.setBounds(125,200, 170, nAppRowHeight*tblLeftIndex_glossary.getRowCount());
		tblLeftIndex_glossary.setBackground(lightgrey);
		tblLeftIndex_glossary.setVisible(false);
		tblLeftIndex_glossary.setRowHeight(nAppRowHeight);
		tblLeftIndex_glossary.setForeground(Color.black);	
		//tblLeftIndex_glossary.sete	
		add(tblLeftIndex_glossary);	
		
		lblHeader_glossary = new JLabel();
		lblHeader_glossary.setText("Index");		
		add(lblHeader_glossary);
		lblHeader_glossary.setVisible(false);
		lblHeader_glossary.setBounds(tblLeftIndex_glossary.getBounds().x+4, tblLeftIndex_glossary.getBounds().y-25, 48, 22);
		
		lblMessage_glossary = new JLabel();
		lblMessage_glossary.setText("Choose a topic from left, the definition will appear on the right.");		
		add(lblMessage_glossary);
		lblMessage_glossary.setVisible(false);		
		lblMessage_glossary.setBounds(tblLeftIndex_glossary.getBounds().x+4, tblLeftIndex_glossary.getBounds().y-70, 500, 22);
		
		txtPaneDescription_glossary = new JTextPane();
		StyledDocument docglossary = txtPaneDescription_glossary.getStyledDocument();
		MutableAttributeSet standardglossary = new SimpleAttributeSet();
		StyleConstants.setAlignment(standardglossary, StyleConstants.ALIGN_RIGHT);
		StyleConstants.setLineSpacing(standardglossary, 2);
		add(txtPaneDescription_glossary);
		txtPaneDescription_glossary.setText("Select the keyword from the left menu list.");	
		txtPaneDescription_glossary.setBackground(lightgrey);
		txtPaneDescription_glossary.setForeground(Color.black);
		txtPaneDescription_glossary.setBounds(300, 200, 295,nAppRowHeight*tblLeftIndex_glossary.getRowCount());
		txtPaneDescription_glossary.setVisible(false);		
		
		tblLeftIndex_glossary.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent evt) {
				tblLeftIndexMouseClicked(evt);
			}
			public void mouseEntered(MouseEvent arg0) {	}
			public void mouseExited(MouseEvent arg0) { }
			public void mousePressed(MouseEvent arg0) {	}
			public void mouseReleased(MouseEvent arg0) { }
		});
		
		// Glossary Tab ........STOP............
		
		
		// Header.............START..........
		lbl_subject=new JLabel("CSMA/CD Simulation ");
		lbl_subject.setBounds(260,5,600,28);
		lbl_subject.setForeground(Color.white);
		lbl_subject.setFont(new Font("Helvetica",Font.BOLD,25));
		container1.add(lbl_subject);
		
		lbl_topic=new JLabel(" Computer Science and Engineering > Networking ");
		lbl_topic.setBounds(252,35,450,35);
		
		lbl_topic.setForeground(Color.white);
		lbl_topic.setFont(new Font("Helvetica",Font.BOLD,14));
		container1.add(lbl_topic);
		
		lbl_oscar_image=new JLabel("");
		lbl_oscar_image.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/oscarlogo.png")));
		lbl_oscar_image.setBounds(5,5,250,75);
		container1.add(lbl_oscar_image);
		
		
		
		// Header.............STOP..........
		
		// Different Tabs ...........START.................
		im_home=new ImageIcon(getClass().getClassLoader().getResource("images/home.png"));
		but_home = new JButton("");
		//but_home.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/home.png")));
		but_home.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/1_home.png")));
		but_home.setFont(new Font("",Font.PLAIN,13));
		but_home.setBackground(new_head_color);//(yellow);	
		
		//but_home.setBounds(650,37,50,40);
		but_home.setBounds(700,37,50,40);
		but_home.setToolTipText("Home");
		 but_home.setBorderPainted(false);
		container1.add(but_home);
		but_home.addActionListener(this);
		
		//im_theory=new ImageIcon(getClass().getClassLoader().getResource("images/theory.png"));	
		im_theory=new ImageIcon(getClass().getClassLoader().getResource("images/5_Theory.png"));	
		but_Theory=new JButton(im_theory);
		but_Theory.setFont(new Font("",Font.PLAIN,13));
		but_Theory.setForeground(Color.white);
		
		//but_Theory.setBounds(700,37,50,40);
		but_Theory.setBounds(750,37,50,40);
		but_Theory.setToolTipText("Click Here To View the Theory.");
		container1.add(but_Theory);
		but_Theory.addActionListener(this);
		
		
		im_demo=new ImageIcon(getClass().getClassLoader().getResource("images/2_demo.png"));
		but_Demo=new JButton(im_demo);
		but_Demo.setFont(new Font("",Font.PLAIN,13));
		but_Demo.setForeground(grey);
		but_Demo.setBackground(Color.white);
		
		//but_Demo.setBounds(750,37,50,40);
		but_Demo.setBounds(800,37,50,40);
		but_Demo.setToolTipText("Click Here To View the Demo.");
		container1.add(but_Demo);
		but_Demo.addActionListener(this);
		
	/*	im_interaction=new ImageIcon(getClass().getClassLoader().getResource("images/3_interactivity.png"));
		but_Interaction=new JButton(im_interaction);
		but_Interaction.setFont(new Font("",Font.PLAIN,13));
		but_Interaction.setForeground(grey);		
		
		but_Interaction.setBounds(800,37,50,40);
		but_Interaction.setToolTipText("Click Here To interact.");
		container1.add(but_Interaction);
		but_Interaction.addActionListener(this);
	*/
		/*im_analogy=new ImageIcon(getClass().getClassLoader().getResource("images/analogy.png"));
		but_Analogy=new JButton(im_analogy);
		but_Analogy.setFont(new Font("",Font.PLAIN,13));
		but_Analogy.setForeground(grey);		
		but_Analogy.setBounds(750,37,50,40);
		but_Analogy.setToolTipText("Click Here To view Analogy");
		container1.add(but_Analogy);
		but_Analogy.addActionListener(this);
		*/
	/*	im_glossary=new ImageIcon(getClass().getClassLoader().getResource("images/6_Glossary.png"));
		but_Glossary=new JButton(im_glossary);
		but_Glossary.setFont(new Font("",Font.PLAIN,13));
		but_Glossary.setForeground(grey);
		//but_Glossary.setBackground(Color.white);
		but_Glossary.setBounds(800,37,50,40);
		but_Glossary.setToolTipText("Click Here To view Definitions.");		
		container1.add(but_Glossary);
		but_Glossary.addActionListener(this);
*/
		im_exercise=new ImageIcon(getClass().getClassLoader().getResource("images/7_Quiz.png"));
		but_Exercise=new JButton(im_exercise);
		but_Exercise.setFont(new Font("",Font.PLAIN,13));
		but_Exercise.setForeground(grey);
		but_Exercise.setBackground(Color.white);	
		but_Exercise.setBounds(850,37,50,40);
		but_Exercise.setToolTipText("Click Here To view Questionare");
		container1.add(but_Exercise);
		but_Exercise.addActionListener(this);

		im_reference=new ImageIcon(getClass().getClassLoader().getResource("images/8_Reference.png"));
		but_Links=new JButton(im_reference);
		but_Links.setFont(new Font("",Font.PLAIN,13));
		but_Links.setForeground(grey);
		but_Links.setBackground(Color.white);
		but_Links.setBounds(900,37,50,40);
		but_Links.setToolTipText("Click Here To view Links for further Reading");		
		container1.add(but_Links);
		but_Links.addActionListener(this);

		im_help=new ImageIcon(getClass().getClassLoader().getResource("images/9_Help.png"));
		but_Help=new JButton(im_help);
		but_Help.setFont(new Font("",Font.PLAIN,13));
		but_Help.setForeground(grey);	
		but_Help.setBackground(Color.white);
		but_Help.setBounds(950,37,50,40);
		but_Help.setToolTipText("Click Here To view Help");
		container1.add(but_Help);
		but_Help.addActionListener(this);
		
		addMouseListener(this);

		// Different Tabs ...........STOP.................
		
		//im_credits=new ImageIcon(getClass().getClassLoader().getResource("images/credits.jpg"));
		im_credits=new ImageIcon(getClass().getClassLoader().getResource("images/10_Credits.png"));
		but_credits=new JButton(im_credits);
		but_credits.setFont(new Font("",Font.PLAIN,13));
		but_credits.setForeground(grey);
		//but_credits.setBackground(color8);
		but_credits.setBounds(935,580,63,20);
		but_credits.setToolTipText("Click Here To view author,mentor");
		container1.add(but_credits);
		but_credits.addActionListener(this);
		
		// For DemoTab ............START.............		
	/*	im_pause=new ImageIcon("images/pause.jpg");
		but_Pause=new JButton(im_pause);
		but_Pause.setFont(new Font("",Font.PLAIN,13));
		but_Pause.setForeground(Color.white);		
		but_Pause.setBounds(674,130,30,25);
		but_Pause.setToolTipText("Click Here To pause the Demo");
		but_Pause.setVisible(false);
		container1.add(but_Pause);
		but_Pause.addActionListener(this);
		*/
		
		im_pause=new ImageIcon(getClass().getClassLoader().getResource("images/clear_button.png"));
		im_reset=new ImageIcon(getClass().getClassLoader().getResource("images/stop.png"));
		im_play=new ImageIcon(getClass().getClassLoader().getResource("images/addStation.png"));
		/*im_play=new ImageIcon("images/play.jpg");
		but_Resume=new JButton(im_play);
		but_Resume.setFont(new Font("",Font.PLAIN,13));
		but_Resume.setForeground(Color.white);
		but_Resume.setBackground(color10);
		but_Resume.setBounds(674,130,30,25);
		but_Resume.setToolTipText("Click Here To Resume the Demo");
		but_Resume.setVisible(false);
		container1.add(but_Resume);
		but_Resume.addActionListener(this);
		*/
		
	
		// For DemoTab ............STOP.............
		
		// Opening Screen .....START .........
		/*opening_screen=new JTextPane();		
		opening_screen.setFont(new Font("Monospaced",Font.PLAIN,16));
		opening_screen.setForeground(grey);		
		opening_screen.setBounds(180,280,700,100);		
		opening_screen.setVisible(true);
		opening_screen.setText("Details of Stop And Wait ARQ:;;  ");
		container1.add(opening_screen);*/
		
		//blhome = true;
		
		lbl_opening_screen_left = new JPanel() ;
		//lbl_opening_screen_left.setBounds(30, 125, 470, 315);
		lbl_opening_screen_left.setBounds(30, 150, 400, 200);
        lbl_opening_screen_left.setVisible(true);
        container1.add(lbl_opening_screen_left);
        
        // put image
        ImageIcon image_home = new ImageIcon(getClass().getClassLoader().getResource("images/csmacd_home.png"));// change the image
		JLabel home_image1 = new JLabel(image_home);
		home_image1.setBounds(30,180,357,162);
		lbl_opening_screen_left.add(home_image1);
        
		
		opening_screen_message=new JTextPane();
		opening_screen_message.setFont(new Font("Arial", Font.PLAIN, 12));
		opening_screen_message.setForeground(Color.darkGray);		
		
		opening_screen_message.setBounds(30,100,650,50);
		opening_screen_message.setVisible(true);
		opening_screen_message.setText("Click on the Icons on the top right corner to go to the relevent" +
				" section of the learning Object(LO).");
		
		
		container1.add(opening_screen_message);
		
		
		opening_screen=new JTextPane();	
		
		
		opening_screen.setBounds(480, 160, 470, 120);
        opening_screen.setVisible(true);
        opening_screen.setFont(new Font("Arial", Font.PLAIN, 13));
        opening_screen.setEditable(false);
        opening_screen.setBorder(null);
       	opening_screen.setForeground(Color.BLACK);
		
		StyledDocument doc_open = opening_screen.getStyledDocument();
		MutableAttributeSet standard_open = new SimpleAttributeSet();
		StyleConstants.setAlignment(standard_open, StyleConstants.ALIGN_JUSTIFIED);	
		//StyleConstants.setFontSize(standard_open, 18);
		//StyleConstants.setForeground(standard_open,Color.BLACK);
		//StyleConstants.setFontFamily(standard_open, "Arial");
		//doc_open.setParagraphAttributes(0, 0, standard_open, true);
		//opening_screen.setFont(new Font("",Font.PLAIN,12));
		//opening_screen.setForeground(Color.black);		
		//opening_screen.setBounds(100,200,700,200);		
		//opening_screen.setVisible(true);
		opening_screen.setText("Carrier Sense Multiple Access (CSMA), although more efficient than ALOHA or slotted ALOHA, " +
				"still has one glaring inefficiency: When two frames collide, the medium remains unusable for the duration" +
				" of transmission of both damaged frames. For long frames, compared to propagation time, the amount of wasted " +
				"capacity can be considerable. This waste can be reduced if a station continues to listen to the medium " +
				"while transmitting.");
		container1.add(opening_screen);
		
		lbl_openingscreen=new JLabel("Learning Objectives ");
		//lbl_openingscreen.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/home.png")));
		lbl_openingscreen.setBounds(480,270,470,50);
		lbl_openingscreen.setFont(new Font("",Font.BOLD,14));
		lbl_openingscreen.setForeground(Color.BLACK);
		container1.add(lbl_openingscreen);
		lbl_openingscreen.setVisible(true);
		
		
		opening_screen1=new JTextPane();	
		
		
		opening_screen1.setBounds(480, 320, 470, 100);
        opening_screen1.setVisible(true);
        opening_screen1.setFont(new Font("Arial", Font.PLAIN, 13));
        opening_screen1.setEditable(false);
        opening_screen1.setBorder(null);
       	opening_screen1.setForeground(Color.BLACK);
       	
       	opening_screen1.setText("After interacting with this Learning Object, the learner will be able to:\n\n"+
				" Explain the process of collision detection in CSMA/CD.");
       	container1.add(opening_screen1);
       	
		opening_screen_logo = new JPanel();  
		opening_screen_logo.setLayout(null);		
		opening_screen_logo.setVisible(true);
		opening_screen_logo.setBackground(Color.LIGHT_GRAY);
		opening_screen_logo.setBounds(2,450,998,130);
		add(opening_screen_logo);
		
		JLabel by = new JLabel("Sponsored by :");
		by.setBounds(5, 1, 121, 25);
		by.setFont(new Font("",Font.BOLD,14));
		by.setForeground(Color.BLACK);
		opening_screen_logo.add(by);
		
		JLabel at = new JLabel("Developed by :");
		at.setBounds(865, 1, 120, 25);
		at.setFont(new Font("",Font.BOLD,14));
		at.setForeground(Color.BLACK);
		opening_screen_logo.add(at);
		
		//im_mhrd = new ImageIcon("images/mhrd.png");
		JLabel mhrd=new JLabel("");
		mhrd.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/mhrd.png")));
		mhrd.setBounds(5, 27, 97, 97);		
		opening_screen_logo.add(mhrd);
		
		//im_iit = new ImageIcon("images/iit.png");
		JLabel iit=new JLabel("");
		iit.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/iitb.png")));
		iit.setBounds(865, 27, 97, 97);
		opening_screen_logo.add(iit);

		// testing.............................
	//	ImageIcon image_sigma = new ImageIcon(getClass().getClassLoader().getResource("images/sigma2.png"));// change the image
	//	demo_image1 = new JLabel(image_sigma);
	//	demo_image1.setBounds(730,340,300,250);
	//	container1.add(demo_image1);
		
		//demo_image1.setVisible(true);
		// end testing............................
		
		
		// Opening Screen .....STOP.........		
		
		
		/*fr_credits = new JFrame("Credits : Stop And Wait ARQ");
		fr_credits.setBounds(6,92,400,400);
		fr_credits.setBackground(color8);
		fr_credits.getContentPane().setLayout(null);
		
		txtPane_credits=new JTextPane();	
		txtPane_credits.setText("\n\n\n\n\tAuthor        :  Aruna Adil\n\n\tMentor        :  Prof.Saravanan Vijayakumaran\n\n\tDeveloper  :  Aruna Adil\n\n\tDesigner    :  Amita Shinde");
		txtPane_credits.setBounds(20,30,350,300);		
		txtPane_credits.setBackground(color8);	
		txtPane_credits.setForeground(orange1);
		txtPane_credits.setEditable(false);
		fr_credits.getContentPane().add(txtPane_credits);	
		*/
		
		fr_credits = new JFrame("Credits : ");
		fr_credits.setBounds(12,87,500,400);
		//fr_credits.setBackground(color8);
		fr_credits.getContentPane().setLayout(null);
		
		txtPane_credits=new JTextPane();
		
		
		txtPane_credits.setFont(new Font("",Font.PLAIN,15));
		txtPane_credits.setText("\nWe would like to thank IIT Bombay, MHRD and following people for their contribution in "
								 +"creating this Learning Object (LO).\n\n\tAuthor        :  Phani Swathi Chitta\n\n\tMentor        :  Prof. Sridhar Iyer, Aruna Adil\n\n\tDeveloper    :  B Anuradha, C Manoj Kumar, T \n                                    Chitti Babu\n\n\tDesigner     :  Sameer S Sahasrabudhe ");
		txtPane_credits.setBounds(10,20,450,250);		
		txtPane_credits.setBackground(Color.WHITE);	
		txtPane_credits.setForeground(Color.BLACK);
		txtPane_credits.setVisible(false);
		txtPane_credits.setEditable(false);
		fr_credits.getContentPane().add(txtPane_credits);	
		//container1.add(txtPane_credits);
		
		StyledDocument doc_credit = txtPane_credits.getStyledDocument();
		
		Style style_bold = txtPane_credits.addStyle("iitb", null);		
		StyleConstants.setForeground(style_bold, new Color(0xA31717));
		StyleConstants.setBold(style_bold,true);
		doc_credit.setCharacterAttributes(24, 16, txtPane_credits.getStyle("iitb"), true);
		
		Style style_color = txtPane_credits.addStyle("color", null);
		StyleConstants.setBold(style_color,true);
		StyleConstants.setForeground(style_color, new Color(0xA31717));
		doc_credit.setCharacterAttributes(142, 20, txtPane_credits.getStyle("color"), true);
		doc_credit.setCharacterAttributes(181, 31, txtPane_credits.getStyle("color"), true);
		doc_credit.setCharacterAttributes(230, 78, txtPane_credits.getStyle("color"), true);
		doc_credit.setCharacterAttributes(327, 27, txtPane_credits.getStyle("color"), true);
		
		
		
		
		//For DemoExplanation
		txtPane_explanation=new JTextPane();
		StyledDocument doc = txtPane_explanation.getStyledDocument();
		MutableAttributeSet standard = new SimpleAttributeSet();
		StyleConstants.setAlignment(standard, StyleConstants.ALIGN_JUSTIFIED);		
		doc.setParagraphAttributes(0, 0, standard, true);	
		MutableAttributeSet TLB = new SimpleAttributeSet();
		StyleConstants.setForeground(TLB, Color.red);
		StyleConstants.setItalic(TLB, true);
		//txtPane_explanation.setBounds(750,200,230,300);			
		txtPane_explanation.setVisible(false);
		txtPane_explanation.setEditable(false);
		container1.add(txtPane_explanation);
		
		//For Interaction Explanation
		txtPane_interaction=new JTextPane();
		StyledDocument docinteraction = txtPane_interaction.getStyledDocument();
		MutableAttributeSet standardinteraction = new SimpleAttributeSet();
		StyleConstants.setAlignment(standardinteraction, StyleConstants.ALIGN_JUSTIFIED);
		StyleConstants.setForeground(standardinteraction, grey);
		docinteraction.setParagraphAttributes(0, 0, standard, true);	
		MutableAttributeSet TLBinteraction = new SimpleAttributeSet();
		StyleConstants.setForeground(TLB, Color.red);
		StyleConstants.setItalic(TLBinteraction, true);
		//txtPane_interaction.setBounds(700,200,280,350);	
		txtPane_interaction.setText("For Interaction Explanation");
		txtPane_interaction.setVisible(false);
		txtPane_interaction.setEditable(false);
		container1.add(txtPane_interaction);
		
		//For Theory Explanation
		txtPane_theory=new JTextPane();
		StyledDocument doctheory = txtPane_theory.getStyledDocument();
		MutableAttributeSet standardtheory = new SimpleAttributeSet();
		StyleConstants.setAlignment(standardtheory, StyleConstants.ALIGN_JUSTIFIED);		
		doctheory.setParagraphAttributes(0, 0, standardtheory, true);
		txtPane_theory.setBounds(475,220,400,300);	
		txtPane_theory.setText("For Theory Explanation");
		txtPane_theory.setVisible(false);
		txtPane_theory.setEditable(false);
		container1.add(txtPane_theory);	
		
		//For Analogy explanation
		txtPane_Analogy=new JTextPane();
		StyledDocument docAnalogy = txtPane_Analogy.getStyledDocument();
		Style style = txtPane_Analogy.addStyle("Red", null); 
		StyleConstants.setForeground(style, Color.red); 		
		MutableAttributeSet standard8 = new SimpleAttributeSet();
		MutableAttributeSet keyWord8 = new SimpleAttributeSet();
		StyleConstants.setForeground(keyWord8, Color.red);
		docAnalogy = txtPane_Analogy.getStyledDocument();		             
		docAnalogy.setCharacterAttributes(3,14,keyWord8, true);
		docAnalogy.setCharacterAttributes(5, 2, txtPane_Analogy.getStyle("Red"), true); 				
		txtPane_Analogy.setBounds(550,210,350,260);		
		txtPane_Analogy.setText("For Analogy explanation");
		txtPane_Analogy.setVisible(false);
		txtPane_Analogy.setEditable(false);
		container1.add(txtPane_Analogy);	
		
		//For Demo Tab

		//Further Reading ............START...........
		but_go_links = new JButton("http://en.wikipedia.org/wiki/virtual _ memory");
		but_go_links.setBounds(150,160,350,30);		
		but_go_links.addActionListener(this);		
		add(but_go_links);
		but_go_links.setVisible(false);
		
		but_go1_links = new JButton("http://en.wikipedia.org/wiki/Page_table");
		but_go1_links.setBounds(150,210,350,30);		
		but_go1_links.addActionListener(this);		
		add(but_go1_links);
		but_go1_links.setVisible(false);
		
		/*
		fr_links_Message = new JLabel("Click below for further reading : ");
		fr_links_Message.setBounds(130,100,350,30);
		fr_links_Message.setBackground(color12);		
		add(fr_links_Message);
		fr_links_Message.setVisible(false);
		*/
		fr_links_Message = new JLabel("References");
		fr_links_Message.setBounds(130,150,350,30);
		fr_links_Message.setForeground(links_color);
		fr_links_Message.setFont(new Font("",Font.BOLD,30));
		add(fr_links_Message);
		fr_links_Message.setVisible(false);
		
		fr_links_Message1 = new JLabel("Books:");
		fr_links_Message1.setBounds(130,190,350,30);
		fr_links_Message1.setForeground(Color.BLACK);
		fr_links_Message1.setFont(new Font("",Font.BOLD,20));
		add(fr_links_Message1);
		fr_links_Message1.setVisible(false);
		
		fr_links_Message2 = new JLabel("Website:");
		fr_links_Message2.setBounds(130,300,350,30);
		fr_links_Message2.setForeground(Color.BLACK);
		fr_links_Message2.setFont(new Font("",Font.BOLD,20));
		add(fr_links_Message2);
		fr_links_Message2.setVisible(false);
		
		txtPane_ref = new JTextPane();
		txtPane_ref.setBounds(130,230,600,50);			
		txtPane_ref.setVisible(false);
		txtPane_ref.setEditable(false);
		container1.add(txtPane_ref);
		
		txtPane_ref.setFont(new Font("",Font.PLAIN,15));
		txtPane_ref.setText("1. COMPUTER NETWORKS – Andrew S. Tanenbaum");
		
		
		l = new JLabel("<html><u>http://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection</u></html>");
		l.setBounds(130,340,600,50);
		l.setForeground(Color.BLUE);
		l.setVisible(false);
		l.addMouseListener(new MouseAdapter(){
		Cursor hc;	
			public void mouseEntered(MouseEvent me){
				
			    	 // System.out.println(" inside mouse listener"+me.getComponent() );
			    	  hc = new Cursor(Cursor.HAND_CURSOR);
	                   l.setCursor(hc);
			        
			      
			     
			}
			public void mousePressed(MouseEvent me) {
		 
	      try {
	    	  System.out.println(" inside mouse listener");
	    	  
	         AppletContext a = getAppletContext();
	         
	         URL url = new URL("http://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection");
	         a.showDocument(url,"_blank");
	      }
	      catch (MalformedURLException e){
	         System.out.println(e.getMessage());
	      }
			}
		});
		container1.add(l);
		
		l1 = new JLabel("<html><u>http://www.erg.abdn.ac.uk/~gorry/eg3561/lan-pages/csma-cd.html</u></html>");
		l1.setBounds(130,365,600,50);
		l1.setForeground(Color.BLUE);
		l1.setVisible(false);
		l1.addMouseListener(new MouseAdapter(){
		Cursor hc1;	
			public void mouseEntered(MouseEvent me){
				
			    	 // System.out.println(" inside mouse listener"+me.getComponent() );
			    	  hc1 = new Cursor(Cursor.HAND_CURSOR);
	                   l1.setCursor(hc1);
			        
			      
			     
			}
			public void mousePressed(MouseEvent me) {
		 
	      try {
	    	  System.out.println(" inside mouse listener");
	    	  
	         AppletContext a = getAppletContext();
	         
	         URL url = new URL("http://www.erg.abdn.ac.uk/~gorry/eg3561/lan-pages/csma-cd.html");
	         a.showDocument(url,"_blank");
	      }
	      catch (MalformedURLException e){
	         System.out.println(e.getMessage());
	      }
			}
		});
		container1.add(l1);
		l2 = new JLabel("<html><u>http://www.ethermanage.com/ethernet/10quickref/ch1qr_7.html</u></html>");
		l2.setBounds(130,390,600,50);
		l2.setForeground(Color.BLUE);
		l2.setVisible(false);
		l2.addMouseListener(new MouseAdapter(){
		Cursor hc2;	
			public void mouseEntered(MouseEvent me){
				
			    	 // System.out.println(" inside mouse listener"+me.getComponent() );
			    	  hc2 = new Cursor(Cursor.HAND_CURSOR);
	                   l2.setCursor(hc2);
			        
			      
			     
			}
			public void mousePressed(MouseEvent me) {
		 
	      try {
	    	  System.out.println(" inside mouse listener");
	    	  
	         AppletContext a = getAppletContext();
	         
	         URL url = new URL("http://www.ethermanage.com/ethernet/10quickref/ch1qr_7.html ");
	         a.showDocument(url,"_blank");
	      }
	      catch (MalformedURLException e){
	         System.out.println(e.getMessage());
	      }
			}
		});
		container1.add(l2);
		l3 = new JLabel("<html><u>http://www.mcmcse.com/cisco/guides/csma.shtml</u></html>");
		l3.setBounds(130,415,600,50);
		l3.setForeground(Color.BLUE);
		l3.setVisible(false);
		l3.addMouseListener(new MouseAdapter(){
		Cursor hc3;	
			public void mouseEntered(MouseEvent me){
				
			    	 // System.out.println(" inside mouse listener"+me.getComponent() );
			    	  hc3 = new Cursor(Cursor.HAND_CURSOR);
	                   l3.setCursor(hc3);
			        
			      
			     
			}
			public void mousePressed(MouseEvent me) {
		 
	      try {
	    	  System.out.println(" inside mouse listener");
	    	  
	         AppletContext a = getAppletContext();
	         
	         URL url = new URL("http://www.mcmcse.com/cisco/guides/csma.shtml");
	         a.showDocument(url,"_blank");
	      }
	      catch (MalformedURLException e){
	         System.out.println(e.getMessage());
	      }
			}
		});
		container1.add(l3);
		
		paneltemp = new JPanel();
		paneltemp.setLayout(null);
		add(paneltemp);
		paneltemp.setVisible(false);
		paneltemp.setBackground(Color.white);
		paneltemp.setBounds(40,90,620,55);
		
		
		
		panel1=new JPanel();			
		panel1.setLayout(null);		
		add(panel1);
		panel1.setVisible(false);
		panel1.setBounds(40,145,620,370);
		
		
		panel2=new JPanel(); 
		panel2.setLayout(null);		
		add(panel2);
		panel2.setVisible(false);		
		panel2.setBounds(40,145,620,370);
		
		
		panel3=new JPanel();  
		panel3.setLayout(null);		
		add(panel3);
		panel3.setVisible(false);		
		panel3.setBounds(40,145,620,370);
		
		panel4=new JPanel();  
		panel4.setLayout(null);		
		add(panel4);
		panel4.setVisible(false);		
		panel4.setBounds(40,145,620,370);
		
		panel5=new JPanel();  
		panel5.setLayout(null);		
		add(panel5);
		panel5.setVisible(false);		
		panel5.setBounds(40,145,620,370);
		
		fr_exercise_Message=new JLabel("Check your understanding :  ");
		fr_exercise_Message.setBounds(5,5, 230, 15);		
		paneltemp.add(fr_exercise_Message);
		fr_exercise_Message.setVisible(false);
		
		fr_exercise_Message1=new JLabel("Click buttons 1,2,..5 to view questions ");
		fr_exercise_Message1.setBounds(5,25, 275, 15);
		fr_exercise_Message1.setFont(new Font("",Font.PLAIN,12));		
		paneltemp.add(fr_exercise_Message1);
		fr_exercise_Message1.setVisible(false);
		
		fr_exercise_but1=new JButton("1");
		fr_exercise_but1.setBounds(300,15,42,20);			
		paneltemp.add(fr_exercise_but1);
		fr_exercise_but1.setVisible(false);
		fr_exercise_but1.addActionListener(this);
		
		fr_exercise_but2=new JButton("2");
		fr_exercise_but2.setBounds(342,15,42,20);		
		paneltemp.add(fr_exercise_but2);
		fr_exercise_but2.addActionListener(this);
		fr_exercise_but2.setVisible(false);
		
		fr_exercise_but3=new JButton("3");
		fr_exercise_but3.setBounds(384,15,42,20);		
		paneltemp.add(fr_exercise_but3);
		fr_exercise_but3.addActionListener(this);
		fr_exercise_but3.setVisible(false);
		
		fr_exercise_but4=new JButton("4");
		fr_exercise_but4.setBounds(426,15,42,20);		
		paneltemp.add(fr_exercise_but4);
		fr_exercise_but4.addActionListener(this);
		fr_exercise_but4.setVisible(false);
		
		fr_exercise_but5=new JButton("5");
		fr_exercise_but5.setBounds(468,15,42,20);		
		paneltemp.add(fr_exercise_but5);
		fr_exercise_but5.addActionListener(this);
		fr_exercise_but5.setVisible(false);

		txtPane_Exercise1=new JTextPane();				
		txtPane_Exercise1.setBounds(20,20,550,60);		
		txtPane_Exercise1.setVisible(true);
		txtPane_Exercise1.setText("1. A node wants to send a packet over a wireless LAN. What will CSMA/CD protocol do if the channel " +
				"is idle?" );		
		panel1.add(txtPane_Exercise1);
		
		/*ImageIcon que_1 = new ImageIcon(getClass().getClassLoader().getResource("images/que1_ans1.png"));
		JLabel que_image1 = new JLabel(que_1);
		que_image1.setBounds(20, 60, 500, 170);
		panel1.add(que_image1);*/
		
		/*ImageIcon que_1_ans = new ImageIcon(getClass().getClassLoader().getResource("images/que1_ans2.png"));
		JLabel que_image1_ans = new JLabel(que_1_ans);
		que_image1_ans.setBounds(5, 100, 600, 180);
		panel1.add(que_image1_ans);
*/
		
		
		txtPane_Exercise2=new JTextPane();				
		txtPane_Exercise2.setBounds(20,20,550,60);		
		txtPane_Exercise2.setVisible(true);		
		txtPane_Exercise2.setText("2. A node wants to send a packet over a wireless LAN. What will CSMA/CD protocol do if the channel is busy?");
		panel2.add(txtPane_Exercise2);
		
		/*ImageIcon que_2 = new ImageIcon(getClass().getClassLoader().getResource("images/que2_ans1.png"));
		JLabel que_image2 = new JLabel(que_2);
		que_image2.setBounds(20, 100, 500, 180);
		panel2.add(que_image2);
		*/
		
		txtPane_Exercise3=new JTextPane();				
		txtPane_Exercise3.setBounds(20,20,550,40);		
		txtPane_Exercise3.setVisible(true);		
		txtPane_Exercise3.setText("3. What is the jam signal sent for?");
		panel3.add(txtPane_Exercise3);
		
		/*ImageIcon que_3 = new ImageIcon(getClass().getClassLoader().getResource("images/que3.png"));
		JLabel que_image3 = new JLabel(que_3);
		que_image3.setBounds(20, 45, 500, 150);
		panel3.add(que_image3);
		
		ImageIcon que_3_ans = new ImageIcon(getClass().getClassLoader().getResource("images/ans3.png"));
		JLabel que_image3_ans = new JLabel(que_3_ans);
		que_image3_ans.setBounds(5, 180, 600, 150);
		panel3.add(que_image3_ans);
*/
		
		txtPane_Exercise4=new JTextPane();				
		txtPane_Exercise4.setBounds(20,10,550,40);		
		txtPane_Exercise4.setVisible(true);		
		txtPane_Exercise4.setText("4.  After a jam signal is sent, which of the below event happens?");
		panel4.add(txtPane_Exercise4);
		
		/*ImageIcon que_4 = new ImageIcon(getClass().getClassLoader().getResource("images/que4_con.png"));
		JLabel que_image4 = new JLabel(que_4);
		que_image4.setBounds(20, 25, 500, 150);
		panel4.add(que_image4);


		ImageIcon que_4_ans = new ImageIcon(getClass().getClassLoader().getResource("images/ans4.png"));
		JLabel que_image4_ans = new JLabel(que_4_ans);
		que_image4_ans.setBounds(5, 180, 600, 160);
		panel4.add(que_image4_ans);
*/
		
		txtPane_Exercise5=new JTextPane();				
		txtPane_Exercise5.setBounds(20,20,550,40);		
		txtPane_Exercise5.setVisible(true);		
		txtPane_Exercise5.setText("5. What is purpose of CSMA/CD protocol in wireless LAN? ");
		panel5.add(txtPane_Exercise5);
		
		/*ImageIcon que_5 = new ImageIcon(getClass().getClassLoader().getResource("images/que5_con.png"));
		JLabel que_image5 = new JLabel(que_5);
		que_image5.setBounds(20, 5, 550, 230);
		panel5.add(que_image5);
		
		ImageIcon que_5_ans = new ImageIcon(getClass().getClassLoader().getResource("images/ans5.png"));
		JLabel que_image5_ans = new JLabel(que_5_ans);
		que_image5_ans.setBounds(5, 180, 600, 160);
		panel5.add(que_image5_ans);
*/
		
		q11 = new JRadioButton("<html>a) &nbsp; Sense the channel and sends the packet immediately if it is idle	</html>");		
		q11.setBounds(25, 120, 580, 20);
		q11.addItemListener(this);
		
		q12 = new JRadioButton("<html> b) &nbsp;  Sense the channel and sends the packet if it is still idle after a random <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; period of time after the jam signal is sent	</html>");			
		q12.setBounds(25, 160, 580, 50);
		q12.addItemListener(this);
		
		q13 = new JRadioButton("<html>c) &nbsp; Both a) and b)</html>");		
		q13.setBounds(25, 220, 280, 20);		
		q13.addItemListener(this);
		
		q14 = new JRadioButton("<html>d) &nbsp;  Either a) or b)</html>");		
		q14.setBounds(25, 260, 280, 20);		
		q14.addItemListener(this);
		
		
		q1 = new ButtonGroup();
		q1.add(q11);
		q1.add(q12);
		q1.add(q13);
		q1.add(q14);
		panel1.add(q11);
		panel1.add(q12);
		panel1.add(q13);
		panel1.add(q14);
		
		q21 = new JRadioButton("<html>a) &nbsp;waits until the channel is idle and sends the packet immediately	</html> ");		
		q21.setBounds(25, 120, 580, 20);
		q21.addItemListener(this);		
		
		
		q22 = new JRadioButton("<html> b) &nbsp; waits until the channel is idle and sends the packet if it is idle even after &nbsp;&nbsp;&nbsp;&nbsp; the jam signal is sent	");		
		q22.setBounds(25, 160, 580, 50);		
		q22.addItemListener(this);
		
		q23 = new JRadioButton("<html> c) &nbsp; both a) and b) </html>");		
		q23.setBounds(25, 220, 280, 20);		
		q23.addItemListener(this);
		
		
		q24 = new JRadioButton("<html>d)&nbsp; either a) or b) </html>");		
		q24.setBounds(25, 260, 2800, 20);		
		q24.addItemListener(this);
		
		
		q2 = new ButtonGroup();
		q2.add(q21);
		q2.add(q22);
		q2.add(q23);
		q2.add(q24);
		panel2.add(q21);
		panel2.add(q22);
		panel2.add(q23);
		panel2.add(q24);
		
		q31 = new JRadioButton(" To stop transmission for a random back off time ");		
		q31.setBounds(25, 120, 480, 20);
		q31.addItemListener(this);
		
		q32 = new JRadioButton("To avoid further collision");		
		q32.setBounds(25, 160, 380, 20);
		q32.addItemListener(this);		
		
		q33 = new JRadioButton("To inform all other nodes that there is a collision");	
		q33.setBounds(25, 200, 480, 20);
		q33.addItemListener(this);	
		
		q34 = new JRadioButton("All of the above");	
		q34.setBounds(25, 240, 380, 20);
		q34.addItemListener(this);
		
		q3 = new ButtonGroup();
		q3.add(q31);
		q3.add(q32);
		q3.add(q33);
		q3.add(q34);
		
		panel3.add(q31);
		panel3.add(q32);
		panel3.add(q33);
		panel3.add(q34);
		
		q41 = new JRadioButton("<html>a) &nbsp;Nodes send packet immediately</html>");		
		q41.setBounds(25, 120, 280, 20);
		q41.addItemListener(this);
		
		q42 = new JRadioButton("<html>b)&nbsp;Nodes wait for a random period of time</html>");		
		q42.setBounds(25, 160, 580, 20);
		q42.addItemListener(this);		
		
		q43 = new JRadioButton("<html>c) &nbsp; a) and b)</html>");	
		q43.setBounds(25, 200, 280, 20);
		q43.addItemListener(this);
		
		q44 = new JRadioButton("<html>d) &nbsp; a) or b)</html>");	
		q44.setBounds(25, 240, 280, 20);
		q44.addItemListener(this);
		
		q4 = new ButtonGroup();
		q4.add(q41);
		q4.add(q42);
		q4.add(q43);
		q4.add(q44);
		
		panel4.add(q41);
		panel4.add(q42);
		panel4.add(q43);
		panel4.add(q44);
		
		q51 = new JRadioButton("Create different size of packets");		
		q51.setBounds(25, 120, 480, 20);
		q51.addItemListener(this);
		
		q52 = new JRadioButton("Detect collision of packets");		
		q52.setBounds(25, 160, 480, 20);
		q52.addItemListener(this);		
		
		q53 = new JRadioButton("Avoid collision of packets");	
		q53.setBounds(25, 200, 480, 20);
		q53.addItemListener(this);	
		
		q54 = new JRadioButton("All of the above ");	
		q54.setBounds(25, 240, 480, 20);
		q54.addItemListener(this);	

		q5 = new ButtonGroup();
		q5.add(q51);
		q5.add(q52);
		q5.add(q53);
		q5.add(q54);
		
		panel5.add(q51);
		panel5.add(q52);
		panel5.add(q53);
		panel5.add(q54);
		
		fr_exercise_answer=new JTextPane();
		fr_exercise_answer.setText("");
		fr_exercise_answer.setBounds(40,400,620,50);		
		add(fr_exercise_answer);
		fr_exercise_answer.setVisible(false);
		
		TitledBorder Answer = BorderFactory.createTitledBorder(line_border, "Answer");		
		fr_exercise_answer=new JTextPane();
		fr_exercise_answer.setText("");
		fr_exercise_answer.setBounds(40,520,620,50);
		fr_exercise_answer.setBackground(Color.white);
		fr_exercise_answer.setBorder(Answer);
		//fr_exercise_answer.setFont(new Font("",Font.BOLD,15));
		fr_exercise_answer.setLayout(new BoxLayout(fr_exercise_answer, BoxLayout.Y_AXIS));
		add(fr_exercise_answer);
		fr_exercise_answer.setVisible(false);
		fr_exercise_answer.setEditable(false);
		
		// *****************************   EXERCISE STOP ***************************

		//Help............START.......	
		//Object data_help[][]={{im_demo," This will give a demonstartion of different cases in Stop And Wait ARQ."},{im_play," This will Play the animation."},{im_pause," This will Pause the animation."},{im_glossary," This will display the terms and definitions related to ARQ."},{im_exercise," User can check their understanding by going through questionare"},{im_reference," User will get some links and books related to the topic."},{im_home," This Button will take user to the Home Page."}};
		//DefaultTableModel model_help = new DefaultTableModel(data_help,colnames_help);
		
		Object data_help[][]={{im_theory," This button will take the user to the 'Theory' section of the Learning Object(LO)."},{im_demo," This button will take the user to the 'Demo' section of the Learning Object(LO)."},{im_play," This button will add new station in Demo."},{im_reset," This button will stop Demo."},{im_pause," This button will reset the Demo."},/*{im_interaction," This button will take the user to the 'Interaction' section of the Learning Object(LO)."},*/{im_exercise," This button will take the user to the 'Quiz' section of the Learning Object(LO)."},{im_reference," This button will take the user to the 'References' section of the Learning Object(LO)."},{im_home," This Button will take user to the Home Page of the Learning Object(LO)."}};
		DefaultTableModel model_help = new DefaultTableModel(data_help,colnames_help);

		
		table_help=new JTable(model_help){
			//  Returning the Class of each column will allow different
			//  renderers to be used based on Class
			public Class getColumnClass(int column)
			{
				return getValueAt(0, column).getClass();
			}
		};
		
		table_help.setBounds(150,180,750,380);//nAppRowHeight*table_help.getRowCount());
		//table_help.setRowHeight(nAppRowHeight+18);
		table_help.setRowHeight(nAppRowHeight+24);
		table_help.setFont(new Font("",Font.PLAIN,14));
		TableColumn col = table_help.getColumnModel().getColumn(1);
		col.setPreferredWidth(700);
		table_help.enable(false);		
		table_help.setBackground(lightgrey);	
		container1.add(table_help);
		table_help.setVisible(false);
		
		fr_help_head=new JLabel(" Button                         Description");
		fr_help_head.setBounds(table_help.getBounds().x+5,table_help.getBounds().y-20, 400, 15);		
		add(fr_help_head);
		fr_help_head.setVisible(false);
		
		fr_help_Message=new JLabel("Explanation of different buttons used in animation is given below.");
		fr_help_Message.setBounds(table_help.getBounds().x-10,table_help.getBounds().y-65, 500, 15);		
		add(fr_help_Message);
		fr_help_Message.setVisible(false);
		
		//Help............STOP.......
		
		
		
		//aruna
		
	 	
	 
	 	
	 	
	 	
	 	
	 	
	 	 // Theory Label on Left Side 
	 	lbl = new JLabel("Theory");
	 	//lbl.setBounds(8,162,150,20);
	 	//lbl.setFont(new Font("Arial",Font.BOLD,15));
	 	//lbl.setForeground(Color.black);
	 	
	  // Instruction Label on Left Side
	 	lbl1 = new JLabel("Instructions");
	 	//lbl1.setBounds(8,438,150,20);
	 	//lbl1.setFont(new Font("Arial",Font.BOLD,15));
	 	//lbl1.setForeground(Color.black);
		
	 	  //Buttons
	 	
	 	
	 	
	 	
	 	
	 	
	 
	 	
	 	 // Copyright label
	 info=new JLabel("The contents in this page are licensed under");
	 	//info.setForeground(Color.black);
	 	//info.setFont(new Font("Arial",0,12));
	 	//info.setBackground(footer);
	 	//info.setBounds(713,597,270,18);
	    
	 	info1=new JLabel("Creative Commons Attribution-NonCommercial-ShareAlike 2.5 India license.");
	 	//info1.setForeground(Color.black);
	 	//info1.setFont(new Font("Arial",0,12));
	 	//info1.setBackground(footer);
	 	//info1.setBounds(544,615,438,20);
	 	
	 	
	
	 	
	 	//theory algoritham
	 	theory_button1 = new JButton("1");
		theory_button1.setFont(new Font("",Font.PLAIN,13));
		theory_button1.setForeground(grey);		
		//theory_button1.setBounds(850,555,50,20);
		theory_button1.setBounds(790,555,50,20);
		theory_button1.setVisible(false);
		theory_button1.setToolTipText("Click Here To Theory");
		container1.add(theory_button1);
		theory_button1.addActionListener(this);
		
		/*theory_button2 = new JButton("2");
		theory_button2.setFont(new Font("",Font.PLAIN,13));
		theory_button2.setForeground(grey);	
		theory_button2.setVisible(false);
		//theory_button2.setBounds(910,555,50,20);
		theory_button2.setBounds(850,555,50,20);
		theory_button2.setToolTipText("Click Here To Theory");
		container1.add(theory_button2);
		theory_button2.addActionListener(this);
		
		// button to put timing diagram in theory section
		theory_button3 = new JButton("3");
		theory_button3.setFont(new Font("",Font.PLAIN,13));
		theory_button3.setForeground(grey);	
		theory_button3.setVisible(false);
		//theory_button3.setBounds(790,555,50,20);
		theory_button3.setBounds(910,555,50,20);
		theory_button3.setToolTipText("Click Here To Theory");
		container1.add(theory_button3);
		theory_button3.addActionListener(this);
	*/
		/*txtPane_theory1 = new JTextPane();
		txtPane_theory1.setBounds(130,230,600,200);			
		txtPane_theory1.setVisible(false);
		txtPane_theory1.setEditable(false);
		container1.add(txtPane_theory1);
		
		txtPane_theory1.setFont(new Font("",Font.PLAIN,15));
		txtPane_theory1.setText("Binary data can be transmitted using a number of different   types of pulses. The choice of a particular pair of pulses to represent the symbols 1 and 0 is called Line Coding.");
		*/
		
		theory1 = new JPanel();			
				
		//ImageIcon theory_image1 = new ImageIcon(getClass().getClassLoader().getResource("images/theory2.png"));
		//JLabel theory_label1 = new JLabel(theory_image1);
		////theory_label1.setBounds(50, 15, 500, 445);
		//theory1.add(theory_label1);
		
		ImageIcon theory_fig = new ImageIcon(getClass().getClassLoader().getResource("images/theory_fig.png"));
		theoryC = new JTextPane();
		//theoryC.setBounds(50,110,900,430);
		theoryC.setBounds(50, 20, 500, 445);
		//theoryC.setContentType("text/html; charset = utf-8");
		theoryC.setContentType("text/html");
		theoryC.setText("<html><br><font size = '5' face = 'Times'><center> <b>Definitions of the components/Keywords</b></center></font><br><font face = 'Times'><ul>" +
				"<li>CSMA/CD is Carrier Sense Multiple Access / Collision Detection : <br>" +
				"<ul><li > &nbsp;Carrier Sense – the ability of a network card to sense or detect communication on the network  </li><br>" +
				"<li > &nbsp;Multiple Access – states that in that network there are multiple stations that could access the network at the same time  </li><br>" +
				"<li>&nbsp; Collision Detection – the method needed for detecting a collision  </li></ul></li><br><br>" +
				
				"<li><b>Carrier Sense Multiple Access/Collision Detect </b>(CSMA/CD) is the protocol for carrier transmission access in Ethernet networks.  <br><br>" +
				"<li><b>Carrier-sense multiple access with collision detection</b> describes how the Ethernet protocol regulates communication among nodes</li><br><br>" +
				"<li>On Ethernet, any station can send a frame at any time. Each station senses whether the medium is idle and therefore available " +
				"for use. If it is, the station begins to transmit its first frame. If another station also tries to transmit at the same " +
				"time, a collision occurs and the frames are discarded and then a jamming signal is sent throughout the network in order " +
				"to notify all stations of the collision. Each station then waits for a random period of time and retries. If another " +
				"collision occurs, the time intervals from which the random waiting time is selected are increased step by step. This is " +
				"known as exponential back off. The stations retry until successful transmission of the frame.</li><br><br>" +
				"<li> CSMA/CD is specified in the IEEE 802.3 standard.  </li><br><br>" +
				"<li> The <b>jam signal</b> is a signal that carries a 32-bit binary pattern sent by a data station to inform the other " +
				"stations that they must not transmit.</li><br><br>" +
				"<li><b>Transmit –</b> The stations (nodes) sends the frames to other stations (nodes) </li><br><br>" +
				"<li><b>Carrier Sense –</b> The stations (nodes) listen to the medium if it is idle for transmission</li><br><br>" +
				"<li><b>Back off –</b> After collision occurs, a jam signal is sent to notify all stations of the collision.  After the " +
				"jam signal is sent, the stations (nodes) wait for a random period of time called Back off period</li><br><br>" +
				"<li>The <b>flow chart for CSMA/CD protocol</b> is : </li><br><br></ul><br><br><br><br><br><br><br>" +
				"<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>" +
				"<br><br><br><br><br><br><br><br><br></font> </html>");
		
		JLabel imgLbl = new JLabel(theory_fig);
		imgLbl.setBounds(250, 830, 504, 559);
		theoryC.add(imgLbl);
		
		//JLabel imgLbl1 = new JLabel(theory_fig1);
		//imgLbl1.setBounds(270, 530, 330, 230);
		//theoryC.add(imgLbl1);
		
		add(theoryC);
		theoryC.setCaretPosition(0);
		theoryC.setEditable(false);
		
		Dimension scrollSize = new Dimension(400,600);
		theory1_scrollPane = new JScrollPane(theoryC);
		theory1_scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		theory1_scrollPane.setVisible(false);
		theory1_scrollPane.setPreferredSize(scrollSize);
		theory1_scrollPane.setBounds(22,97,957,453);
		
		add(theory1_scrollPane);
		
		/*theory2 = new JPanel();			
			
		ImageIcon theory_image2 = new ImageIcon(getClass().getClassLoader().getResource("images/theory2.png"));
		JLabel theory_label2 = new JLabel(theory_image2);
		theory_label2.setBounds(50, 5, 500, 445);
		theory2.add(theory_label2);
		
		theory2_scrollPane = new JScrollPane(theory2);
		theory2_scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		theory2_scrollPane.setVisible(false);
		theory2_scrollPane.setPreferredSize(scrollSize);
		theory2_scrollPane.setBounds(22,97,957,453);
		
		add(theory2_scrollPane);

// for timing diagram in theory content
		theory3 = new JPanel();			
		
		ImageIcon theory_image3 = new ImageIcon(getClass().getClassLoader().getResource("images/123.png"));
		JLabel theory_label3 = new JLabel("This is image 3");
		theory_label3.setBounds(50, 5, 500, 445);
		theory3.add(theory_label3);
		
		theory3_scrollPane = new JScrollPane(theory3);
		theory3_scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		theory3_scrollPane.setVisible(false);
		theory3_scrollPane.setPreferredSize(scrollSize);
		theory3_scrollPane.setBounds(22,97,957,453);
		
		add(theory3_scrollPane);
*/
		// for demo screen
		
		// main panel graph data-----------------------------------------
		// right panel data

		
	
	// end of main panel
	// interaction panel
		//textBox = new TextField();
		//textBox.setText("Enter 11 Binary Digits");
		//textBox.setEnabled(false);
		//container1.add(textBox);
		
		
	// demo section code starts here---------------------------------
	
		myNetwork = new Network();

	    

	    // the network is initialized

	    myNetwork.init();

		

		// the clock is started	

		 myTimer = new Timer(myNetwork,this,50);

		 myTimer.start(); 



	 

	    //setBackground(Color.white);

	   

	    mySetSizeButton = new Button("FrameSize:");

	    stopButton = new Button("Stop");

	    addButton = new Button("AddStation");

	    clearButton = new Button("Clear");



	    mySizeTextField = new TextField("150");
	    //mySizeTextField.setEnabled(false);
	    posTextField = new TextField(" enter number");

	    
	    container1.add(addButton);

	   container1. add(posTextField);
	   container1.add(stopButton);	

	   container1.add(clearButton);

	   container1.add(mySetSizeButton);

	   container1.add(mySizeTextField);

	  /*  setLayout (new BorderLayout());

		

		 Panel p = new Panel();

		 p.setLayout( new GridLayout(2,1));

		 	 

	    Panel p1 = new Panel();


	    p1.setBackground(Color.ORANGE);
	    p1.setLayout(new FlowLayout());

	    p1.add(addButton);

	    p1.add(posTextField);

	    p.add(p1);

	    

	    Panel panel = new Panel();

	    panel.setLayout(new FlowLayout());

	    

			

		 panel.add(stopButton);	

		 panel.add(clearButton);

	    panel.add(mySetSizeButton);

	    panel.add(mySizeTextField);
	    panel.setBackground(Color.green);
		 p.add(panel);

		

	   // add ("South", p );

	   // setSize(600,470);
	   setSize(d.width,d.height);
	    //p.setBounds(12,120, 600, 400);
	   // add(p);
	   // p.setBackground(Color.pink);
		
		
		
		*/
		
		
		
	 	
	Font myFont= new Font("Helvetica", Font.BOLD, 15);
	
	/*
	
	// play and stop button
	 btnPlay = new JButton("PLAY");
	 btnPlay.setToolTipText("Press here to play the animation");
	// btnPlay.setBounds(767,430,80,20);
	
	 btnPlay.setBackground(new Color (0xc0fd68));
	 container1.add(btnPlay);
	 
	 btnPause = new JButton("PAUSE");
	 btnPause.setToolTipText("Click Here To Pause");
	 btnPause.setBackground(new Color (0xc0fd68));
	 container1.add(btnPause);
	 btnPause.setEnabled(false);
	 
	 btnStop = new JButton("RESET");
	 btnStop.setToolTipText("Press here to Stop the animation");
	
	 btnStop.setBackground(new Color (0xff4500));
	 container1.add(btnStop);
	 btnStop.setEnabled(false);
	 // end if play and stop button
	
	  //----------ADD ACTION LISTENERS---------------
     btnPlay.addActionListener(this);
     btnStop.addActionListener(this);
     btnPause.addActionListener(this);
     
    
     
     		
		btnPlay.addActionListener(new ActionListener()
		{			    

			    public void actionPerformed(ActionEvent e) {
					
					btnPlay.setEnabled(false);
					btnStop.setEnabled(false);
					btnPause.setEnabled(true);
					
				}
			
		});
		

		btnStop.addActionListener(new ActionListener()
		{			    

			    public void actionPerformed(ActionEvent e) {
					
					btnPlay.setEnabled(true);
					btnStop.setEnabled(false);
					btnPause.setEnabled(false);
				}
			
		});
		
		btnPause.addActionListener(new ActionListener()
		{			    

			    public void actionPerformed(ActionEvent e) {
					
					btnPlay.setEnabled(true);
					btnStop.setEnabled(false);
					btnPause.setEnabled(false);
				}
			
		});
		
	*/
		
		
}//end of init
//aruna



	
public void actionPerformed(ActionEvent e){	
		
		if(e.getSource()==but_Demo){
			
			init();
			addButton.setBounds(860,180,80,25);
			posTextField.setBounds(750,180,100,25);
			stopButton.setBounds(750,220,80,20);	

			 clearButton.setBounds(850,220,80,20);

		    mySetSizeButton.setBounds(750,260,80,20);

		    mySizeTextField.setBounds(850,260,80,20);
			//btnPause.setBounds(750,220,80,25);
			//btnStop.setBounds(860,220,80,25);
			//btnPlay.setBounds(750,220,80,25);
			
			
				
			blTheory=false;
			blAnalogy=false;
			blInteraction=false;
			blGlossary=false;
			blExercise=false;
			blHelp=false;
			blhome = false;
			blLinks=false;
			demo=true;
			demo_zero=true;
			if(blInteraction==true)
			{
			//t_interaction.stop();
			}
			txtPane_explanation.setVisible(true);
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			//txtPane_theory1.setVisible(false);
			
			but_Demo.setBorder(thickBorder_demo);
		}//end of Demo Button
		
		if(e.getSource()== but_home)
		{
			System.out.println("Inside Home");
			init();
			demo=false;
			blAnalogy=false;
			blInteraction=false;
			blTheory=false;	
			blGlossary=false;
			blExercise=false;
			blHelp=false;
			blLinks=false;
			blhome = true;
			opening_screen.setVisible(true);
			opening_screen1.setVisible(true);
			lbl_openingscreen.setVisible(true);
			lbl_opening_screen_left.setVisible(true);
			opening_screen_message.setVisible(true);
			opening_screen_logo.setVisible(true);
			lbl_opening_screen_left.setVisible(true);
			lblHeader_glossary.setVisible(false);
			lblMessage_glossary.setVisible(false);
			tblLeftIndex_glossary.setVisible(false);
			txtPaneDescription_glossary.setVisible(false);
			//txtPane_theory1.setVisible(false);
			
			repaint();

		}
		
		if(e.getSource()==btnPause)
		{	
			System.out.println("PAUSE");
			repaint();
			myPause();
			
		}
		
		if(e.getSource()==but_Resume)
		{	
			System.out.println("Resume");
			but_Resume.setVisible(false);
			but_Pause.setVisible(true);
			//stopf=false;
			//t_demo=new Thread(this);
			//t_demo.resume();//start();	
		}
		
		if(e.getSource()==but_Theory)
		{
			init();				
			blGlossary=false;
			blExercise=false;
			blHelp=false;
			blhome = false;
			blLinks=false;			
			demo=false;
			blAnalogy=false;
			blInteraction=false;
			blTheory=true;
			//table_theoryApplnPrg.setVisible(true);
			//table_theoryPhymem.setVisible(true);
			//table_theorySecmem.setVisible(true);
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			//txtPane_theory1.setVisible(true);
			//txtPane_theory.setVisible(true);
			but_Theory.setBorder(thickBorder_theory);
			//txtPane_theory.setText("Write Theory Here");
			//txtPane_theory.setText("\t\t\t\t\t\t\t\t\t\tVirtual Memory Concept\nVirtual memory is a technique which gives an application program the impression that it has contiguous working memory, while in fact it may be physically fragmented and may overflow on to disk storage.\nPrograms use virtual addresses than real addresses to store data. When the program is actually executed, the virtual addresses are converted into real memory addresses. When a process requests access to its memory, it is the responsibility of the operating system to map the virtual address to the physical address. A page table is used to store mapping between virtual addresses and physical addresses.\nWhen a virtual address needs to be translated into a physical address, the TLB is searched first. If a match is found (TLB hit), the physical address is returned and memory access can continue. However, if there is no match (TLB miss),will be searched in page table to see whether a mapping exists (a Page Walk). If one exists, it is written back to the TLB  and the faulting instruction is restarted.\nThe page table lookup may fail for two reasons.1) The first is if there is no translation available for that address, meaning the memory access to that virtual address is invalid. This will typically occur because of a programming error, and the operating system must take some action to deal with the problem.2) The page table lookup may also fail if the page is not resident in physical memory. This will occur if the requested page has been swapped out of physical memory to make room for another page. In this case the page is swapped to a secondary store.Here the page to be brought back to physical  memory.\nWhen physical memory is full, one or more pages in physical memory will need to be swapped out to make room for the requested page. Which page to swap out is the subject of page replacement algorithms.");
			//theory_button1.setVisible(true);
			//theory_button2.setVisible(true);
			//theory_button3.setVisible(true);
			//theory1.setVisible(true);
			theory1_scrollPane.setVisible(true);
			//theory2_scrollPane.setVisible(false);
			//theory3_scrollPane.setVisible(false);
			repaint();
		}
		
		/*if(e.getSource()== theory_button1){
			
			theory1_scrollPane.setVisible(true);
			//theory2_scrollPane.setVisible(false);
			///theory3_scrollPane.setVisible(false);
		}*/
		
		/*if(e.getSource()== theory_button2){
			
			theory1_scrollPane.setVisible(false);
			theory2_scrollPane.setVisible(true);
			theory3_scrollPane.setVisible(false);
		}

		if(e.getSource()== theory_button3){
			
			theory1_scrollPane.setVisible(false);
			theory2_scrollPane.setVisible(false);
			theory3_scrollPane.setVisible(true);
		}*/
		/*if(e.getSource()==but_Glossary)
		{		
			init();
			demo=false;
			blAnalogy=false;
			blInteraction=false;
			blTheory=false;	
			blGlossary=true;
			blHelp=false;
			blLinks=false;
			blhome = false;
			blExercise=false;
			opening_screen.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			lblHeader_glossary.setVisible(true);
			lblMessage_glossary.setVisible(true);
			tblLeftIndex_glossary.setVisible(true);
			txtPaneDescription_glossary.setVisible(true);
			txtPane_Analogy.setVisible(false);
			but_Glossary.setBorder(thickBorder_glossary);
			FillHashMapObject();
			repaint();
		}*/
		
		if(e.getSource()==but_Links)
		{
			init();
			demo=false;
			blAnalogy=false;
			blInteraction=false;
			blTheory=false;	
			blGlossary=false;
			blExercise=false;
			blHelp=false;
			blhome = false;
			blLinks=true;
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			lblHeader_glossary.setVisible(false);
			lblMessage_glossary.setVisible(false);
			tblLeftIndex_glossary.setVisible(false);
			txtPaneDescription_glossary.setVisible(false);
			txtPane_Analogy.setVisible(false);
			//but_go_links.setVisible(true);
			//but_go1_links.setVisible(true);
			fr_links_Message.setVisible(true);
			fr_links_Message1.setVisible(true);
			fr_links_Message2.setVisible(true);
			txtPane_ref.setVisible(true);
			
			but_Links.setBorder(thickBorder_links);
			l.setVisible(true);
			l1.setVisible(true);
			l2.setVisible(true);
			l3.setVisible(true);
			//txtPane_theory1.setVisible(false);
			repaint();
		}
		
		if(e.getSource()==but_Exercise)
		{
			init();
			paneltemp.setVisible(true);
			
			fr_exercise_Message.setVisible(true);
			fr_exercise_Message1.setVisible(true);
			fr_exercise_but1.setVisible(true);
			fr_exercise_but2.setVisible(true);
			fr_exercise_but3.setVisible(true);
			fr_exercise_but4.setVisible(true);
			fr_exercise_but5.setVisible(true);
			fr_exercise_answer.setVisible(true);
			panel1.setVisible(true);					
			demo=false;
			blAnalogy=false;
			blInteraction=false;
			blTheory=false;	
			blGlossary=false;
			blExercise=true;
			blHelp=false;
			blhome = false;
			blTheory=false;
			blLinks=false;
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			lblHeader_glossary.setVisible(false);
			lblMessage_glossary.setVisible(false);
			tblLeftIndex_glossary.setVisible(false);
			txtPaneDescription_glossary.setVisible(false);
			txtPane_Analogy.setVisible(false);	
			but_Exercise.setBorder(thickBorder_exercise);
			//txtPane_theory1.setVisible(false);
			repaint();
		}

		/*
		if(e.getSource()==but_close_links)
		{
			fr_links.setVisible(false);
		}
		if(e.getSource()== but_go_links)
		{
			try {
				getAppletContext().showDocument(new URL(but_go_links.getLabel()),"_blank");
			}
			catch (Exception ee) {
				ee.printStackTrace();
			}
		}
		if(e.getSource()== but_go1_links)
		{
			try {
				getAppletContext().showDocument(new URL(but_go1_links.getLabel()),"_blank");
			}
			catch (Exception ee) {
				ee.printStackTrace();
			}
		}*/
		if(e.getSource()==but_Help)
		{
			System.out.println("INside Help");
			init();
			blHelp=true;
			blhome = false;
			//fr_exercise_Message.setVisible(false);
			//fr_exercise_Message1.setVisible(false);
			//fr_exercise_but1.setVisible(false);
			//fr_exercise_but2.setVisible(false);
			//fr_exercise_but3.setVisible(false);
			//fr_exercise_answer.setVisible(false);
			//panel1.setVisible(false);
			blTheory=false;
			demo=false;
			blAnalogy=false;
			blInteraction=false;
			blTheory=false;	
			blGlossary=false;
			blExercise=false;
			blLinks=false;
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			lblHeader_glossary.setVisible(false);
			lblMessage_glossary.setVisible(false);
			tblLeftIndex_glossary.setVisible(false);
			txtPaneDescription_glossary.setVisible(false);
			txtPane_Analogy.setVisible(false);	
			fr_help_Message.setVisible(true);
			fr_help_head.setVisible(true);
			table_help.setVisible(true);
			but_Help.setBorder(thickBorder_help);
			//txtPane_theory1.setVisible(false);
			repaint();

		}
		if(e.getSource()==but_Analogy)
		{
			init();
			blAnalogy=true;
			blTheory=false;
			demo=false;
			blInteraction=false;
			blHelp=false;
			blhome = false;
			blExercise=false;
			blGlossary=false;
			blLinks=false;
			txtPane_Analogy.setVisible(true);
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			//txtPane_theory1.setVisible(false);
			but_Analogy.setBorder(thickBorder_analogy);
			repaint();

		}
		if(e.getSource()==but_Interaction)
		{
			System.out.println("button Interaction clicked.");
			
			init();
			
			btnPause.setBounds(750,275,80,25);
			btnStop.setBounds(860,275,80,25);
			btnPlay.setBounds(750,275,80,25);
			
			
					
			blAnalogy=false;
			blTheory=false;			
			demo=false;
			blInteraction=true;
			blHelp=false;
			blhome = false;
			blExercise=false;
			blGlossary=false;
			blLinks=false;
			
			txtPane_interaction.setText("\n\nHere you can view the explanation of what is going on leftside as animation.");
			txtPane_interaction.setVisible(true);
			opening_screen.setVisible(false);
			opening_screen1.setVisible(false);
			lbl_openingscreen.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			opening_screen_message.setVisible(false);
			opening_screen_logo.setVisible(false);
			lbl_opening_screen_left.setVisible(false);
			//txtPane_theory1.setVisible(false);
			//but_Analogy.setBorder(thickBorder_analogy);
			but_Interaction.setBorder(thickBorder_interaction);
			
			repaint();
			System.out.println("after repaint interaction_first :"+interaction_first);
			
			  
			 
		}
		
		if(e.getSource()== but_credits)
		{
			System.out.println("Inside Credits");
			
			//init();
			/*demo=false;*/
			blAnalogy=false;
			//blInteraction=false;
			/*blTheory=false;	
			blGlossary=false;
			blExercise=false;
			blHelp=false;
			blhome = false;
			blLinks=false;
			//blhome = true;
			opening_screen.setVisible(true);			
			opening_screen_logo.setVisible(true);
			opening_screen1.setVisible(true);
			lbl_openingscreen.setVisible(true);
			lbl_opening_screen_left.setVisible(true);
			opening_screen_message.setVisible(true);*/
			
			if(blTheory==true){
				//theory1.setVisible(true);
				theory1_scrollPane.setVisible(true);
				//txtPane_theory1.setVisible(true);
				/*opening_screen.setVisible(false);			
				opening_screen_logo.setVisible(false);
				opening_screen1.setVisible(false);
				lbl_openingscreen.setVisible(false);
				lbl_opening_screen_left.setVisible(false);
				opening_screen_message.setVisible(false);
				*/
				
			}else if(blhome == true){
				opening_screen.setVisible(true);			
				opening_screen_logo.setVisible(true);
				opening_screen1.setVisible(true);
				lbl_openingscreen.setVisible(true);
				lbl_opening_screen_left.setVisible(true);
				opening_screen_message.setVisible(true);
			}else if(blGlossary==true){
				lblHeader_glossary.setVisible(true);
				lblMessage_glossary.setVisible(true);
				tblLeftIndex_glossary.setVisible(true);
				txtPaneDescription_glossary.setVisible(true);
				
				// home false
				/*opening_screen.setVisible(false);			
				opening_screen_logo.setVisible(false);
				opening_screen1.setVisible(false);
				lbl_openingscreen.setVisible(false);
				lbl_opening_screen_left.setVisible(false);
				opening_screen_message.setVisible(false);*/
				
			}else if(blHelp== true){
				fr_help_Message.setVisible(true);
				fr_help_head.setVisible(true);
				table_help.setVisible(true);
				//
				/*opening_screen.setVisible(false);			
				opening_screen_logo.setVisible(false);
				opening_screen1.setVisible(false);
				lbl_openingscreen.setVisible(false);
				lbl_opening_screen_left.setVisible(false);
				opening_screen_message.setVisible(false);*/
			}
			else if(demo== true){
				//btnPause.setBounds(715,320,80,25);
				//btnStop.setBounds(840,320,80,25);
				//btnPlay.setBounds(715,320,80,25);
					
				
				txtPane_explanation.setVisible(true);
				/*
				opening_screen.setVisible(false);			
				opening_screen_logo.setVisible(false);
				opening_screen1.setVisible(false);
				lbl_openingscreen.setVisible(false);
				lbl_opening_screen_left.setVisible(false);
				opening_screen_message.setVisible(false);*/
			}else if(blInteraction==true){
				//js.setBounds(750,325,200,20);
				btnPause.setBounds(750,275,80,25);
				btnStop.setBounds(860,275,80,25);
				btnPlay.setBounds(750,275,80,25);
				//textBox.setBounds(750,220,185,30);
				//bitSelect.setBounds(750,220,185,30);
				//selectionBox.setBounds(750,160,185,30);
				
				txtPane_interaction.setText("\n\nHere you can view the explanation of what is going on leftside as animation.");
				txtPane_interaction.setVisible(true);
				
			}else if(blExercise==true){
			
				fr_exercise_Message.setVisible(true);
				paneltemp.setVisible(true);
				
				fr_exercise_Message1.setVisible(true);
				fr_exercise_but1.setVisible(true);
				fr_exercise_but2.setVisible(true);
				fr_exercise_but3.setVisible(true);
				fr_exercise_but4.setVisible(false);
				fr_exercise_but5.setVisible(false);
				fr_exercise_answer.setVisible(true);
				
				panel1.setVisible(true);
				//
				/*opening_screen.setVisible(false);			
				opening_screen_logo.setVisible(false);
				opening_screen1.setVisible(false);
				lbl_openingscreen.setVisible(false);
				lbl_opening_screen_left.setVisible(false);
				opening_screen_message.setVisible(false);
				*/
			}else if(blLinks==true){
				fr_links_Message.setVisible(true);
				txtPane_ref.setVisible(true);
				//
			/*	opening_screen.setVisible(false);			
				opening_screen_logo.setVisible(false);
				opening_screen1.setVisible(false);
				lbl_openingscreen.setVisible(false);
				lbl_opening_screen_left.setVisible(false);
				opening_screen_message.setVisible(false);*/
			}
			
			
			
			//lbl_opening_screen_left.setVisible(false);
			//lblHeader_glossary.setVisible(false);
			//lblMessage_glossary.setVisible(false);
			//tblLeftIndex_glossary.setVisible(false);
			//txtPaneDescription_glossary.setVisible(false);
			//txtPane_Analogy.setVisible(false);
			//but_go_links.setVisible(true);
			//but_go1_links.setVisible(true);
			fr_credits.setVisible(true);
			txtPane_credits.setVisible(true);
			//repaint();
		}
		
		if(e.getSource()==fr_exercise_but1)
		{
			exercise = true;
			panel1.setVisible(true);
			panel2.setVisible(false);			
			panel3.setVisible(false);
			panel4.setVisible(false);			
			panel5.setVisible(false);
			q1.clearSelection();
			fr_exercise_answer.setText(" ");
			q11.setSelected(false);
			q12.setSelected(false);
			//q13.setSelected(false);
			//q14.setSelected(false);
			fr_exercise_answer.setForeground(Color.red);
			//q13.setSelected(false);
			//q14.setSelected(false);
			
		}
		
		if(e.getSource()==fr_exercise_but2)
		{
			System.out.println(" in que 2");
			exercise = true;
			panel1.setVisible(false);
			panel2.setVisible(true);			
			panel3.setVisible(false);
			panel4.setVisible(false);
			panel5.setVisible(false);
			q2.clearSelection();
			fr_exercise_answer.setText(" ");
			q21.setSelected(false);
			q22.setSelected(false);
			//q23.setSelected(false);
			//q24.setSelected(false);
			fr_exercise_answer.setForeground(Color.red);
			
		}
		if(e.getSource()==fr_exercise_but3)
		{
			exercise = true;
			panel1.setVisible(false);
			panel2.setVisible(false);
			panel3.setVisible(true);
			panel4.setVisible(false);
			panel5.setVisible(false);			
			q3.clearSelection();
			fr_exercise_answer.setText(" ");
			q31.setSelected(false);
			q32.setSelected(false);
			q33.setSelected(false);
			q34.setSelected(false);
			fr_exercise_answer.setForeground(Color.red);
		}
		
		if(e.getSource()==fr_exercise_but4)
		{
			exercise = true;
			panel1.setVisible(false);
			panel2.setVisible(false);
			panel3.setVisible(false);
			panel4.setVisible(true);
			panel5.setVisible(false);
			q4.clearSelection();
			fr_exercise_answer.setText(" ");
			q41.setSelected(false);
			q42.setSelected(false);
			q43.setSelected(false);
			q44.setSelected(false);
			fr_exercise_answer.setForeground(Color.red);
		}
		
		if(e.getSource()==fr_exercise_but5)
		{
			exercise = true;
			panel1.setVisible(false);
			panel2.setVisible(false);
			panel3.setVisible(false);
			panel4.setVisible(false);
			panel5.setVisible(true);
			q5.clearSelection();
			fr_exercise_answer.setText(" ");
			q51.setSelected(false);
			q52.setSelected(false);
			q53.setSelected(false);
			//q54.setSelected(false);
			fr_exercise_answer.setForeground(Color.red);
		}
		
		 if(e.getSource()== btnPlay) 
	 		{	
			 System.out.println(" in Play");
			 
			 	repaint();
			 	myStart();
			
	 		}
		
		
		 if(e.getSource()== btnStop)
	 		{	
	 			repaint();
	 			myStop();
	 			
	 			
	 		}
		 
		
	}


public void FillHashMapObject()
{
	map = new HashMap();
	//map.put("0", "testing");
	
	map.put("0","Signal \n\n Any physical quantity that varies with time space, or any other variable."+ 
            "In signal processing, a time signal is electrical representation of a time varying quantity."); 
	map.put("1","Signal Transformation \n\n Arithmetic operations performed on signal amplitude or time that manipulate the signal.");
	map.put("2","Shifting \n\n The shifting of a signal in time.");
	map.put("3","Delaying \n\n Causing the signal to occur late (shift to right) by subtracting a positive constant from time parameter.");
	map.put("4","Advancing\n\n Causing the signal to occur early (shift to left) by adding a positive constant to time parameter.");
	map.put("5","Scaling\n\n Compressing or expanding a signal by multiplying the time variable by some quantity.");
	map.put("6","Compression\n\n Narrowing the signal in time, by multiplying time parameter by a positive constant grater than 1.");
	map.put("7","Expansion\n\n Widening the signal in time, by multiplying time parameter by a positive constant lower than 1.");
	map.put("8","Reversal\n\n Flipping the signal over amplitude axis by multiplying time parameter by -1.");

}



	public void itemStateChanged(ItemEvent e) {
	// TODO Auto-generated method stub
		 System.out.println(" selection box"+e.getItem());
		 if (exercise == true){
			 fr_exercise_answer.setFont(new Font("",Font.BOLD,16));
				fr_exercise_answer.setForeground(Color.red);
					if(e.getSource()==q11)		{
						
						fr_exercise_answer.setForeground(new Color(0x009900));
						fr_exercise_answer.setText("Correct");
						
					}
					if(e.getSource()==q12)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q13)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q14)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q21)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
						
						
					}
					if(e.getSource()==q22)
					{
						fr_exercise_answer.setForeground(new Color(0x009900));
						fr_exercise_answer.setText("Correct");
						
					}
					if(e.getSource()==q23)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q24)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
						
					}
					if(e.getSource()==q31)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q32)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q33)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q34)
					{

						fr_exercise_answer.setForeground(new Color(0x009900));
						fr_exercise_answer.setText("Correct");
						
					}
					if(e.getSource()==q41)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q42)
					{

						fr_exercise_answer.setForeground(new Color(0x009900));
						fr_exercise_answer.setText("Correct");
					}
					if(e.getSource()==q43)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q44)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q51)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong.");
					}
					if(e.getSource()==q52)
					{
						fr_exercise_answer.setForeground(new Color(0x009900));
						fr_exercise_answer.setText("Correct");

						
					}
					if(e.getSource()==q53)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
					if(e.getSource()==q54)
					{
						fr_exercise_answer.setForeground(Color.red);
						fr_exercise_answer.setText("Wrong");
					}
		    }
		 	
} 
	public boolean action (Event ev1, Object arg) {

		if (ev1.target instanceof Button) 

		{

			String label = (String)arg;



			if (label.equals("FrameSize:")) 

			{

				myNetwork.setFrameSize(Integer.parseInt(mySizeTextField.getText()));       

				return true;

			}

			if(label.equals("Stop"))

			{

				System.out.println("pressed INIT!!");

				//init();

				

				myNetwork = new Network();

    

				// the network is initialized

				myNetwork.init();

	

				// the clock is started	

				myTimer = new Timer(myNetwork,this,50);

				myTimer.start(); 



 

				setBackground(Color.white);





				System.out.println("count = "+count);

				for(int k=0;k<count;k++)
					
					myNetwork.addStation(posArray[k]);

				//Network.stop();

				System.out.println("returned from Init!!");



				posTextField.setText("0");

			}

			

			

			if(label.equals("Clear"))

			{

				count=0;

				myNetwork = new Network();

    

				// the network is initialized

				myNetwork.init();

	

				// the clock is started	

				myTimer = new Timer(myNetwork,this,50);

				myTimer.start(); 



 

				setBackground(Color.white);

    

				for(int k=0;k<count;k++)

					myNetwork.addStation(posArray[k]);

					//Network.stop();

					System.out.println("returned from Init!!");



					posTextField.setText("0");





			}

			if(label.equals("AddStation"))

			{

				

				int position = Integer.parseInt(posTextField.getText());

				

				if((posTextField.getText()==null) || (posTextField.getText().equals("")))

				{

					alarmFrame a = new alarmFrame("Enter some value!",400,410);

					a.show();



				}
				
				else

				{	

					if(!(position>0 && position < 100))
	
					{	alarmFrame a = new alarmFrame("Give Value between 0 and 100",400,410);
	
						a.show();
	
					}

					else

					{

						int n=0;

						for(int k=0;k<count;k++)

							if(Math.abs(position-posArray[k])<15)

							{

								alarmFrame b = new alarmFrame("min. distance 15 between 2 station",400,410);

								b.show();

								n=1;

							}

							if(n!=1)

							{	

								posArray[count++]=position;

								System.out.println("pressed the button!!");

								System.out.println(position);

								if(position!=0)

									myNetwork.addStation(Integer.parseInt(posTextField.getText()));       

							}
							
						}//else

				}//else

			}//if

   	   else

				return false;

		}

		return false;



	} 


	
	public void myStart()
	{
	/*	
		System.out.println("in mystart function");
		animationrunning=true;
		//animator = new Thread(this);
		//animator.start();
		
		
		
		clearScreen=false;
		// added new below
		btnPlay.setVisible(false);
		btnPlay.setEnabled(false);
		btnPause.setVisible(true);
		btnPause.setEnabled(true);
		btnStop.setVisible(true);
		//btnStop.setEnabled(true);
		*/
		
	}
	public void myPause(){
		/*
			stopf=!stopf;
			if(stopf)
			{
				btnPause.setText("PLAY");
				btnPause.setToolTipText("Click Here To Play");
				
			}
			else if(!stopf)
			{
				btnPause.setText("PAUSE");
				btnPause.setToolTipText("Click Here To Pause");
			}
			btnPause.setVisible(true);
			btnPause.setEnabled(true);
			btnPlay.setVisible(false);
			btnPlay.setEnabled(false);
			//btnStop.setEnabled(true);
			
		*/
	}
	
	public void start()
	{		
		super.start();
		container1.revalidate();  
		
	}
	
	public synchronized void myStop()
	{/*
		animator = null;
		notify();
		stopf=false;
		counter=0;
		btnPlay.setEnabled(true);
		btnPlay.setVisible(true);
		btnPause.setVisible(false);
		btnPause.setEnabled(false);
		//selectionBox.setEnabled(true) ;
		animationrunning=false;
		clearScreen = true;
		
		flagC=0;
		
		flagC1=0;
		
		repaint();
		*/
	}

	/*public void run()
	{
     
		if(demo == true) {
			//numMove = 10;
			
			
				while (Thread.currentThread() == animator){
					while(animationrunning){	
						
						try {
							if(stopf)
								break;
							//next();
							
							animator.sleep(100);
							counter++;
							
						} catch (InterruptedException e){}
				
						
					}// while	
				}//while
				
		}//demo
		else if(blInteraction==true){
			
				while (Thread.currentThread() == animator){
					while(animationrunning){	
					
						try {
							if(stopf)
								break;
							
								//next_for_interaction();
							
							animator.sleep(100);
							counter++;
						} catch (InterruptedException e){}
					
						
					}	
				}//while
			
			
			
         }//end of if interaction
			
      
	}//end of run
	
	*/
	
	
	
	
	public void buttons() throws InterruptedException
	{
		try
		{
			
			table.enable(false);
			blPHY_MEMcheck=false;
			blPAGETABLEcheck=false;
			blSEC_MEMcheck=false;	
			interaction_incr=0;		
			//t_demo=null;
			//t_interaction=new Thread(this);
		    //t_interaction.start();
		}
		catch(Exception e)
		{
			
		}
	}
	
	 public void destroy() {

	 }



	 public void update( Graphics g ) {  



		    if ( null == myOffScreenImage || myResized ) {

		      myOffScreenImage = createImage( size().width,size().height );

		      myOffScreenGraphics = myOffScreenImage.getGraphics();

		      myResized = false;

		    }



		    myOffScreenGraphics.setColor( getBackground() );

		    myOffScreenGraphics.fillRect( 0, 0, size().width,size().height );

		    myOffScreenGraphics.setColor( g.getColor() );

		    paint( myOffScreenGraphics );



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

		  }



	  public boolean handleEvent(Event e) {

		  System.out.println("  in handleevent function_main__________%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%_______________");

		 /*   if ( myNetwork.handleEvent(e) ) {

		      repaint();

		      return true;

		    }*/

		    return super.handleEvent(e);



		  }

	
	public void stop()
	{
		
		System.out.println(" min stop function------------------------");
		current = null;	
		
		// counter = 0;
		container1.removeAll();

	}	
	
	
	

	public void mouseReleased(MouseEvent me){}
	public void mousePressed(MouseEvent me){}
	public void mouseEntered(MouseEvent me){}
	public void mouseExited(MouseEvent me){}
	

	public void mouseClicked(MouseEvent me)
	{		
		Point point= new Point(me.getX(),me.getY());
		showStatus("x1 : "+point.x+"   y1 :"+point.y);
		System.out.println("+++++++++++++"+point.x+"  id ==="+me.getID()+ " mousedown ="+MouseEvent.MOUSE_CLICKED);	
		 if ( myNetwork.handleEvent(me) ) {

		      repaint();

		      //return true;

		    }

		   // return super.handleEvent(e);

	}
	
	// for glossary table
	public void tblLeftIndexMouseClicked(MouseEvent evt) {
		//txtPaneDescription_glossary.setText(map.get(tblLeftIndex_glossary.getSelectedRow()).toString());
		txtPaneDescription_glossary.setText(map.get(String.valueOf(tblLeftIndex_glossary.getSelectedRow())).toString());
	}
	
	

	public void stateChanged(ChangeEvent e) {
		// TODO Auto-generated method stub
			
			
			
	}
		
	}


class Timer extends Thread {

	  

	  public  int myTime = 0;

	  public static int myTime1 = 0;

	  Network myNetwork;

	  Component myComponent;

	  int myInterval;



	  void setTime(int value)

	  {

	  	myTime = value;

	  }

	    

	  void sleep(int time) 

	  {

	    try { 

	      Thread.sleep(time); 

	       } 

	    catch (InterruptedException e)

	     {

	      

	     }

	   }



	  public Timer(Network network, Component component, int interval) {

	    myNetwork = network;

	    myComponent = component;

	    myInterval = interval;

	   

	  }



	  public void run() 

	  {

	    while (true) 

	    {	
	    	System.out.println(" in timer run--------------------");
	      myNetwork.update();

	      myComponent.repaint();

	      sleep(myInterval);

		   myTime++;
		   
	    }

	  } 

	}







class Counter {



  int myCount;

  

  public Counter( int start ) 

  {

    myCount = start;

  }



  public void decrement() 

  {

    myCount--;

    return;

  }



  public void increment() 

  {

    myCount++;

    return;

  }



  public int getCount() 

  {

    return myCount;

  }



  public void setCount(int count) 

  {

    myCount = count;

  }



}




/* the left and right parts of a signal are simualated */



class Part {



  Medium myMedium;



  int myMaxFrameSize;

  int myLength;



  int myOffset;

  int myStart;

  int myEnd;



  public boolean myDoneFlag;



  boolean myCollisionFlag;



  public Part( int start, int end, int offset, int frameSize, Medium medium ) 

  {

    myStart = start;

    myEnd = end;

    myOffset = offset;

    myCollisionFlag = false;

    myMaxFrameSize = frameSize;

    myMedium = medium;

    myLength = 0;

    myDoneFlag = false;

  }



  void setCollisionFlag( boolean flag ) 

  {

    myCollisionFlag = flag;

  }



  boolean getCollisionFlag() 

  {

    return myCollisionFlag;

  }



  boolean getDoneFlag() 

  {

    return myDoneFlag;

  }



  int getStart() 

  {

    return myStart;

  }



  int getEnd() 

  {

    return myEnd;

  }



  boolean isSent() 

  {

    return (myLength > myMaxFrameSize);

  }



  public void update() 

  {



    if (myLength>0 && myStart==myEnd) 

    {

      myDoneFlag=true;

      return;

    }

    myLength = myLength + Math.abs(myOffset);

    myStart = myStart + myOffset;

    if ( myLength > myMaxFrameSize )

       myEnd = myEnd + myOffset;



    if (myStart<0) 

      myStart = 0;



    if (myStart>myMedium.getBusLength() )//ACTULLY buslength=100

      myStart = myMedium.getBusLength();



    if (myEnd<0) 

      myEnd = 0;



    if (myEnd>myMedium.getBusLength() )

      myEnd = myMedium.getBusLength();



  }



}




/* the various kinds of (messages for transmission) signals are simulated here */

class Signal 

{

  

  Part myLeftPart;

  Part myRightPart;

  

  int myStationId;



  int getStationId() 

  {

    return myStationId;

  }

	public void setIdle()

	{

		myLeftPart.myDoneFlag=true;

		myRightPart.myDoneFlag=true;

	}

  Part getLeftPart() 

  {

    return myLeftPart;

  }



  Part getRightPart() 

  {

    return myRightPart;

  }



  public Signal(int stationId, int position, int frameSize, Medium medium) 

  {

    myStationId = stationId;

    myLeftPart = new Part(position,position,-1,frameSize,medium);

    myRightPart = new Part(position,position, 1,frameSize,medium);

  }



  public void update() 

  {

    myLeftPart.update();

    myRightPart.update();    

  }



  public boolean isDone() 

  {

    return myLeftPart.getDoneFlag() && myRightPart.getDoneFlag();

  }



  public boolean isCollision() 

  {

    return myLeftPart.getCollisionFlag() || myRightPart.getCollisionFlag();

  }



  boolean isSent() 

  {

    return myLeftPart.isSent() && myRightPart.isSent();

  }





}



/* the medium class which simulates the medium(-bus) */

class Medium {

  

 

  int myBusLength        = 100;	        // in meters

  

  public static final int MAX_SIGNALS = 10;





  Signal[] mySignals;



  boolean isInInterval(int value, int start, int end) 

  {

    if ( (value>=Math.min(start,end))&&(value<=Math.max(start,end)) )

      return true;

    else

      return false;

  }

	

  public void setMediumIdle()

  {

 		for(int j=0;j<10;j++)

		 if(mySignals[j]!=null)

		 	mySignals[j].setIdle();

			  

  }	

  public Medium() 

  {    

    mySignals = new Signal[MAX_SIGNALS];    

  }



  public int getBusLength() 

  {

    return myBusLength;

  }



  Signal[] getSignals() 

  {
	  System.out.println(" signals ======******"+mySignals);
    return mySignals;

  }

  



  public boolean isCollision(int station, int position) 

  {

    int index;

    for ( index=0; index<MAX_SIGNALS; index++ ) 

    {

      if ( (mySignals[index] != null) && (mySignals[index].getStationId()!=station) ) 

      {

        if ( isInInterval( position, mySignals[index].getLeftPart().getStart(), 

			   mySignals[index].getLeftPart().getEnd() ) ) 

			   {

          if ( mySignals[index].getLeftPart().getCollisionFlag() == true ) 

          {

            return true;

          }

        }

        if ( isInInterval( position, mySignals[index].getRightPart().getStart(),

			    mySignals[index].getRightPart().getEnd() ) ) {

          if ( mySignals[index].getRightPart().getCollisionFlag() == true ) {

            return true;

          }

        }        

      }

    }



    return false;

  }



  public boolean isFree(int position) {



    int index;



    for ( index=0; index<MAX_SIGNALS; index++ ) {

      if ( mySignals[index] != null ) {

        if ( isInInterval( position, mySignals[index].getLeftPart().getStart(), 

			   mySignals[index].getLeftPart().getEnd() ) ) {

          return false;

        }

        if ( isInInterval( position, mySignals[index].getRightPart().getStart(), 

			   mySignals[index].getRightPart().getEnd() ) ) {

          return false;

        }

        

        return true;

      }

    }



    return true;

  }



  void sleep(int time) {

    try { 

      Thread.sleep(time); 

    } 

    catch (InterruptedException e) {

      

    }

  }



  public boolean send( int station, int position, int frameSize) {



    int index;



    for ( index=0; index<MAX_SIGNALS; index++ ) {

      if ( mySignals[index] == null ) {

        

        mySignals[index] = new Signal( station, position, frameSize, this);



        while(true) {

          if ( mySignals[index].isSent() ) {

            return true;

          }          

          if ( isCollision(station, position) ) {

            return false;

          }          

          sleep(50);

        }

      }

    }



    return false;

  }



  public void update() {



    int i,j; 

    int start,end, id;



    

    // update signals

    for ( i=0; i<MAX_SIGNALS; i++ ) {

      if ( mySignals[i] != null ) {        

        mySignals[i].update();

          if ( mySignals[i].isDone() ) {

            mySignals[i] = null;

          }

      }

    }



    // find collisions

    for ( i=0; i<MAX_SIGNALS; i++ ) {

      if ( mySignals[i] != null ) {        

        id    = mySignals[i].getStationId();



        start = mySignals[i].getLeftPart().getStart();

        end   = mySignals[i].getLeftPart().getEnd();



        for ( j=0; j<MAX_SIGNALS; j++ ) {

          if ( (mySignals[j] != null) && (mySignals[j].getStationId() != id)) {



            if ( isInInterval( mySignals[j].getLeftPart().getStart(), start, end ) ) {

              mySignals[i].getLeftPart().setCollisionFlag(true);

              if (!mySignals[i].getRightPart().isSent())

                {

                mySignals[i].getRightPart().setCollisionFlag(true);

                mySignals[j].getLeftPart().setCollisionFlag(true);

						}

              break;

            }

            else  if ( isInInterval( mySignals[j].getLeftPart().getEnd(), start, end ) ) {

              mySignals[i].getLeftPart().setCollisionFlag(true);

              if (!mySignals[i].getRightPart().isSent())

               {

                mySignals[i].getRightPart().setCollisionFlag(true);

                 mySignals[j].getLeftPart().setCollisionFlag(true);

					}

              break;

            }

            else  if ( isInInterval( mySignals[j].getRightPart().getStart(), start, end ) ) {

              mySignals[i].getLeftPart().setCollisionFlag(true);

              if (!mySignals[i].getRightPart().isSent())

                {

                mySignals[i].getRightPart().setCollisionFlag(true);

               mySignals[j].getLeftPart().setCollisionFlag(true);

					}

              break;

            }

            else  if ( isInInterval( mySignals[j].getRightPart().getEnd(), start, end ) ) {

              mySignals[i].getLeftPart().setCollisionFlag(true);

              if (!mySignals[i].getRightPart().isSent())

               {

                mySignals[i].getRightPart().setCollisionFlag(true);

               mySignals[j].getLeftPart().setCollisionFlag(true);

					}

					break;

            }

          }

        }



        start = mySignals[i].getRightPart().getStart();

        end   = mySignals[i].getRightPart().getEnd();



        for ( j=0; j<MAX_SIGNALS; j++ ) {

          if ( (mySignals[j] != null) && (mySignals[j].getStationId() != id)) {



            if ( isInInterval( mySignals[j].getLeftPart().getStart(), start, end ) ) {

              mySignals[i].getRightPart().setCollisionFlag(true);

              if (!mySignals[i].getLeftPart().isSent())

               {

                mySignals[i].getLeftPart().setCollisionFlag(true);



               mySignals[j].getRightPart().setCollisionFlag(true);

					}

              	break;

            }

            else if ( isInInterval( mySignals[j].getLeftPart().getEnd(), start, end ) ) {

              mySignals[i].getRightPart().setCollisionFlag(true);

              if (!mySignals[i].getLeftPart().isSent())

                {

                mySignals[i].getLeftPart().setCollisionFlag(true);

                             mySignals[j].getRightPart().setCollisionFlag(true);

}					break;

            }

            else  if ( isInInterval( mySignals[j].getRightPart().getStart(), start, end ) ) {

              mySignals[i].getRightPart().setCollisionFlag(true);

              if (!mySignals[i].getLeftPart().isSent())

               {

                mySignals[i].getLeftPart().setCollisionFlag(true);

                             mySignals[j].getRightPart().setCollisionFlag(true);

              }

              break;

            }

            else  if ( isInInterval( mySignals[j].getRightPart().getEnd(), start, end ) ) {

              mySignals[i].getRightPart().setCollisionFlag(true);

              if (!mySignals[i].getLeftPart().isSent())

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            {

                mySignals[i].getLeftPart().setCollisionFlag(true);

                            mySignals[j].getRightPart().setCollisionFlag(true);

		} break;

            }

          }

        }



      }

    }

  



  }



}



/*

 *

 */

class Station extends Thread {



	public static final int IDLE = 0;

	public static final int CARRIER_SENSE = 1;

	public static final int TRANSMIT = 2;

	public static final int BACKOFF = 3;





  Counter myCounter;



  Medium myMedium;

  Network myNetwork;



  int myBackoffCount;



  int myPosition;

  int myState;

  int myId;



  Random myRandom;





  boolean mySendRequest;



  public Station(int id, int position, Network network, Medium medium) {

    myPosition = position;

    myMedium = medium;

    myNetwork = network;

    myId = id;

    myState = IDLE;

    mySendRequest = false;

    myRandom = new Random(this.hashCode());

    this.start();

  }



  public void setSendRequest( boolean flag ) {

    mySendRequest = flag;

  }



  public int getState1() {
    return myState;

  }



  public void setState(int x)

  {

  		myState=x;

  }

  

  public int getBackoffCount() {

    return myBackoffCount;

  }



  public int getBackoffRemain() {

    return myCounter.getCount();

  }



  public int getPosition() {
	  
    return myPosition;

  }



  void sleep(int time) {

    try { 

      Thread.sleep(time); 

    } 

    catch (InterruptedException e) {

      ;

    }

  }



  public void backoff(int count) {

    

    int slotTime = 200;



    myCounter = new Counter( 

      (int)((myRandom.nextDouble()*(double)Math.pow(2,count))*(double)slotTime) 

    );



    while(myCounter.getCount()>0) {

      sleep(50);

    }



  }



  public void update() {

    if (myState==BACKOFF) {

      myCounter.decrement();

    }

	  return;

  }



  public boolean send() {



    myState = CARRIER_SENSE;

    while(!myMedium.isFree(myPosition)) {

      sleep(100);

    }



    myState = TRANSMIT;

    if (myMedium.send(myId, myPosition, myNetwork.getFrameSize())==false) {

      myState = BACKOFF;

      return false;

    }

    else {

      myState = IDLE;

      return true;

    }

    

  }



  public void run() {



    while (true) {		
    	System.out.println(" in station run--------------------");
      if (mySendRequest==true) {

        mySendRequest=false;
        


        myBackoffCount = 0;

        while (send()==false) {

          backoff(myBackoffCount);

          myBackoffCount++;

        }

      }

      sleep(100);

    }

  } 



}


/* the network class which simulates the network */

class Network {



  public static final int NUM_STATIONS = 4;



  Medium myMedium;

  Station[] myStations;



  int	myFrameSize = 150; 

  int i=0;

int flag = 0;



  public Network() {

	/* initializes the medium and also indicates the number of stations */	

    myMedium = new Medium();

    myStations = new Station[NUM_STATIONS];



  }

  public void stop()

  {

  		for(int j=0;j<i;j++)

		  myStations[j].setState(0); //setting the state of stations to idle

		  flag = 0;

		  update();

	  }

	public void addStation(int x)

	{

		myStations[i] = new Station(i++,x, this, myMedium);

		

	}



 public void init() {



		i=0;

	/* the stations are initialized */

	

   // myStations[0] = new Station(0, 10, this, myMedium);

   

   // myStations[1] = new Station(1, 50, this, myMedium);

   // myStations[2] = new Station(2, 90, this, myMedium);

  }



  public int convertPositionToPixel(int position) {

    return (int)Math.round((double)(position*400)/(double)myMedium.getBusLength());    

  }





  public int getFrameSize() {

    return myFrameSize;

  }



  public void setFrameSize(int size) {

    myFrameSize = size; 

  }



  public void update() {



	int index;

	if(i>1)

     myMedium.update();

	

    for (index = 0; index</*NUM_STATIONS*/i; index++) {

		myStations[index].update();

	}

  }



  public void paint(Graphics g) {



    int index;

    int pixel;



    Integer busLength = new Integer(myMedium.getBusLength());

    Integer stationNumber;

    Integer backoffCount;

    Integer backoffRemain;



      //draw states
    g.setColor(Color.black);
    g.setFont(new Font("Times",Font.BOLD,12));
    g.drawString("Legends: ",35,510);
    g.setFont(new Font("Times",Font.PLAIN,12));
    g.drawRect(118, 498, 22, 22);
    g.setColor(Color.white);

  	 g.fillRect(120,500,20,20); 

	 g.setColor(Color.black);  

	 g.drawString("IDLE",150,510); 



    g.setColor(Color.green);

    g.fillRect(240,500,20,20);

     g.setColor(Color.black);  

    g.drawString("TRANSMIT",270,510); 



    g.setColor(Color.blue);	

	 g.fillRect(360,500,20,20);

	  g.setColor(Color.black);  

  g.drawString("CARRIER-SENSE",385,510); 

 



    g.setColor(Color.red);	

    g.fillRect(500,500,20,20); 

     g.setColor(Color.black);  

    g.drawString("BACK-OFF",530,510); 


    g.setColor(Color.red);
    g.fillRect(120, 550, 50, 10);
    g.setColor(Color.black);  
    g.drawString("Jam Signal",180,560); 
    
    g.setColor(Color.black);
    g.fillRect(280, 550, 50, 10);
    g.setColor(Color.black);  
    g.drawString("Transmission signal",340,560); 
 	

	  // draw bus

   

    g.setColor(Color.black);

    g.fillRect(100,300+50,400,10);

     

    g.drawString("0",90,325+50); 

    g.drawString(busLength.toString(),500,325+50); 

    g.drawLine(100,310+50,100,320+50);

    g.drawLine(498,310+50,498,320+50);

if(flag == 0){
    g.setFont(new Font("Times",Font.PLAIN,12));
	
	g.drawString("Minimum 2 stations should be created", 720, 360);
	g.drawString("and maximum 4 stations allowed", 720, 380);
	g.drawString("minimum distance between 2 stations ", 720, 410);
	g.drawString("should be equal to 15 or more", 720, 430);
	g.drawString("After creating stations, click on  any", 720, 460);
	g.drawString(" square box(representing station). ", 720, 480);
}
    // draw stations and indicate their states



    for (index = 0; index</*NUM_STATIONS*/i; index++) {

      pixel = convertPositionToPixel(myStations[index].getPosition());
      
      stationNumber = new Integer(index+1);
      //g.setColor(Color.blue);
      //g.fillRect(720, 400,250, 150);
      switch (myStations[index].getState1()) {
     // g.setColor(Color.black);
        case Station.IDLE:
        {
        	//g.drawString("station "+(index+1)+" is idle", 730,450+index*5);
          g.setColor(Color.white);
          //System.out.println(" station idle*****************************************"+index+1);
          break;
        }
        case Station.CARRIER_SENSE:
        {
        	g.drawString("station "+(index+1)+" is sensing", 730,400+index*22);
        	//System.out.println(" station carrier sense*****************************************"+index+1);
          g.setColor(Color.blue);
          
          break;
        }
        case Station.TRANSMIT:
        {
        	 g.drawString("station "+(index+1)+" is transmitting", 730,400+index*22);
        	//System.out.println(" station transmit*****************************************"+index+1);
          g.setColor(Color.green);
         
          break;
        }
        case Station.BACKOFF:
        {
        	g.drawString("station "+(index+1)+" is backing off due to collision", 730,400+index*22);
        	//System.out.println(" station backoff*****************************************"+index+1);
          g.setColor(Color.red);
          
          break;
        }
        default:

          g.setColor(Color.black);

      }

      

     

      g.fillRect(88+pixel,330+50,25,25);

      g.setColor(Color.black);

      g.drawRect(88+pixel,330+50,25,25);

      g.drawString("Station "+stationNumber.toString(),85+pixel,370+50); 

      g.drawLine(100+pixel,300+50, 100+pixel,330+50);      

      g.drawString("Station "+stationNumber.toString(),40,30+index*40+15+100+50); 
      


      if (myStations[index].getState1() == Station.BACKOFF) {

        backoffCount = new Integer(myStations[index].getBackoffCount());

        backoffRemain = new Integer(myStations[index].getBackoffRemain());



        g.drawString("k = " + backoffCount.toString(),90+pixel-3,300+100+50); 

        g.drawString("t = " + backoffRemain.toString(),90+pixel-3,320+100+50); 
       // g.setColor(Color.white);
       // g.fillRect(720, 420, 200, 30);
       // g.setColor(Color.black);
       // g.drawString(" Station "+stationNumber.toString()+" is backing off", 730, 430+index*2);


      }
     
    }



    // draw frames

    

    int start, end, id;

    Signal[] signals = myMedium.getSignals();



    for ( index=0; index<myMedium.MAX_SIGNALS; index++ ) {
    	System.out.println("   in draw frame-------------&&&&&&&&&&&&&&&&&&&&&&&---------------"+myMedium.MAX_SIGNALS+  " signal["+index+"] = "+signals[index]);
      if ( signals[index] != null ) {        
    	  System.out.println("   in draw frame----not null---------^^^^^^^^&&&&&&&&---------------");


        id    = signals[index].getStationId();



        start = convertPositionToPixel(signals[index].getLeftPart().getStart());

        end   = convertPositionToPixel(signals[index].getLeftPart().getEnd());        

        if (signals[index].getLeftPart().getCollisionFlag() )

			{
        	//System.out.println("   ((((((((((((   collision flag =="+signals[index].getLeftPart().getCollisionFlag());
        	g.setColor(Color.red);
       

         }

        else

          g.setColor(Color.black);
         
        
          
        System.out.println(" drawing black-@-------------------");
        g.fillRect(100+start,((id+1)*40)+100+50,Math.abs(end-start),8); 

		

        start = convertPositionToPixel(signals[index].getRightPart().getStart());

        end   = convertPositionToPixel(signals[index].getRightPart().getEnd());        

        if (signals[index].getRightPart().getCollisionFlag() )

         {
        	//System.out.println("   ((((((((((((   collision flag =="+signals[index].getLeftPart().getCollisionFlag());
          g.setColor(Color.red);
         

			}

        else

          g.setColor(Color.black);
         
        

        g.fillRect(100+end,((id+1)*40)+100+50,Math.abs(start-end),8); 
        System.out.println(" drawing red----$----------------");


      }

    }

    





  }




 // public boolean actionPerformed(ActionEvent e){	
  public boolean handleEvent(MouseEvent me) {

	  System.out.println(" 12343789432509509543&&&&&&&&&&&&&&"+ me.getID()+"      event.mousedown = "+Event.MOUSE_DOWN);
	 // if (e.getID() == Event.MOUSE_DOWN) {
    if (me.getID() == MouseEvent.MOUSE_CLICKED) {
    	System.out.println(" test$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
		if(i==1)

		{

			Frame alarm = new alarmFrame("Please add another station..min 2 stations",400,410);

			alarm.show();

			System.out.println("Please add another station..min 2 stations");

		}

		else

		{

      int index;  

      int pixel;



      for (index = 0; index<NUM_STATIONS; index++) {
    	  System.out.println(" wqeqwrerwereaewewewq==================");
        pixel = convertPositionToPixel(myStations[index].getPosition());
        System.out.println(" pixel ==*********************************="+pixel);
        if ((me.getX()>=88+pixel)&&(me.getX()<=113+pixel)&&(me.getY()>=230+100+50)&&(me.getY()<=255+100+50)) {
       // if ((me.x>=88+pixel)&&(me.x<=113+pixel)&&(me.y>=230+100)&&(me.y<=255+100)) {
        	System.out.println(" in handleevent network class___________");
         	 myStations[index].setSendRequest(true);          
         	flag = 1;
         

			



          

          return true;

        }

      }

      

    }}



    return false;



  }





}






class alarmFrame extends Frame

{

	public alarmFrame(String msg,int x1,int y1)

	{

		//setSize(170,140);
		setSize(300,150);
		setLocation(x1-200,y1-350);

		setLayout(new GridLayout(2,1));

		Label m = new Label(msg);

		Button ok = new Button("OK");

		add(m);

		add(ok);

		

		

	}

	

	public boolean action (Event ev1, Object arg)

	 {

		if (ev1.target instanceof Button) 

		{

			String label = (String)arg;



			if (label.equals("OK"))

			{

				setVisible(false);

			} 

		}

		return true;

	}

}	