2 Replies - 464 Views - Last Post: 15 February 2015 - 01:45 PM Rate Topic: -----

#1 Caleb_Dodson   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-February 15

I am having trouble defining the method repaint().

Posted 15 February 2015 - 01:17 PM

I am messing around trying to make an alternative for buttons. This is just a prototype. After compiling it, an error said " The method repaint() is undefined for the type "

I understand this probably has a no-brainer solution so please don't criticize me too harshly lol. :helpsmilie:/>/>

 import java.applet.*;
 import java.awt.*;
 /**
  * @author Dodson
  *
  */
 public class Rectangles 
 {
  Rectangle red, green, blue;
  int numColor;
  
  public void init()
 
  {
   
   red = new Rectangle(50,50,100,100);
   green = new Rectangle(50,200,100,100);
   blue = new Rectangle(50,350,100,100);
   numColor = 0;
  }
 
  public void paint(Graphics g) {
  
   
 g.setColor(Color.RED);
 g.fillRect(50,50,100,100);
 g.setColor(Color.green);
 g.fillRect(50,200,100,100);
 g.setColor(Color.blue);
 g.fillRect(50,350,100,100);
 switch(numColor)
 {
 
 case 1:
  g.setColor(Color.RED);
  g.drawString("Mouse clicked inside red",200,75);
  break;
 case 2:
  g.setColor(Color.GREEN);
  g.drawString("Mouse clicked inside green",200,225);
  break;
 case 3:
  g.setColor(Color.BLUE);
  g.drawString("Mouse clicked inside blue",200,375);
 case 4:
  g.setColor(Color.BLACK);
  g.drawString("Mouse clicked outside the colored squares",50,20);
  break;
 }
  }
  
  public boolean mouseDown(Event e, int x, int y)
  {
   
  if(red.contains(x,y))
         numColor = 1;
  else if(green.contains(x,y))
      numColor = 2;
  else if(blue.contains(x,y))
      numColor = 3;
  else
      numColor = 4;
   
  repaint(); //What the hell is wrong with you repaint??!?1
 return true;
  
  }
 } 


Is This A Good Question/Topic? 0
  • +

Replies To: I am having trouble defining the method repaint().

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2662
  • View blog
  • Posts: 4,256
  • Joined: 21-June 11

Re: I am having trouble defining the method repaint().

Posted 15 February 2015 - 01:29 PM

You did not define any method named repaint. Did you perhaps mean to inherit from a class that defines it?
Was This Post Helpful? 0
  • +
  • -

#3 Caleb_Dodson   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-February 15

Re: I am having trouble defining the method repaint().

Posted 15 February 2015 - 01:45 PM

View Postsepp2k, on 15 February 2015 - 01:29 PM, said:

You did not define any method named repaint. Did you perhaps mean to inherit from a class that defines it?


I just found what was wrong. I did not extends applet, which in turn effed everything up at the end. thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1