Circuit Negma

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

Moving Square Example

Posted by Circuit Negma on February 6, 2006



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

public class MovingSquare extends Applet implements ActionListener
 private static final String INCRE = “Increase”;
 private static final String DECRE = “Decrease”;
 private Button increase,decrease;
    Square aSquare;
    private int a,b,c,d;
 public void init() {
  this.a = 60;
  this.b = 40;
  this.aSquare =  new Square(new Point(a,b));
  this.increase = new Button(INCRE);
  this.decrease = new Button(DECRE);
  Panel row = new Panel (new FlowLayout(FlowLayout.CENTER,4,4));
  Panel main = new Panel (new GridLayout(1,2));
 public void paint( Graphics g ) {
  g.drawString(“Width: “+a,30,50);
  g.drawString(“Hight: “+b,100,50);
 public void actionPerformed(ActionEvent event){
  String s = event.getActionCommand();
  if (s.equals(INCRE) && a<160){
   this.a = a+20;
   this.b = b+20;
   this.aSquare = new Square(new Point(a,b));}
  else if (s.equals(DECRE) && a>60){
    this.a = a-20;
    this.b = b-20;
    this.aSquare = new Square(new Point(a,b));}





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

public class Square {

private Point upperCorner,aArea;

public Square (Point aPoint) {

 this.upperCorner = new Point(aPoint);
 public void draw(Graphics g) {


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: