• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a box with one half orange and the other black? using awt? diagonals

 
Justin Robbins
Ranch Hand
Posts: 121
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to make the height and width dimensions fine. But unfamiliar with the awt class. I am stuck on how I would create a perfect cut and have the right side of the square orange the left side of the square black.



So this creates a perfect slice right down the middle of the box. However, the problem is I am not sure why, I was experimenting with different combinations and that just sort of happened by trial and error. But now I have a diagonal orange line down the middle. But each side of it is then grey.

Using the awt import. How could I create one side of the orange line all orange and the other side of the orange line all black?


Thanks
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you posted makes no sense to me and I have no idea what you are trying to do.

The code has two loops based on row and column. But the setColor(...) method only references the row variable, which seems wrong to me.

Post a proper SSCCE that demonstrates the problem.

To do custom painting you would probably use the Graphics.fillRect(...) method.

Start with the section from the Swing tutorial on Custom Painting that shows how to draw a red rectangle.

Download the demo code and then modify it for your actual requirement.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use AWT Components. If you are not familiar with GUI programming in Swing it might be better to go straight to using JavaFX because Swing is probably on its way out.
 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering your other questions, I'd focus on learning basic/core Java first and only then try to mess with GUI stuff. Get the basics right first.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justin Robbins wrote:. . . this creates a perfect slice right down the middle of the box. However, the problem is I am not sure why, . . .
Because you are setting all the pixels whose y value is less then their x value to orange. At least I think that is what you are doing. Remember that x goes left to right and y top to bottom by default.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!