Hi, I'm trying to create a program that zooms a green box (from small to large) around a string of text. It starts in the center, then spreads to create a rectangle. It's a pretty simple applet, but since drawRect creates a 1-pixel border, I wanted it thicker. So instead, I used arrays to draw multiple boxes around the text to make the appearance thicker (by pixels). But this applet does not work, it creates one green box that is slightly off-center, and then creates a green dot starting from the middle, then traveling to the left corner of the applet. If someone can read this code, I'll be thankful. It will take a genius to sort my code disorganization (sorry, haste.)
public class MySitepre extends Applet implements Runnable, MouseListener, MouseMotionListener
{
private Rectangle rect = null;
private Color foreground;
private Color background;
private Color selection_color;
private Font font;
private int[] current_pos_x; // current position of one of the boxes
private int[] current_pos_y; // current position of one of the boxes
private int[] current_width; // current width of one
private int[] current_height; // current width of one
// destined position at the end of animation (of one box)
private int[] final_pos_x;
private int[] final_pos_y;
// destined width/height at end of animation (of one)
private int[] final_width;
private int[] final_height;
// start position of one box
private int[] start_pos_x;
private int[] start_pos_y;
/* these string variables are irrelevant to my problem, so ignore anything about strings/fonts, etc. */
private int stringX;
private int stringY;
private int stringHeight;
private int stringTop;
private int pause;
/* values for the arrays, totalNum is the amount of boxes (in this applet, 4) currentNum is for the FOR loops, currentNum2 (is better explained later) */
private int currentNum;
private int currentNum2;
private int totalNum;
The boxes must start out in the coordinates: first box is the very outer box in start position, to the last box, which is the very inner. This sequence must be kept even at the end of its expanding of the width/height. Please try this out, for it is a big help.
With best regards,
Ben
P.S. Don't waste too much time on this if you're getting nowhere. Thanks!
01-04-2006, 07:53 PM
destin
Instead of doing arrays, why not just draw two rectangles, one for the outline, and one the same as the background color, then draw the text over it. So it appears that you're drawing a border, when you're really just drawing a green rectangle, with some of it covered by a black rectangle.
01-04-2006, 08:21 PM
destin
Here's a simple applet to demonstrate what I'm talking about:
Code:
import java.applet.*;
import java.awt.*;
public class BorderDemo extends Applet {
/** color of the background */
private Color backColor;
/** color of the border */
private Color borderColor;
/** the width of the border */
private int borderWidth;
/**
* how far away from the edge of the screen
* that the border will be
*/
private int borderDist;
public void init() {
borderWidth = 10;
borderDist = 15;
public void paint(Graphics g) {
/*
* instead of this.getWidth() and this.getHeight(),
* you can just do getWidth() or getHeight() i just
* like to use this because im weird like that
*/
public void paint(Graphics g) {
/*
* instead of this.getWidth() and this.getHeight(),
* you can just do getWidth() or getHeight() i just
* like to use this because im weird like that
*/