Here is a simple graphics programs which adds some stars on the screen.
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
import javax.sw
The ACM Java Task Force framework is designed "to teach Java to first-year computing students without having those students overwhelmed by its complexity." To achieve this, it intercepts all mouse and keyboard events in a way that precludes interferes with normal JApplet
interaction. Note that the other examples exhibit this same behavior. This example is an alternative using the Swing API.
Addendum: Compiling under Java 1.5 seems to restore the expected functionality.
import acm.graphics.GMath;
import acm.graphics.GPolygon;
import acm.program.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This program creates a five-pointed star every time the user clicks the mouse
* on the canvas.
*/
public class DrawStarMap extends GraphicsProgram {
public void init() {
addMouseListeners();
add(new JButton("ClearN"), NORTH);
add(new JButton("ClearW"), WEST);
add(new JButton("ClearE"), EAST);
add(new JButton("ClearS"), SOUTH);
addActionListeners();
}
/*
* Called whenever the user clicks the mouse.
*/
public void mouseClicked(MouseEvent e) {
GStar star = new GStar(STAR_SIZE);
star.setFilled(true);
add(star, e.getX(), e.getY());
}
/*
* Removes all the graphical objects from the canvas
*/
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
if (e.getActionCommand().startsWith("Clear")) {
removeAll();
}
}
/*
* Private constants
*/
private static final double STAR_SIZE = 20;
private static class GStar extends GPolygon {
...
}
}
I am figuring this out ....
add(fillCheckBox, NORTH); // SOUTH to NORTH
add(new JButton("Clear"), NORTH); // SOUTH to NORTH
how come switching the position from SOUTH
to NORTH
works great ..
UPDATE :
As well as EAST
constraint is not properly working.
May be there is some bug with SOUTH
and EAST
constraints.
OUTPUT :