Guest User

Untitled

a guest
Aug 11th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. class Czlowiek{
  7.  
  8. private String imie;
  9. private int buzi=0;
  10.  
  11. Czlowiek(){
  12.  
  13. }
  14.  
  15. public void nadajImie(String imie){
  16. this.imie=imie;
  17. }
  18.  
  19. public String przedstawSie(){
  20. return this.imie;
  21. }
  22.  
  23. public void dajBuzi(){
  24. ++this.buzi;
  25. System.out.println("Dales buziaka!");
  26. }
  27.  
  28. public int ileBuziakow(){
  29. return this.buzi;
  30. }
  31. }
  32.  
  33. class ButtonListener implements ActionListener{
  34. public void actionPerformed(ActionEvent e){
  35. Czlowiek osoba = new Czlowiek();
  36. osoba.dajBuzi();
  37.  
  38.  
  39. }
  40. }
  41.  
  42. public class DajBuzi {
  43.  
  44. public static void main(String[] args){
  45.  
  46. Czlowiek Domi = new Czlowiek();
  47. Domi.nadajImie("Domi");
  48. JFrame frame = new JFrame("Daj buziaka");
  49. JButton b1 = new JButton("Daj buziaka!");
  50. ButtonListener list = new ButtonListener();
  51. JLabel label = new JLabel("Nazywam sie "+ Domi.przedstawSie() + " i dostalem juz " + Domi.ileBuziakow() + " buziakow" );
  52.  
  53. b1.setSize(90, 50);
  54. b1.setLocation(200, 200);
  55. b1.addActionListener(list);
  56. frame.add(label);
  57. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58. frame.setSize(300,300);
  59. frame.setVisible(true);
  60. frame.add(b1);
  61.  
  62.  
  63. }
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment