Basic Button

This applet displays a button which generates an action when clicked.1

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class ButtonOuch extends Applet implements ActionListener {

private Button tester;
private boolean clickedYet = false;
public void init() {

tester = new Button("Press Here");

public void paint(Graphics g) {

if (clickedYet)

g.drawString("Ouch", 100, 50);

public void actionPerformed(ActionEvent event) {

clickedYet = true;



This is what it looks like:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License