Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication12;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class JavaApplication12 extends JFrame implements ActionListener {
- ButtonGroup buttonGroup1;
- JButton jButton1;
- JLabel jLabel1;
- JLabel jLabel2;
- JRadioButton jRadioButton1;
- JRadioButton jRadioButton2;
- JRadioButton jRadioButton3;
- JRadioButton jRadioButton4;
- JTextField jTextField1;
- JTextField jTextField2;
- JTextField jTextField3;
- public JavaApplication12(){
- // super("Kalulator");
- // setLayout(new GridLayout());
- buttonGroup1 = new ButtonGroup();
- jLabel1 = new JLabel();
- jLabel2 = new JLabel();
- jTextField1 = new JTextField();
- jTextField2 = new JTextField();
- jRadioButton1 = new JRadioButton();
- jRadioButton2 = new JRadioButton();
- jRadioButton3 = new JRadioButton();
- jRadioButton4 = new JRadioButton();
- jButton1 = new JButton("Oblicz");
- jTextField3 = new JTextField(" ");
- jButton1.addActionListener(this);
- add(jButton1);
- add(jTextField3);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jLabel1.setText("Podaj x");
- jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jLabel2.setText("Podaj y");
- buttonGroup1.add(jRadioButton1);
- jRadioButton1.setText("Dodawanie");
- buttonGroup1.add(jRadioButton2);
- jRadioButton2.setText("Odejmowanie");
- buttonGroup1.add(jRadioButton3);
- jRadioButton3.setText("Mnozenie");
- buttonGroup1.add(jRadioButton4);
- jRadioButton4.setText("Dzielenie");
- jButton1.setText("Oblicz");
- jTextField3.setEditable(false);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jTextField3))
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(27, 27, 27)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2)))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jRadioButton1))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jRadioButton3)))
- .addGap(36, 36, 36)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton4)
- .addComponent(jRadioButton2)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jTextField1)
- .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)))))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(4, 4, 4)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addGap(7, 7, 7)
- .addComponent(jLabel2))
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextField2)))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jRadioButton1)
- .addComponent(jRadioButton2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jRadioButton3)
- .addComponent(jRadioButton4))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- pack();
- setVisible(true);
- }
- public static void main(String[] args) throws Exception {
- JavaApplication12 app=new JavaApplication12();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Object o=e.getSource(); //uzyskanie obiektu, na którym wykonano zdarzenie e
- double z1 = Double.parseDouble(jTextField1.getText());
- double z2 = Double.parseDouble(jTextField2.getText());
- double d=z1+z2, od=z1-z2, m=z1*z2, dz=z1/z2;
- if (o==jButton1 && jRadioButton1.isSelected()==true)
- jTextField3.setText(Double.toString(d));
- if (o==jButton1 && jRadioButton2.isSelected()==true)
- jTextField3.setText(Double.toString(od));
- if (o==jButton1 && jRadioButton3.isSelected()==true)
- jTextField3.setText(Double.toString(m));
- if (o==jButton1 && jRadioButton4.isSelected()==true)
- jTextField3.setText(Double.toString(dz));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement