import java.awt.event.*; import javax.swing.*; import java.awt.Container; import java.awt.Font; public class Button1 { public static void main(String[] args) { BFrame frame= new BFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } } class BFrame extends JFrame { public BFrame() { setTitle("Ejemplo de Button"); setSize(XSIZE, YSIZE); ButtonPanel panel= new ButtonPanel(); Container contentPane= getContentPane(); contentPane.add(panel); } public static final int XSIZE= 200; public static final int YSIZE= 200; } class ButtonPanel extends JPanel implements ActionListener { public ButtonPanel() { JButton countButton= new JButton("Avanzar cuenta"); countLabel= new JLabel("Cuenta= 0"); Font fontShow= new Font("Monospaced", Font.BOLD, 24); countLabel.setFont(fontShow); countButton.setFont(fontShow); add(countButton); add(countLabel); countButton.addActionListener(this); } public void actionPerformed(ActionEvent e) { i++; countLabel.setText("Cuenta= " + i); repaint(); } private int i= 0; private JLabel countLabel; }