Link to home
Start Free TrialLog in
Avatar of mijangos
mijangos

asked on

variables for this program

hi i been trying to do a basseball inside this rectangle but i cant and also can you tell me how to make this program short by using variables thank you .

this is my code

import java.applet.*;
import java.awt.*;

public class Pruebas extends Applet

{
      public void init()
      
      {
            setBackground(Color.cyan);
      }
      
      public void paint (Graphics g)
      
      {
            g.setColor(Color.red);
            g.fillRect(50,25,75,120);
            g.setColor(Color.white);
            g.drawOval(73,93,50,50);
            g.drawArc(70,96,50,50,50,100);
      }
}


Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>also can you tell me how to make this program short by using variables thank you .

You probably ought to parameterize the coordinates in paint
SOLUTION
Avatar of petmagdy
petmagdy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also in the same way u can add paramets for the colors if u want
Are you not intending to animate the graphics?
Avatar of mijangos
mijangos

ASKER

no i just want a basic thing , not to fancy , as am a begginer
something really easy not to complicated it as am learning this language
mijangos,

 did u saw my comment? did u try it?
please not that u can drop the long main method if html file to run is enouph
yes i did but for some reason i cant see nothing when i run the programm just a blank thing no rectangle or ovals in the applet
did u run the html, don't run applet directly so the parameters are effective

or as a begining put the applet like this:

import java.applet.*;
import java.awt.*;

public class Pruebas extends Applet

{
     public void init()
     
     {
          setBackground(Color.cyan);
     }
     
     public void paint (Graphics g)
     
     {
          g.setColor(Color.red);
          g.fillRect(50,25,75,120);
          g.setColor(Color.white);
          g.drawOval(50,25,75,120);
     }
}

i created a whole new project for the one you posted , with the same class name and is not working
Make it easier for yourself by *not* using a package. Delete the package statement and operate from the current directory
Please refer to my last comment simple code I was just pointing out that u call drawOval with the same values as u call fillRect
sorry for respond late to your question , i went to school had exams today , but to the question yes i run your applet as you said only the html file and i get just a blank window

Do you have any error in the java consolle?
mijangos I was just pointing out that u call drawOval with the same values as u call fillRect, please just simply try this code first:

import java.applet.*;
import java.awt.*;

public class Pruebas extends Applet

{
     public void init()
     
     {
          setBackground(Color.cyan);
     }
     
     public void paint (Graphics g)
     
     {
          g.setColor(Color.red);
          g.fillRect(50,25,75,120);
          g.setColor(Color.white);
          g.drawOval(50,25,75,120);
     }
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
am sorry i accepted the wrong answer i was going to a petmagdy if theres a way to fix and give you the points petmagdy thanks for all the help guys
Please mijangos go the the above menu press "support" submit a link to this question and ask them to correct the accepted answer so i can get my points :(
>>am sorry i accepted the wrong answer

Can you say why posting a properly working applet deserves no points at all mijangos?
yes it worth points but i can see just  the applet but i dont see the code which is more important cehj
no problems guys

mijangos please go to Support ask a question free of points give them link to this page and ask their correction

I have no problem to split but I deserve to get points because I wrote and tested the sample specially for this question
yes thats what am going to do am going to split the points for both of you guys
>>but i dont see the code which is more important cehj

Naturally i'll give you the code ;-) Here it is:

import java.applet.*;
import java.awt.*;

public class Pruebas extends Applet {

  public void init() {
    setBackground(Color.cyan);
  }


  public void paint(Graphics g) {
    g.setColor(Color.white);
    g.fillRect(50, 50, 75, 75);
    g.setColor(Color.red);
    g.fillOval(50, 50, 75, 75);
  }
}
8-)