Advertisement
Guest User

Untitled

a guest
May 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. package obiektowe;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.WindowEvent;
  6. import java.math.BigDecimal;
  7.  
  8. import javax.swing.AbstractButton;
  9. import javax.swing.JButton;
  10. import javax.swing.JDialog;
  11. import javax.swing.JFrame;
  12. import javax.swing.JLabel;
  13. import javax.swing.JScrollPane;
  14. import javax.swing.JTextArea;
  15. import javax.swing.JTextField;
  16.  
  17. public class MojeOkienko extends JFrame implements ActionListener
  18. {
  19.  
  20. private JScrollPane scrollPane;
  21. private Wyplaty wyplaty;
  22. BigDecimal stan = new BigDecimal("500");
  23. JButton bStan, bWyjdz, bWyplata;
  24. JLabel lSaldo;
  25. JFrame wyplata = new JFrame("Wyplata");
  26.  
  27. public MojeOkienko()
  28. {
  29. setSize(500,200);
  30. setTitle("Testowa aplikacja");
  31. bStan = new JButton("Stan konta: ");
  32. bStan.setBounds(50,50,120,40);
  33. bStan.addActionListener(this);
  34.  
  35. bWyjdz = new JButton("Wyjdz");
  36. add(bStan);
  37. setLayout(null);
  38. bWyjdz.setBounds(120, 120, 100, 20);
  39. add(bWyjdz);
  40. bWyjdz.addActionListener(this);
  41.  
  42. bWyplata = new JButton("Wyplac");
  43. add(bWyplata);
  44. setLayout(null);
  45. bWyplata.setBounds(250,120,100,20);
  46. bWyplata.addActionListener(this);
  47.  
  48. lSaldo = new JLabel("");
  49. lSaldo.setBounds(200, 60, 100, 20);
  50. add(lSaldo);
  51.  
  52. }
  53. public static void main(String[] args) {
  54. MojeOkienko okienko = new MojeOkienko();
  55. okienko.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56. okienko.setVisible(true);
  57.  
  58. }
  59. @Override
  60. public void actionPerformed(ActionEvent e)
  61. {
  62. Object zrodlo = e.getSource();
  63. if (zrodlo == bWyplata)
  64. {
  65. wyplaty = new Wyplaty(this);
  66. wyplaty.setVisible(true);
  67. }
  68.  
  69. if (zrodlo == bStan)
  70. {
  71. lSaldo.setText(String.valueOf(stan +"zł"));
  72. }
  73. else if (zrodlo==bWyjdz)
  74. {
  75. dispose();
  76. }
  77. }
  78.  
  79. class Wyplaty extends JDialog implements ActionListener
  80. {
  81. private JLabel lIlosc;
  82. private JTextField tIlosc;
  83. private JButton bCancel, bWyplac;
  84. private boolean WyplacData;
  85.  
  86. public Wyplaty(JFrame owner)
  87. {
  88. super(owner, "Wyplacanie", true);
  89. setSize(500,200);
  90. setLayout(null);
  91.  
  92. lIlosc = new JLabel("Ile chcesz wyplacic: ", JLabel.RIGHT);
  93. lIlosc.setBounds(0,40,150,20);
  94. add(lIlosc);
  95.  
  96. tIlosc = new JTextField();
  97. tIlosc.setBounds(150,40,100,20);
  98. add(tIlosc);
  99.  
  100. bWyplac = new JButton("Wyplac");
  101. bWyplac.setBounds(0,100,100,20);
  102. bWyplac.addActionListener(this);
  103. add(bWyplac);
  104.  
  105. bCancel = new JButton("Cancel");
  106. bCancel.setBounds(120,100,100,20);
  107. bCancel.addActionListener(this);
  108. add(bCancel);
  109. }
  110.  
  111. public String getUser()
  112. {
  113. return tIlosc.getText();
  114. }
  115.  
  116. public boolean isWyplac()
  117. {
  118. return WyplacData;
  119. }
  120.  
  121.  
  122. @Override
  123. public void actionPerformed(ActionEvent e)
  124. {
  125.  
  126. lSaldo.setText(String.valueOf(ustawNowyStanKonta()) + " zl");
  127. Object zrodlo = e.getSource();
  128. if (zrodlo==bWyplac)
  129. {
  130.  
  131. WyplacData = true;
  132. }
  133. else
  134. WyplacData = false;
  135. setVisible(false);
  136.  
  137.  
  138.  
  139.  
  140. }
  141. public BigDecimal ustawNowyStanKonta() {
  142. //sprawdz stan konta
  143. BigDecimal stanKonta = stan;
  144. if (stanKonta.compareTo(BigDecimal.ZERO) > 0) {
  145. //pobierz kwote jaka chcesz wyplacic
  146. BigDecimal kwota = new BigDecimal(tIlosc.getText());
  147. //porownaj stan z wyplata
  148. //funkcja ta sprawdza czy stanKonta jest wiekszy niz kwota jaka chcesz wyplacic
  149. if (stanKonta.compareTo(kwota) == 1) {
  150. stanKonta = stanKonta.subtract(kwota); //odejmij od stanu konta wyplacana kwote
  151. }
  152. }
  153. return stanKonta;
  154. }
  155.  
  156.  
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement