-
-
Save uncoded-ro/2d774fe0094dc7f70b2b649262f8fa62 to your computer and use it in GitHub Desktop.
Tratarea evenimentelor in aplicatiile Java cu interfata grafica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ro.virtualcampus.ev; | |
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class Contor1 extends JFrame implements ActionListener { | |
private static final long serialVersionUID = 1L; | |
JButton buton; | |
JLabel eticheta; | |
static int contor = 0; | |
public Contor1() { | |
super("Contor"); | |
setLayout(new GridLayout(2, 1)); | |
setLocation(100, 100); | |
buton = new JButton("Apasa!"); | |
eticheta = new JLabel("", JLabel.CENTER); | |
getContentPane().add(buton); | |
getContentPane().add(eticheta); | |
buton.addActionListener(this); | |
} | |
public void actionPerformed(ActionEvent e) { | |
if (e.getActionCommand().equals("Apasa!")) { | |
contor++; | |
eticheta.setText(contor + ""); | |
} | |
} | |
public static void main(String args[]) { | |
Contor1 app = new Contor1(); | |
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
app.pack(); | |
app.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment