Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package thread;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. public class enargeButton extends JFrame {
  6.    
  7.     private JButton jbtenlarge = new JButton("large");
  8.     private JButton jbtshrink = new JButton("small");
  9.     private BallCanvas canvas = new BallCanvas();
  10.    
  11.     public enargeButton(){
  12.         JPanel panel = new JPanel();
  13.         panel.add(jbtenlarge);
  14.         panel.add(jbtshrink);
  15.         this.add(canvas,BorderLayout.CENTER);
  16.         this.add(panel,BorderLayout.SOUTH);
  17.     jbtenlarge.addActionListener(new ActionListener() {
  18.         public void actionPerformed(ActionEvent e){
  19.             canvas.enlarge();
  20.         }});
  21.     jbtshrink.addActionListener(new ActionListener() {
  22.         public void actionPerformed(ActionEvent e){
  23.             canvas.shrink();
  24.         }});  
  25.     }
  26. }
  27.     public class circle{
  28.     public static void main(String[] args) {
  29.         JFrame frame = new enargeButton();
  30.         frame.setTitle("Control Ball");
  31.         frame.setLocationRelativeTo(null);
  32.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.         frame.setSize(200,200);
  34.         frame.setVisible(true);
  35.        
  36.     }
  37.     }
  38.     public static class BallCanvas extends JPanel{
  39.         private int radius =5;
  40.         public void enlarge(){
  41.             radius +=1;
  42.             repaint();
  43.         }
  44.        public void shrink(){
  45.            radius -=1;
  46.            repaint();
  47.        }
  48.        
  49.        protected void paintCompotent(Graphics g){
  50.            super.paintComponent(g);
  51.            g.drawOval(getWidth()/2-radius, getHeight()/2-radius,2*radius,2*radius);
  52.        }
  53.        
  54.        
  55.        
  56.     }
  57.    
  58.    
  59.    
  60.    
  61.    
  62.    
  63.    
  64.    
  65.    
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement