Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class App extends JFrame implements ActionListener
- {
- JLabel label;
- JTextField wynikLabel,wpisanyCiag;
- JButton generujButton;
- int formLiczba;
- public App()
- {
- setSize(400, 150);
- setTitle("Ciag");
- setLayout(null);
- label = new JLabel("Podaj nty wyraz");
- label.setBounds(20, 20, 140, 20);
- add(label);
- wpisanyCiag = new JTextField();
- wpisanyCiag.setBounds(160, 20, 150, 20);
- add(wpisanyCiag);
- generujButton = new JButton("OBLICZ");
- generujButton.setBounds(20,50,150,20);
- add(generujButton);
- wynikLabel = new JTextField("");
- wynikLabel.setBounds(20,80,150,20);
- add(wynikLabel);
- generujButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if(wpisanyCiag.getText().isEmpty() == true)
- {
- wynikLabel.setText("BRAK NUMERU WYRAZU");
- }else if(Integer.parseInt(wpisanyCiag.getText())<=0)
- {
- wynikLabel.setText(String.valueOf("PODAJ DODANI NUMER WYRAZU"));
- }else if(Integer.parseInt(wpisanyCiag.getText())>0)
- {
- wynikLabel.setText(String.valueOf(ntyWyrazCiagu(Integer.parseInt(wpisanyCiag.getText()))));
- }
- }
- });
- }
- int ntyWyrazCiagu(int n){
- if(n == 1){
- return 0;
- }else if(n == 2){
- return 0;
- }else if (n == 3){
- return 1;
- } else return ntyWyrazCiagu(n-3)+ ntyWyrazCiagu(n-2)+ ntyWyrazCiagu(n-1);
- }
- public static void main(String[] args)
- {
- App aplik = new App();
- aplik.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- aplik.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement