You are on page 1of 6

1.

ActionEvent:

- Ejemplo:

java

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

// Código para manejar el evento del botón aquí

});

2. KeyEvent:

- Ejemplo:

java

textField.addKeyListener(new KeyAdapter() {

public void keyTyped(KeyEvent e) {

// Código para manejar el evento de teclado aquí

});

3. MouseEvent:

- Ejemplo:

java

component.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

// Código para manejar el evento de ratón aquí


}

});

4. WindowEvent:

- Ejemplo:

java

frame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

// Código para manejar el evento de cierre de ventana aquí

});

5.item events

Ejemplo:

public void itemStateChanged(ItemEvent ev) {

if (ev.getStateChange() == ItemEvent.SELECTED && ev.getSource() == cbSuspend) {

int idx = cbSuspend.getSelectedIndex();

tfThreadID.setEnabled(idx == CndBreakpoint.SUSPEND_THREAD);

lThreadID.setEnabled(idx == CndBreakpoint.SUSPEND_THREAD);

6.ComponentEvent

Ejemplo:

public ComponentEvent(Component source, int id)

7.Focusevent

ejemplo
<style>

.invalid { border-color: red; }

#error { color: red }

</style>

Su correo por favor: <input type="email" id="input">

<div id="error"></div>

<script>

input.onblur = function() {

if (!input.value.includes('@')) { // not email

input.classList.add('invalid');

error.innerHTML = 'Por favor introduzca un correo válido.'

};

input.onfocus = function() {

if (this.classList.contains('invalid')) {

// quitar la indicación "error", porque el usuario quiere reintroducir algo

this.classList.remove('invalid');

error.innerHTML = "";

};

8.KeyEvent

public void keyPressed(KeyEvent e) {


if (e.isActionKey() && e.getKeyCode() == KeyEvent.VK_ENTER) {

// Do something when the ENTER key is pressed

9.ContainerEvent

public void layoutContainer(Container parent)

int x = 0;

for (Component c : parent.getComponents())

x += ITEM_PADDING;

int height = c.getPreferredSize().height;

if (height > TITLEBAR_SIZE)

height = TITLEBAR_SIZE;

c.setBounds(x, (TITLEBAR_SIZE - height) / 2, TITLEBAR_SIZE, height);

x += TITLEBAR_SIZE;

});

10.AdjustmentEvent

scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

public void adjustmentValueChanged(AdjustmentEvent e) {

e.getAdjustable().setValue(e.getAdjustable().getMaximum());
}

});

11.TextEvent

private static void fireTextEvent() {

EventListener[] lstrs =

EVENT_LISTENER_LIST.getListeners(TextListener.class);

if (lstrs != null && lstrs.length > 0) {

TextEvent te =

new TextEvent(FIND_REPLACE_DIALOG, TextEvent.TEXT_VALUE_CHANGED);

for (int i = 0; i < lstrs.length; i++) {

((TextListener) lstrs[i]).textValueChanged(te);

12. WindonwEvent

private JFrame f = new JFrame("FullScreenTest");

private Action exit = new AbstractAction(EXIT) {

f.dispatchEvent(new WindowEvent(

f, WindowEvent.WINDOW_CLOSING));

private JButton b = new JButton(exit);

this.add(b);

f.getRootPane().setDefaultButton(b);

this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), EXIT);

this.getActionMap().put(EXIT, exit);
this.addMouseMotionListener(new MouseAdapter() {

GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice dev = env.getDefaultScreenDevice();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setBackground(Color.darkGray);

f.setResizable(false);

f.setUndecorated(true);

f.add(this);

f.pack();

dev.setFullScreenWindow(

You might also like