Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package thread;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class enargeButton extends JFrame {
- private JButton jbtenlarge = new JButton("large");
- private JButton jbtshrink = new JButton("small");
- private BallCanvas canvas = new BallCanvas();
- public enargeButton(){
- JPanel panel = new JPanel();
- panel.add(jbtenlarge);
- panel.add(jbtshrink);
- this.add(canvas,BorderLayout.CENTER);
- this.add(panel,BorderLayout.SOUTH);
- jbtenlarge.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e){
- canvas.enlarge();
- }});
- jbtshrink.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e){
- canvas.shrink();
- }});
- }
- }
- public class circle{
- public static void main(String[] args) {
- JFrame frame = new enargeButton();
- frame.setTitle("Control Ball");
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(200,200);
- frame.setVisible(true);
- }
- }
- public static class BallCanvas extends JPanel{
- private int radius =5;
- public void enlarge(){
- radius +=1;
- repaint();
- }
- public void shrink(){
- radius -=1;
- repaint();
- }
- protected void paintCompotent(Graphics g){
- super.paintComponent(g);
- g.drawOval(getWidth()/2-radius, getHeight()/2-radius,2*radius,2*radius);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement