Write a program on filling rectangles, JAVA Programming

Assignment Help:

Write a program on Filling Rectangles ?

The drawRect() method draws an open rectangle, a box if you prefer. If you need to draw a filled rectangle, use the fillRect() method. Or else the syntax is identical.
This program draws a filled square in the center of the applet. This needs you to separate the applet width and height from the rectangle width and height. Here's the code:
import java.applet.*;
import java.awt.*;

public class FillAndCenter extends Applet {

public void paint(Graphics g) {

int appletHeight = this.getSize().height;
int appletWidth = this.getSize().width;
int rectHeight = appletHeight/3;
int rectWidth = appletWidth/3;
int rectTop = (appletHeight - rectHeight)/2;
int rectLeft = (appletWidth - rectWidth)/2;

g.fillRect(rectLeft, rectTop, rectWidth-1, rectHeight-1);

}

}


Related Discussions:- Write a program on filling rectangles

Explain ftp-telnet-voip and instant messaging, Write a brief note on each o...

Write a brief note on each of the following. FTP Telnet Instant messaging VoIP FTP: File Transfer Protocol: This protocol is used to upload and download the

Connect 4 game application, This assignment is a good project for working w...

This assignment is a good project for working with 2 dimensional arrays. In this program, you will implement an ascii version of the classic game "Connect 4". Connect 4 is a 2 p

What are inner beans, When wiring beans, if a bean element is embedded to a...

When wiring beans, if a bean element is embedded to a property tag directly, then that bean is said to the Inner Bean. The disadvantage of this bean is that it cannot be reused any

Explain the use and purpose of java adapter classes, Question: (a) Exp...

Question: (a) Explain the event handling mechanism using a 'JComboBox' as example. Your answer must clearly indicate the event source, event object and event listener. Also

Describe logical operators in java, Describe Logical Operators in Java ? ...

Describe Logical Operators in Java ? The relational operators you've learned so far ( , >=, !=, ==) are enough while you only required to check one condition. Therefore what if

List the keywords which are used in java 1.1, List the keywords which are u...

List the keywords which are used in java 1.1? The list of keywords which are used in java 1.1 are given below: Keyword Purpose boole

Java Login/Register Web CMS, I need help setting up and fleshing out a basi...

I need help setting up and fleshing out a basic outline/structure for a basic Java web app using an MVC pattern

Saaa, Write a program to find the area under the curve y = f(x) between x =...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

Jsf framework compare with the struts framework, Struts framework ...

Struts framework                            J a v a Server Faces More matured since Struts has been started for a few years. It has got var

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd