Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package obiektowe;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.math.BigDecimal;
- import javax.swing.AbstractButton;
- import javax.swing.JButton;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- public class MojeOkienko extends JFrame implements ActionListener
- {
- private JScrollPane scrollPane;
- private Wyplaty wyplaty;
- BigDecimal stan = new BigDecimal("500");
- JButton bStan, bWyjdz, bWyplata;
- JLabel lSaldo;
- JFrame wyplata = new JFrame("Wyplata");
- public MojeOkienko()
- {
- setSize(500,200);
- setTitle("Testowa aplikacja");
- bStan = new JButton("Stan konta: ");
- bStan.setBounds(50,50,120,40);
- bStan.addActionListener(this);
- bWyjdz = new JButton("Wyjdz");
- add(bStan);
- setLayout(null);
- bWyjdz.setBounds(120, 120, 100, 20);
- add(bWyjdz);
- bWyjdz.addActionListener(this);
- bWyplata = new JButton("Wyplac");
- add(bWyplata);
- setLayout(null);
- bWyplata.setBounds(250,120,100,20);
- bWyplata.addActionListener(this);
- lSaldo = new JLabel("");
- lSaldo.setBounds(200, 60, 100, 20);
- add(lSaldo);
- }
- public static void main(String[] args) {
- MojeOkienko okienko = new MojeOkienko();
- okienko.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- okienko.setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e)
- {
- Object zrodlo = e.getSource();
- if (zrodlo == bWyplata)
- {
- wyplaty = new Wyplaty(this);
- wyplaty.setVisible(true);
- }
- if (zrodlo == bStan)
- {
- lSaldo.setText(String.valueOf(stan +"zł"));
- }
- else if (zrodlo==bWyjdz)
- {
- dispose();
- }
- }
- class Wyplaty extends JDialog implements ActionListener
- {
- private JLabel lIlosc;
- private JTextField tIlosc;
- private JButton bCancel, bWyplac;
- private boolean WyplacData;
- public Wyplaty(JFrame owner)
- {
- super(owner, "Wyplacanie", true);
- setSize(500,200);
- setLayout(null);
- lIlosc = new JLabel("Ile chcesz wyplacic: ", JLabel.RIGHT);
- lIlosc.setBounds(0,40,150,20);
- add(lIlosc);
- tIlosc = new JTextField();
- tIlosc.setBounds(150,40,100,20);
- add(tIlosc);
- bWyplac = new JButton("Wyplac");
- bWyplac.setBounds(0,100,100,20);
- bWyplac.addActionListener(this);
- add(bWyplac);
- bCancel = new JButton("Cancel");
- bCancel.setBounds(120,100,100,20);
- bCancel.addActionListener(this);
- add(bCancel);
- }
- public String getUser()
- {
- return tIlosc.getText();
- }
- public boolean isWyplac()
- {
- return WyplacData;
- }
- @Override
- public void actionPerformed(ActionEvent e)
- {
- lSaldo.setText(String.valueOf(ustawNowyStanKonta()) + " zl");
- Object zrodlo = e.getSource();
- if (zrodlo==bWyplac)
- {
- WyplacData = true;
- }
- else
- WyplacData = false;
- setVisible(false);
- }
- public BigDecimal ustawNowyStanKonta() {
- //sprawdz stan konta
- BigDecimal stanKonta = stan;
- if (stanKonta.compareTo(BigDecimal.ZERO) > 0) {
- //pobierz kwote jaka chcesz wyplacic
- BigDecimal kwota = new BigDecimal(tIlosc.getText());
- //porownaj stan z wyplata
- //funkcja ta sprawdza czy stanKonta jest wiekszy niz kwota jaka chcesz wyplacic
- if (stanKonta.compareTo(kwota) == 1) {
- stanKonta = stanKonta.subtract(kwota); //odejmij od stanu konta wyplacana kwote
- }
- }
- return stanKonta;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement