Advertisement
Guest User

Untitled

a guest
May 29th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. package zadanie12.pkg2;
  2.  
  3. import java.util.LinkedList;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. class Program extends JFrame{
  10. private Stos obiekt_stos;
  11. private JButton b1 = new JButton("init");
  12. private JButton b2 = new JButton("push");
  13. private JTextField t1 = new JTextField(" ");
  14. private JButton b3 = new JButton("pop");
  15. private JButton b4 = new JButton("top");
  16. private JTextField t2 = new JTextField(" ");
  17. private JButton b5 = new JButton("empty");
  18. private JTextField t3 = new JTextField(" ");
  19. private JButton b6 = new JButton("full");
  20. private JTextField t4 = new JTextField(" ");
  21. Program(){
  22. setTitle("Stos");
  23. setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  24. getContentPane().setLayout(new FlowLayout());
  25. add(b1); add(b2); add(t1); add(b3); add(b4); add(t2); add(b5); add(t3); add(b6); add(t4);
  26. pack();
  27. b1.addActionListener(new ActionListener(){
  28. public void actionPerformed(ActionEvent evt){
  29. obiekt_stos = new Stos();
  30. }
  31. });
  32. b2.addActionListener(new ActionListener(){
  33. public void actionPerformed(ActionEvent evt){
  34. int liczba_push = Integer.parseInt(t1.getText().trim());
  35. obiekt_stos.push(liczba_push);
  36. }
  37. });
  38. b3.addActionListener(new ActionListener(){
  39. public void actionPerformed(ActionEvent evt){
  40. obiekt_stos.pop();
  41. }
  42. });
  43. b4.addActionListener(new ActionListener(){
  44. public void actionPerformed(ActionEvent evt){
  45. int liczba_top = obiekt_stos.top();
  46. t2.setText(liczba_top);
  47. }
  48. });
  49. }
  50. }
  51.  
  52. class Stos{
  53. private LinkedList<Integer> stos_l = new LinkedList<>();
  54. private int rozmiar = 0;
  55. Stos(){
  56. rozmiar = 10;
  57. }
  58. public void push(int _element){
  59. stos_l.add(_element);
  60. }
  61. public void pop(){
  62. stos_l.removeLast();
  63. }
  64. public int top(){
  65. return stos_l.getLast();
  66. }
  67. public boolean pusty(){
  68. return stos_l.isEmpty();
  69. }
  70. public boolean pelny(){
  71. return stos_l.size() == rozmiar;
  72. }
  73. }
  74.  
  75. public class Zadanie122 {
  76.  
  77. public static void main(String[] args) {
  78. new Program().setVisible(true);
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement