Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.34 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication12;
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11.  
  12.  
  13. public class JavaApplication12 extends JFrame implements ActionListener {
  14.  
  15.      ButtonGroup buttonGroup1;
  16.     JButton jButton1;
  17.     JLabel jLabel1;
  18.     JLabel jLabel2;
  19.     JRadioButton jRadioButton1;
  20.     JRadioButton jRadioButton2;
  21.     JRadioButton jRadioButton3;
  22.     JRadioButton jRadioButton4;
  23.     JTextField jTextField1;
  24.     JTextField jTextField2;
  25.     JTextField jTextField3;
  26.    
  27.    public JavaApplication12(){
  28. //       super("Kalulator");
  29. //       setLayout(new GridLayout());
  30.         buttonGroup1 = new ButtonGroup();
  31.         jLabel1 = new JLabel();
  32.         jLabel2 = new JLabel();
  33.         jTextField1 = new JTextField();
  34.         jTextField2 = new JTextField();
  35.         jRadioButton1 = new JRadioButton();
  36.         jRadioButton2 = new JRadioButton();
  37.         jRadioButton3 = new JRadioButton();
  38.         jRadioButton4 = new JRadioButton();
  39.         jButton1 = new JButton("Oblicz");
  40.         jTextField3 = new JTextField("   ");
  41.  
  42.         jButton1.addActionListener(this);
  43.         add(jButton1);
  44.         add(jTextField3);
  45.        
  46.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47.  
  48.         jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  49.         jLabel1.setText("Podaj x");
  50.  
  51.         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  52.         jLabel2.setText("Podaj y");
  53.  
  54.         buttonGroup1.add(jRadioButton1);
  55.         jRadioButton1.setText("Dodawanie");
  56.  
  57.         buttonGroup1.add(jRadioButton2);
  58.         jRadioButton2.setText("Odejmowanie");
  59.  
  60.         buttonGroup1.add(jRadioButton3);
  61.         jRadioButton3.setText("Mnozenie");
  62.  
  63.         buttonGroup1.add(jRadioButton4);
  64.         jRadioButton4.setText("Dzielenie");
  65.  
  66.         jButton1.setText("Oblicz");
  67.        jTextField3.setEditable(false);
  68.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  69.         getContentPane().setLayout(layout);
  70.         layout.setHorizontalGroup(
  71.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  72.             .addGroup(layout.createSequentialGroup()
  73.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  74.                     .addGroup(layout.createSequentialGroup()
  75.                         .addContainerGap()
  76.                         .addComponent(jTextField3))
  77.                     .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
  78.                     .addGroup(layout.createSequentialGroup()
  79.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  80.                             .addGroup(layout.createSequentialGroup()
  81.                                 .addGap(27, 27, 27)
  82.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  83.                                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
  84.                                     .addComponent(jLabel2)))
  85.                             .addGroup(layout.createSequentialGroup()
  86.                                 .addContainerGap()
  87.                                 .addComponent(jRadioButton1))
  88.                             .addGroup(layout.createSequentialGroup()
  89.                                 .addContainerGap()
  90.                                 .addComponent(jRadioButton3)))
  91.                         .addGap(36, 36, 36)
  92.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93.                             .addComponent(jRadioButton4)
  94.                             .addComponent(jRadioButton2)
  95.                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  96.                                 .addComponent(jTextField1)
  97.                                 .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)))))
  98.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  99.         );
  100.         layout.setVerticalGroup(
  101.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102.             .addGroup(layout.createSequentialGroup()
  103.                 .addContainerGap()
  104.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  105.                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
  106.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
  107.                 .addGap(4, 4, 4)
  108.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  109.                     .addGroup(layout.createSequentialGroup()
  110.                         .addGap(7, 7, 7)
  111.                         .addComponent(jLabel2))
  112.                     .addGroup(layout.createSequentialGroup()
  113.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  114.                         .addComponent(jTextField2)))
  115.                 .addGap(18, 18, 18)
  116.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  117.                     .addComponent(jRadioButton1)
  118.                     .addComponent(jRadioButton2))
  119.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  120.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  121.                     .addComponent(jRadioButton3)
  122.                     .addComponent(jRadioButton4))
  123.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  124.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
  125.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  126.                 .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
  127.                 .addContainerGap())
  128.         );
  129.  
  130.         pack();
  131.         setVisible(true);
  132.        
  133.        
  134.        
  135.    }
  136.    
  137.    
  138.     public static void main(String[] args) throws Exception {
  139.          JavaApplication12 app=new JavaApplication12();
  140.     }
  141.  
  142.     @Override
  143.     public void actionPerformed(ActionEvent e) {
  144.            Object o=e.getSource(); //uzyskanie obiektu, na którym wykonano zdarzenie e
  145.           double z1 = Double.parseDouble(jTextField1.getText());
  146.         double z2 = Double.parseDouble(jTextField2.getText());
  147.         double d=z1+z2, od=z1-z2, m=z1*z2, dz=z1/z2;
  148.      
  149.        
  150.    
  151.  if (o==jButton1 && jRadioButton1.isSelected()==true)
  152.     jTextField3.setText(Double.toString(d));
  153.  
  154.  if (o==jButton1 && jRadioButton2.isSelected()==true)
  155.     jTextField3.setText(Double.toString(od));
  156.  
  157.  if (o==jButton1 && jRadioButton3.isSelected()==true)
  158.     jTextField3.setText(Double.toString(m));
  159.  
  160.  if (o==jButton1 && jRadioButton4.isSelected()==true)
  161.     jTextField3.setText(Double.toString(dz));
  162.    
  163.     }
  164.  
  165.      
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement