Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. public class App extends JFrame implements ActionListener
  6. {
  7.  
  8. JLabel label;
  9. JTextField wynikLabel,wpisanyCiag;
  10. JButton generujButton;
  11. int formLiczba;
  12.  
  13. public App()
  14. {
  15. setSize(400, 150);
  16. setTitle("Ciag");
  17. setLayout(null);
  18.  
  19. label = new JLabel("Podaj nty wyraz");
  20. label.setBounds(20, 20, 140, 20);
  21. add(label);
  22.  
  23. wpisanyCiag = new JTextField();
  24. wpisanyCiag.setBounds(160, 20, 150, 20);
  25. add(wpisanyCiag);
  26.  
  27. generujButton = new JButton("OBLICZ");
  28. generujButton.setBounds(20,50,150,20);
  29. add(generujButton);
  30.  
  31. wynikLabel = new JTextField("");
  32. wynikLabel.setBounds(20,80,150,20);
  33. add(wynikLabel);
  34. generujButton.addActionListener(new ActionListener() {
  35.  
  36. @Override
  37. public void actionPerformed(ActionEvent e) {
  38. if(wpisanyCiag.getText().isEmpty() == true)
  39. {
  40. wynikLabel.setText("BRAK NUMERU WYRAZU");
  41. }else if(Integer.parseInt(wpisanyCiag.getText())<=0)
  42. {
  43. wynikLabel.setText(String.valueOf("PODAJ DODANI NUMER WYRAZU"));
  44. }else if(Integer.parseInt(wpisanyCiag.getText())>0)
  45. {
  46. wynikLabel.setText(String.valueOf(ntyWyrazCiagu(Integer.parseInt(wpisanyCiag.getText()))));
  47. }
  48. }
  49. });
  50. }
  51.  
  52. int ntyWyrazCiagu(int n){
  53. if(n == 1){
  54. return 0;
  55. }else if(n == 2){
  56. return 0;
  57. }else if (n == 3){
  58. return 1;
  59. } else return ntyWyrazCiagu(n-3)+ ntyWyrazCiagu(n-2)+ ntyWyrazCiagu(n-1);
  60. }
  61.  
  62.  
  63. public static void main(String[] args)
  64. {
  65. App aplik = new App();
  66. aplik.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  67. aplik.setVisible(true);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement