SHARE
TWEET

Untitled

a guest Apr 24th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.swing.*;
  2. import javax.swing.event.ChangeEvent;
  3. import javax.swing.event.ChangeListener;
  4. import java.awt.*;
  5.  
  6. public class Epitrohoid {
  7.     private JPanel MainPanel;
  8.     private JSpinner radiusSpinner;
  9.     private JLabel Radius;
  10.     private JLabel S;
  11.     private JTextArea SText;
  12.     private CanvasPanel canvasPanel;
  13.  
  14.     public Epitrohoid() {
  15.         radiusSpinner.addChangeListener(new ChangeListener() {
  16.             @Override
  17.             public void stateChanged(ChangeEvent e) {
  18.                 int radius = (int) radiusSpinner.getValue();
  19.                 double area = Math.PI * radius * radius;
  20.                 canvasPanel.setRadius(radius);
  21.                 SText.setText(String.format("%.2f", area));
  22.             }
  23.         });
  24.         radiusSpinner.setValue(50);
  25.     }
  26.     public static void main(String[] args) {
  27.         JFrame frame = new JFrame("Epitrohoid");
  28.         Epitrohoid app = new Epitrohoid();
  29.         app.createUIComponents();
  30.         frame.setPreferredSize(new Dimension(300, 500));
  31.         frame.setResizable(false);
  32.         frame.setContentPane(app.MainPanel);
  33.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.         frame.pack();
  35.         frame.setVisible(true);
  36.     }
  37.  
  38.     private void createUIComponents() {
  39.         canvasPanel = new CanvasPanel();
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top