import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Random;
/*<applet code=app1 width=300 height=300></applet>*/
public class app1 extends Applet implements ActionListener{
Button b1,b2,b3;
boolean a,b,c;
Random r = new Random();
Image img[] = new Image[3];
static int z=0;
static int m=0;
Font f[] = new Font[2];
public void init(){
setBackground(Color.blue);
b1=new Button("change bg");
b2=new Button("change img");
b3=new Button("change font");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(b1);
add(b2);
add(b3);
String str;
img[0] = getImage(getDocumentBase(),"1.jpg");
img[1] = getImage(getDocumentBase(),"2.jpg");
img[2] = getImage(getDocumentBase(),"3.jpg");
f[0]= new Font("Impact",Font.PLAIN,14);
f[1]= new Font("Dialog",Font.PLAIN,24);
}
public void paint(Graphics g){
b1.setFont(f[m]);
b2.setFont(f[m]);
b3.setFont(f[m]);
g.drawImage(img[z],20,20,200,200,this);
if(a==true){
Color c[] = {Color.red,Color.blue,Color.orange,Color.black,Color.pink};
int k = r.nextInt(5);
setBackground(c[k]);
}
if(b==true){
z=r.nextInt(3);
g.drawImage(img[z],20,20,200,200,this);
}
if(c==true){
m=r.nextInt(2);
b1.setFont(f[m]);
b2.setFont(f[m]);
b3.setFont(f[m]);
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
b=false;
a=true;
c=false;
repaint();
}
if(e.getSource()==b2){
a=false;
b=true;
c=false;
repaint();
}
if(e.getSource()==b3){
a=false;
b=false;
c=true;
repaint();
}
}
}
// OUTPUT
No comments:
Post a Comment