actionlistener....Cannot use this in a static context

6

6e

Hi! Im creating a java application that works in a JFrame.

Ive put a button onto my frame called butNewType, however when I try to
add an actionlistener, I get the error "Cannot use this in a static
context"

butNewType.addActionListener(this);

does anybody know a way to work around this, Im sure that there is a
simple solution... Thanks!

butNewType.setMnemonic(KeyEvent.VK_T);
butNewType.setActionCommand("butNewType");
butNewType.setToolTipText("create a new \"type\".");
butNewType.addActionListener(this);

does anybody know a way to work around this, Im sure that there is a
simple solution... Thanks!
 
6

6e

figured it out!

could not call butNewType.addActionListener(t­his); from main, nor
could I put it into a funciton and call it from there.

but i was able to create a Class named constructor, calling that
function, and initiate the entire process from main.

so

static void main (string args[]){
myClassName x = new myClassName();
}

public myClassName() {
.........
butNewType.addActionListener(t­his);
................
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top