java - JComponent subclass not appearing -
okay. writing ball class , ball not displayed. tried adding other components container , displayed, think safe assume problem ball. class code:
import java.awt.color; import java.awt.graphics; import javax.swing.jcomponent; public class ball extends jcomponent { public ball() { ballx = (window.window_width - ball_diameter) / 2; bally = (window.window_height - ball_diameter) / 2; } @override public void paintcomponent(graphics g) { super.paintcomponent(g); g.drawrect(5, 5, 50, 50); g.setcolor(color.green); g.filloval(ballx, bally, ball_diameter, ball_diameter); g.dispose(); } public void setx(int x) { ballx = x; } public void sety(int y) { bally = y; } private int ballx; private int bally; public static final int ball_diameter = 30; } the first rect used testing. doesn't appear neither....
make sure component has preferred size larger (0, 0):
@override public dimension getpreferredsize() { return new dimension(500, 500); }
Comments
Post a Comment