Sunday, 17 July 2011

AWT package

awt:- is a package
Abstract window package

import java.awt.*;
It contains many classes like Frame class, Dialogue class, Canvas class.

*g.drawRext(x,y,width,height);    //to draw a rectangle
Eg.
g.drawRect(100,100,50,50);
*g.drawOval(x,y,width,height);    //to draw a oval
Eg.
g.drawOval(100,100,50,50);

*g.setColor(Color.red);                 //to set a color
*g.fillRect(100,100,50,50);           //to fill a rect
*g.drawLine(x,y,x1,y1);                //to draw a line
*g.drawArc(x,y,width,height,angle1,angle2);
Eg.
g.drawArc(100,100,80,80,100,60);




Ques1:-Write a program to display a frame.
Ques2:-Write a program to draw a hut.

*g.drawString(“Ashish”,100,200);
*for filling any color
Color c=new Color(255,0,0);
g.setColor(c);
*Font f=new Font(“Arial”,Font.BOLD,22);
g.setFont(f) ;

Ques3:-Write a program of marquee.
Ques4:-Write a program of digital clock (00:00:00).
Ques5:-Write a program in which two string collide and bounces back.
Ques6:-Write a program of analog clock.
Ques7:-write a program of traffic light.

Math.random()
Random is the function of math class that is available in lang package it will generate a number between 0 & 1 randomly.
0 can be generated but 1 can’t be generated.

For generating between 100&580
X=(int)(Math.random*481+100);
Y=(int)(Math.random*481+100) ;

100 is the starting point where as 481 is the difference plus 1.

*Color c=new Color(r,gr,b);

int r=(int)(Math.random()*256);
int gr=(int)(Math.random()*256);
int b=(int)(Math.random()*256);

Ques:-Write a program which generates a different names with different colors randomly.

No comments:

Post a Comment

 

About The Author


I am a B.Tech Computer Science Student. I love Programming and blogging. I am Oracle certified Java Professional. Read More
Indian Blogger

Teachers Jobs

Footer 3

Twitter Facebook RSS YouTube Google
​

All Rights Reserved ©Sun Java Masters 2013