0
Colorful Equal Bars
Definition:
Write an applet that draws four Vertical bars of equal size & of different colors such that they cover up the whole applet area. The applet should operate correctly even if it is resized.
Code:
import java.applet.*; import java.awt.*; public class equalBars extends Applet { Color[] clr = {Color.red, Color.green, Color.pink, Color.blue}; int cnt = 0; public void init() { setBackground(Color.black); } public void paint(Graphics g) { int w = getWidth(); int h = getHeight(); for(int i=0;i<4;i++) { g.setColor(clr[i]); g.fillRect(w/4*i,0,w/4,h); } } } /* <applet code="equalBars" width="500" height="500"></applet> */
Recent Comments