Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JApplet;
- import javax.swing.JButton;
- public class Border extends JApplet implements ActionListener {
- JButton rect,oval,square,circle;
- int code;
- public void init() {
- rect=new JButton("RECTANGLE");
- oval=new JButton("OVAL");
- square=new JButton("SQUARE");
- circle=new JButton("CIRCLE");
- setLayout(null);
- rect.setBounds(100,100,150,30);square.setBounds(500,100,150,30);
- oval.setBounds(100,500,150,30);circle.setBounds(500,500,150,30);
- add(rect);
- add(oval);
- add(circle);
- add(square);
- rect.addActionListener(this);
- oval.addActionListener(this);
- square.addActionListener(this);
- circle.addActionListener(this);
- }
- public void actionPerformed(ActionEvent ae) {
- String s=ae.getActionCommand();
- Graphics g= this.getGraphics(); //Create a graphics class
- // if(ae.getSource().equals(rect))
- if(s.equals("RECTANGLE"))
- g.drawRect(80, 80, 190, 70);
- else if(s.equals("OVAL"))
- g.drawOval(80, 470, 200, 80);
- else if(s.equals("SQUARE"))
- g.drawRect(480, 50, 200, 200);
- else
- g.drawOval(430, 430, 250, 250);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment