Results 1 to 4 of 4
Thread: Paint????
- 02-15-2011, 06:50 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Paint????
Hey guys its me again. So I'm having an issue.
Java Code:package pr1; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class SemiPongPanel extends JPanel { // start of class public static void main(String[] args) { // start of main class JFrame frame1 = new JFrame("SemiPong"); // new jframe called frame1 frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // default close // jframe on // exit JPanel panel1 = new JPanel(); // New Jpanel frame1.getContentPane().add(panel1); // Add panel1 to frame1 panel1.setPreferredSize(new Dimension(600, 400)); // size of panel frame1.pack(); // Packs the panel size into the frame frame1.setVisible(true); // Make frame visible Ball singleBall = new Ball(30, 40, 10, Color.RED); // @Override // public void paint(Graphics g){ // } } }
when placingI get an error that states. Void is an invalid type for the variable paint. But in my other program......Java Code:public void paint(Graphics g)
Java Code:package balls; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.util.Random; import javax.swing.JApplet; // Chantae M. Ross @SuppressWarnings("serial") // This got rid of a weird error i have never seen.... public class BallsApplet extends JApplet { //private Ball ball; private Ball[] testBall; private static Physics physics; public void init() { super.setSize(400, 500); //ball = new Ball(30, 30, 10, Color.green); physics = new Physics(this, this, 10); //physics.addBall(ball); testBall = new Ball[20]; for (int index = 0; index < testBall.length; index++) { testBall[index] = makeRandomBall(); physics.addBall(testBall[index]); } } @Override public void paint(Graphics g) { int redBalls = 0; int greenBalls = 0; Rectangle bounds = getBounds(); g.setColor(Color.lightGray); g.fillRect(0, 0, bounds.width, bounds.height); //ball.draw(g); for (int index = 0; index < testBall.length; index++) { testBall[index].draw(g); if (testBall[index].getColor().equals(Color.red)) redBalls++; else greenBalls++; } g.setColor(Color.BLACK); g.drawString("Chantae M. Ross", 10, 15); g.drawString("RedBalls: " + redBalls, 10, 30); g.drawString("Green Balls: " + greenBalls, 10, 45); if (redBalls == 20) physics.stopIt(); } private int randomRange(int low, int high) { Random rand = new Random(); int range = high - low; int number = low + rand.nextInt(range); return number; } private Ball makeRandomBall() { // What the hell is going on here??? // randomBalls = new Ball(randomRange(20, 200), randomRange(20, 200), // randomRange(2, 10), Color.GREEN); // return randomBalls; Ball randomBalls = new Ball(randomRange(20, 200), randomRange(20, 200), randomRange(2, 10), Color.GREEN); randomBalls.setVelocityX(randomRange(-40, 40)); randomBalls.setVelocityY(randomRange(-40, 40)); // for (int index = 0; index < randomBalls.length; index++) return randomBalls; } /* * private Ball fBall1; * * @Override public void init() { super.setSize(400, 500); * * fBall1 = new Ball(30, 30, 10, Color.GREEN); } * * @Override public void paint(Graphics g) { fBall1.draw(g); } } */ }
It works perfectly fine????
I've attached a screenshot of the error also just to clear up any confusion.
- 02-15-2011, 07:08 AM #2
Member
- Join Date
- Feb 2011
- Location
- Ahmedabad
- Posts
- 36
- Rep Power
- 0
refer the reply of Fubarable in the thread "an error in paint method"
- 02-15-2011, 07:24 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Entering super.paint(g), or paintComponent, etc doesn't work. Are you talking about the post that he is stating, the user is drawing directly to the JFrame??
- 02-15-2011, 08:00 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
Paint problem =P
By santa in forum New To JavaReplies: 7Last Post: 02-08-2011, 09:29 AM -
Paint Program Help
By ngiannini in forum AWT / SwingReplies: 12Last Post: 05-10-2010, 04:24 PM -
Some confusions with paint()
By kendaop in forum Java AppletsReplies: 1Last Post: 01-24-2009, 12:23 AM -
finished paint!
By diggitydoggz in forum New To JavaReplies: 3Last Post: 01-04-2009, 10:33 AM -
paint() and paintComponent()
By goldhouse in forum Java 2DReplies: 1Last Post: 07-17-2007, 03:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks