Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zadanie12.pkg2;
- import java.util.LinkedList;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- class Program extends JFrame{
- private Stos obiekt_stos;
- private JButton b1 = new JButton("init");
- private JButton b2 = new JButton("push");
- private JTextField t1 = new JTextField(" ");
- private JButton b3 = new JButton("pop");
- private JButton b4 = new JButton("top");
- private JTextField t2 = new JTextField(" ");
- private JButton b5 = new JButton("empty");
- private JTextField t3 = new JTextField(" ");
- private JButton b6 = new JButton("full");
- private JTextField t4 = new JTextField(" ");
- Program(){
- setTitle("Stos");
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- getContentPane().setLayout(new FlowLayout());
- add(b1); add(b2); add(t1); add(b3); add(b4); add(t2); add(b5); add(t3); add(b6); add(t4);
- pack();
- b1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent evt){
- obiekt_stos = new Stos();
- }
- });
- b2.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent evt){
- int liczba_push = Integer.parseInt(t1.getText().trim());
- obiekt_stos.push(liczba_push);
- }
- });
- b3.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent evt){
- obiekt_stos.pop();
- }
- });
- b4.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent evt){
- int liczba_top = obiekt_stos.top();
- t2.setText(liczba_top);
- }
- });
- }
- }
- class Stos{
- private LinkedList<Integer> stos_l = new LinkedList<>();
- private int rozmiar = 0;
- Stos(){
- rozmiar = 10;
- }
- public void push(int _element){
- stos_l.add(_element);
- }
- public void pop(){
- stos_l.removeLast();
- }
- public int top(){
- return stos_l.getLast();
- }
- public boolean pusty(){
- return stos_l.isEmpty();
- }
- public boolean pelny(){
- return stos_l.size() == rozmiar;
- }
- }
- public class Zadanie122 {
- public static void main(String[] args) {
- new Program().setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement