pro47.java

import java.applet.Applet; import java.awt.*; import java.awt.event.*; //<applet code="pro47" height="400" width="400"></applet> public class pro47 extends Applet { int height=200,width=200; TextField t1,t2; Button b1; Label l1,l2; Color randomColor; int R,G,B; public void init() { t1=new TextField(); l1=new Label("ENTER WIDTH"); l2=new Label("ENTER HEIGHT"); t2=new TextField(); b1=new Button("check"); R = (int) (Math.random( )*256); G = (int)(Math.random( )*256); B= (int)(Math.random( )*256); randomColor = new Color(R, G, B); setLayout(null); l1.setBounds(30,30,100,20); t1.setBounds(200,30,80,20); l2.setBounds(30,60,100,20); t2.setBounds(200,60,80,20); b1.setBounds(50,100,50,20); add(l1); add(l2); add(t1); add(t2); add(b1); b1.addActionListener(new lol()); } public class lol implements ActionListener { public void actionPerformed(ActionEvent e) { width=Integer.parseInt(t1.getText()); height=Integer.parseInt(t2.getText()); if (e.getSource() == b1) { R = (int) (Math.random( )*256); G = (int)(Math.random( )*256); B= (int)(Math.random( )*256); randomColor = new Color(R, G, B); repaint(); } } } public void paint(Graphics g) { g.setColor(randomColor); g.fillOval(100,100,width,height); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.