Android/Patró observador amb exemples: diferència entre les revisions

Contingut suprimit Contingut afegit
Cap resum de modificació
Cap resum de modificació
Línia 158:
}
</source>
<br />
<br />
<br />
 
Java amb un botó i una label:
 
 
<source lang="java">
package listeners;
 
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
 
/**
*
* @author Jaume
*/
public class Listeners {
private static JFrame pp;
private static JButton bb;
private static JLabel ll;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ll= new JLabel();
ll.setSize(20, 10);
pp =new JFrame ();
bb = new JButton();
bb.setText("clicam");
bb.setSize(100 , 100 );
pp.add(bb);
pp.add(ll);
bb.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
ll.setText(" botó clicat" );
}
});
pp.setSize(300, 300);
pp.setVisible(true);
}
}
 
</source>
 
a continuació veurem diferents exemples.