anirudhp06

Border

Aug 17th, 2021
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JApplet;
  8. import javax.swing.JButton;
  9.  
  10. public class Border extends JApplet implements ActionListener {
  11.  
  12.     JButton rect,oval,square,circle;
  13.     int code;
  14.    
  15.     public void init() {
  16.        
  17.         rect=new JButton("RECTANGLE");
  18.         oval=new JButton("OVAL");
  19.         square=new JButton("SQUARE");
  20.         circle=new JButton("CIRCLE");
  21.        
  22.         setLayout(null);
  23.         rect.setBounds(100,100,150,30);square.setBounds(500,100,150,30);
  24.         oval.setBounds(100,500,150,30);circle.setBounds(500,500,150,30);
  25.        
  26.         add(rect);
  27.         add(oval);
  28.         add(circle);
  29.         add(square);
  30.        
  31.         rect.addActionListener(this);
  32.         oval.addActionListener(this);
  33.         square.addActionListener(this);
  34.         circle.addActionListener(this);    
  35.     }
  36.  
  37.     public void actionPerformed(ActionEvent ae) {
  38.         String s=ae.getActionCommand();
  39.         Graphics g= this.getGraphics(); //Create a graphics class
  40.     //  if(ae.getSource().equals(rect))
  41.         if(s.equals("RECTANGLE"))
  42.             g.drawRect(80, 80, 190, 70);
  43.         else if(s.equals("OVAL"))
  44.             g.drawOval(80, 470, 200, 80);
  45.         else if(s.equals("SQUARE"))
  46.             g.drawRect(480, 50, 200, 200);
  47.         else
  48.             g.drawOval(430, 430, 250, 250);
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment