Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- class Czlowiek{
- private String imie;
- private int buzi=0;
- Czlowiek(){
- }
- public void nadajImie(String imie){
- this.imie=imie;
- }
- public String przedstawSie(){
- return this.imie;
- }
- public void dajBuzi(){
- ++this.buzi;
- System.out.println("Dales buziaka!");
- }
- public int ileBuziakow(){
- return this.buzi;
- }
- }
- class ButtonListener implements ActionListener{
- public void actionPerformed(ActionEvent e){
- Czlowiek osoba = new Czlowiek();
- osoba.dajBuzi();
- }
- }
- public class DajBuzi {
- public static void main(String[] args){
- Czlowiek Domi = new Czlowiek();
- Domi.nadajImie("Domi");
- JFrame frame = new JFrame("Daj buziaka");
- JButton b1 = new JButton("Daj buziaka!");
- ButtonListener list = new ButtonListener();
- JLabel label = new JLabel("Nazywam sie "+ Domi.przedstawSie() + " i dostalem juz " + Domi.ileBuziakow() + " buziakow" );
- b1.setSize(90, 50);
- b1.setLocation(200, 200);
- b1.addActionListener(list);
- frame.add(label);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(300,300);
- frame.setVisible(true);
- frame.add(b1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment