Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Errors in screen Redraw...

  Asked By: Gin    Date: Oct 23    Category: Java    Views: 579
  

Run this code and then, using the frame edge make the window as small
as you can, then grab the top of the frame and move it around on your
screen. Next, resize the frame back to approximately its original
size, again using frame edges.

I've deleted most of the extraneous code to keep it simple. Each
should be saved into their own .java files... and compiled(javac)
independantly...

On my system the black rectangle will shift from its original
position and lock onto the left edge of the frame... does anyone have
any idea why...

a confounded demon_coder

import java.awt.*;
import javax.swing.*;

public class StripTest extends JFrame {

/** Creates new StripTest */
public StripTest() {
super("Strip Test");
setSize(640, 480);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Strip strip = new Strip(25F, 25F);
Container content = getContentPane();
content.add(strip);
setVisible(true);

}


public static void main (String args[]) {
StripTest test = new StripTest();

}

}

/////////////////////////////////////////////////////////////
///must save and compile individually

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class Strip extends JPanel {
static float fromLeft;
static float fromTop;

/** Creates new Strip */
public Strip(float xLoc, float yLoc) {
fromLeft = xLoc;
fromTop = yLoc;
}

//simple strip creation
public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
comp2D.setColor(Color.black);
Rectangle2D.Float stripBackGround = new Rectangle2D.Float
(fromLeft, fromTop, 300F, 50F);
comp2D.fill(stripBackGround);
comp2D.setColor(Color.green);
Line2D.Float line = new Line2D.Float(fromLeft, (fromTop +
25F), (fromLeft + 300F), (fromTop +25F));
comp2D.draw(line);

}

}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Errors in screen Redraw... Or get search suggestion and latest updates.




Tagged: