# JFrame\_example\_

**URL:** https://discourse.processing.org/t/jframe-example/35370
**Category:** Coding Questions
**Created:** [February 22, 2022, 4:40am UTC](https://discourse.processing.org/t/jframe-example/35370 "2022-02-22T04:40:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [February 22, 2022, 4:40am UTC](https://discourse.processing.org/t/jframe-example/35370/1 "2022-02-22T04:40:13Z")

</div>

Before I waste too much time on this, would someone please remind me why this is a bad idea and shouldn’t be pursued. Other than the fact that I have two windows (one of which I didn’t ask for) it seems to work ok. ActionListener is used to trap button clicks.

```auto
import java.awt.event.*;
import javax.swing.*;

void setup() {
  JFrame frame = new JFrame("JFrame Demo");
  frame.setBounds(500, 300, 300, 100);
  JButton btn = new JButton("Press me.");
  btn.setBounds(30,30,100,30);
  frame.add(btn);
  frame.setLayout(null); // Need this or btn takes up entire window
  frame.setVisible(true);
  ActionListener actionListener = new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
      println("JFrame btn hit.");
    }
  };
  btn.addActionListener(actionListener);
}

```

![wnd](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/326ae88da9e87ea4c3e6eebcabe78c5dde4a8ff7.png)
