You are viewing our Forum Archives. To view or take place in current topics click here.
Java code help Problem no2 +rep again [solved]
Posted:

Java code help Problem no2 +rep again [solved]Posted:

FR0NTLinealpaca
  • V5 Launch
Status: Offline
Joined: Feb 26, 201212Year Member
Posts: 365
Reputation Power: 15
Status: Offline
Joined: Feb 26, 201212Year Member
Posts: 365
Reputation Power: 15
I am making a program for some uni work that im stuck with. The program allows the person to scroll through 10 squares and when 1 is selected it has a blue outline.The problem is that there is no blue outline around the square (dont know if its just i cant see it so how can i do that if it is the problem) I have put where the relative code is in bold. any help would be great and you will get some rep

private void displayBlock(Graphics g)
{

for(int i = 0; i < 10; i++)
{
if (occupant[i].equals("Empty"))
{
g.setColor(Color.green);
g.fillRect(150+(i*50), 120, aptWidth, aptHeight); //Sets the rectangle red to show the room is occupied

}
else
{
g.setColor(Color.red);
g.fillRect(150+(i*50), 120, aptWidth, aptHeight); //Sets the rectangle green to show the room is free
}
if (i == selectedApartment)
{
g.setColor(Color.blue);
g.drawRect(150+(i*50), 120, aptWidth, aptHeight);
}

g.setColor(Color.black);
g.drawRect(150+(i*50), 120, aptWidth, aptHeight);

// Draws the numbers in the Corresponding boxes
g.setColor(Color.black);
g.drawString(Integer.toString(i+1), 150+(i*50)+15, 120+25);
}

//Drawing the key allowing the user to see what the colours refer to
g.setFont(new Font("TimesRoman", Font.PLAIN, 14));
g.drawString("Key", 20,120);
g.drawString("Occupied",60,150);
g.drawString("Empty", 60, 170);

// Drawing the boxes to show what the colours mean in the key
g.setColor(Color.red);
g.fillRect(20, 130, 25, 25);
g.setColor(Color.black);
g.drawRect(20, 130, 25, 25);
g.setColor(Color.green);
g.fillRect(20,150,25,25);
g.setColor(Color.black);
g.drawRect(20,150,25,25);


} // End of displayBlock


Last edited by FR0NTLinealpaca ; edited 4 times in total
#2. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
To access an the ith array element use occupant[i], not occupant(i).
#3. Posted:
FR0NTLinealpaca
  • V5 Launch
Status: Offline
Joined: Feb 26, 201212Year Member
Posts: 365
Reputation Power: 15
Status: Offline
Joined: Feb 26, 201212Year Member
Posts: 365
Reputation Power: 15
i knew it was something stupid like that i overlooked! cheers man
#4. Posted:
ObscureCoder
  • Resident Elite
Status: Offline
Joined: Jun 29, 201310Year Member
Posts: 211
Reputation Power: 13
Status: Offline
Joined: Jun 29, 201310Year Member
Posts: 211
Reputation Power: 13
OT: I'm not sure if pasting the code broke your indentation etc. but your java coding conventions are way off in terms of formatting. It's good to be clean.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.