Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Moving Door

Posted by Circuit Negma on February 11, 2006


Door.java
============

import java.awt.*;
import java.applet.*;
import java.util.*;

public class Door {

/**
 *
 * @param aPoint
 */
public Door (Point aPoint) {
 this.cordinate = new Point(aPoint);

public void draw(Graphics graphics){

 graphics.fillRect(cordinate.x, cordinate.y, 30, 50);
 
 }

//instance variable
private Point cordinate;
}

____________________________________________________

MovingDoor.java
===============

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;

public class MovingDoor extends Applet implements ActionListener {
        
     private static final String RED = “Red”;
     private static final String BLUE = “Blue”;
     private Button red, blue;  
     private static final Color color1 = Color.red;
     private static final Color color2 = Color.blue;
     private Color color3;
     Door aDoor;
     private int a,b;
       
         public void init() {
        
         this.a = 0;
         this.b = 60;
         this. aDoor = new Door(new Point(a,b));
        
         this.red = new Button(RED);
         this.red.setBackground(color1);
         this.red.addActionListener(this);
        
         this.blue = new Button(BLUE);
         this.blue.setBackground(color2);
         this.blue.addActionListener(this);
        
         Panel row = new Panel(new FlowLayout(FlowLayout.CENTER,4,4));
         row.add(red);
         row.add(blue);
                 
         Panel main = new Panel(new GridLayout(1,2));
         main.add(row);
         add(main);
        
        
       }
      
 public void paint(Graphics graphics) {
 /* applet display statements go here. */
  
  
  graphics.setColor(color3);
  aDoor.draw(graphics);
  graphics.setColor(Color.black);
  graphics.drawString(“Position of Xd:> ” + a, 140, 50);
  graphics.drawString(“Position of Yd:> ” + b, 260, 50);
  setBackground(Color.white);
 }

public void actionPerformed(ActionEvent event){
  String s = event.getActionCommand();
  
  if (s.equals(BLUE) && a<440){
   this.a = this.a+20;
   this.b = 60;
   color3 = color2;
   this.aDoor  = new Door(new Point(a,b));
   System.out.println(“Position of blue button :>” +a);
   }
  else if (s.equals(RED) && a>0){
   this.a = this.a-20;
   this.b = 60;
   color3 = color1;
   this.aDoor = new Door(new Point(a,b));
   System.out.println(“Position of red button:> ” + a);
   }
   
   repaint();
   
}
}

One Response to “Moving Door”

  1. okiyohukyo said

    Here are some links that I believe will be interested

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: