Circuit Negma

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

Shape Changer and shifter

Posted by Circuit Negma on February 11, 2006


Exam.java
===========

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

public class Exam {

private Point upperCorner;

public Exam (Point aPoint){

 this.upperCorner = new Point(aPoint);
  }
 
 public void circle (Graphics g) {
   
   g.drawOval(this.upperCorner.x,this.upperCorner.y,10,10);
  }
 public void square(Graphics g) {
 
   g.drawRect(this.upperCorner.x,this.upperCorner.y,10,10);
 }
 
 }

________________________________________________

Shapes.java
==============
/*
 Trivial applet that displays a string – 4/96 PNL
 Updated stationery – 8/2000 C.Phan
*/

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

public class Shaps extends Applet implements ActionListener
{

 Exam aExam;
 private int a,b;
 private Button Circle,Square,Reset;
 private static final String CIRCLE = “Circle”;
 private static final String SQUARE = “Square”;
 private static final String RESET = “Reset”;
 private boolean cir,squa;
 
 public void init() {
  
  this.cir = true;
  this.a = 0;
  this.b = 50;
  this.aExam = new Exam(new Point(a,b));
  
  this.Circle = new Button(CIRCLE);
  this.Circle.addActionListener(this);
  this.Square = new Button(SQUARE);
  this.Square.addActionListener(this);
  this.Reset = new Button(RESET);
  this.Reset.addActionListener(this);
  
  Panel main = new Panel(new GridLayout(1,3));
  main.add(Circle);
  main.add(Square);
  main.add(Reset);
  add(main);
  
  repaint();
 }
 
 public void paint( Graphics g ) {
  if (cir){
  aExam.circle(g);}
  else
  aExam.square(g);
 }
 
 public void actionPerformed(ActionEvent event){
  String s = event.getActionCommand();
  
  if (s.equals(CIRCLE)){
   this.a = a+10;
   this.b = 50;
   this.aExam = new Exam(new Point(a,b));
   this.cir = true;
   this.squa = false;
   }
  else if (s.equals(SQUARE)){
   this.a = a+10;
   this.b = 50;
   this.aExam = new Exam(new Point(a,b));
   this.cir = false;
   this.squa = true;}
  else if (s.equals(RESET)){
   this.a = 0;
   this.b = 50;
   this.aExam = new Exam(new Point(a,b));
   this.cir = true;
   this.squa = false;}
  
   repaint();

}

}

_______________________________________________

 

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: