Buttons1.java program code


import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class Buttons1 extends Applet implements ActionListener { int top = 50; int left = 25; int size = 60; int step = 20; Button shrink, grow; public void init() { // set up "SHRINK" button shrink = new Button("Draw It Smaller"); add( shrink ); shrink.addActionListener( this ); // set up "GROW" button grow = new Button("Draw It Larger"); add( grow ); grow.addActionListener( this ); } public void actionPerformed( ActionEvent event ) { if (event.getSource() == shrink) { // shrink button was pressed size = size - step; } else if (event.getSource() == grow) { // grow button pressed size = size + step; } repaint(); } public void paint( Graphics g ) { g.drawRect( left, top, size, size ); } }