addActionListener in type AbstractButton not applicable for arguments (DigiUhr)
I have searched for this Problem and I found some threads, regardless they did not solve my issue since they all used different implementations of the ActionListener Interface. My Program is supposed to display a simple digital watch with a button to choose each position (hour min sec) and when chosen increase by pressing the other button. In order to achieve that I have used the ActionListener Interface. Zustand -> State, basically 'z' registers what state we are in and then changes the action performed when pressed each button. Did I forget importing something, am I just overseeing something?
package semester2;
import javax.swing.*;
import java.awt.event.*;
import java.util.Calendar;
import java.awt.*;
@SuppressWarnings("serial")
public class DigiUhr extends JFrame implements ActionListener {
Container c;
int h, m, s;
JButton choose, inc;
JPanel Display;
Zustand z = new Ausgang();
JLabel hour, min, sec, brand;
public DigiUhr(){
c = getContentPane();
//Buttons
choose = new JButton(">");
choose.setBackground (Color.black);
choose.setForeground(Color.yellow);
inc = new JButton ("+");
inc.setBackground(Color.black);
inc.setForeground(Color.yellow);
choose.addActionListener(this);
inc.addActionListener(this);
choose.setPreferredSize(new Dimension(80,80));
inc.setPreferredSize(new Dimension(80,80));
//Uhrzeit
Calendar jz = Calendar.getInstance();
h = jz.get(Calendar.HOUR_OF_DAY);
m = jz.getMaximum(Calendar.MINUTE);
s = jz.get (Calendar.SECOND);
//Display
Display = new JPanel (new BorderLayout());
Display.setBackground(Color.yellow);
Display.setPreferredSize(new Dimension (300,300));
//Labels
brand = new JLabel ("ROLEX");
hour = new JLabel();
min = new JLabel();
sec = new JLabel();
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
//add Labels to Display
Display.add(brand, BorderLayout.NORTH);
Display.add(hour, BorderLayout.WEST);
Display.add(min, BorderLayout.CENTER);
Display.add(sec, BorderLayout.EAST);
//Configure Labels
hour.setText(getHour());
hour.setHorizontalTextPosition(JLabel.CENTER);
min.setText(getMin());
min.setHorizontalTextPosition(JLabel.CENTER);
sec.setText(getSec());
sec.setHorizontalTextPosition(JLabel.CENTER);
c.setLayout(new FlowLayout(FlowLayout.CENTER, 30, 0));
c.add(inc);
c.add(Display);
c.add(choose);
}
public void actionPerformed (ActionEvent e){
if (e.getSource() == choose){
z.Button1Pressed();
}
if(e.getSource() == inc){
z.Button2Pressed();
}
}
abstract class Zustand {
abstract void Button1Pressed();
abstract void Button2Pressed();
}
class Ausgang extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.GRAY);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new StundenStellen();
}
void Button2Pressed(){}
}
class StundenStellen extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.gray);
sec.setForeground(Color.black);
z = new MinutenStellen();
}
void Button2Pressed(){
h = h++;
hour.setText(getHour());
}
}
class MinutenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.gray);
z = new SekundenStellen();
}
void Button2Pressed(){
m = m++;
min.setText(getMin());
}
}
class SekundenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new Ausgang();
}
void Button2Pressed(){
s = s++;
sec.setText(getSec());
}
}
String getHour(){
return(String.valueOf(h));
}
String getMin(){
return(String.valueOf(m));
}
String getSec(){
return(String.valueOf(s));
}
public static void main (String args){
DigiUhr Rolex = new DigiUhr();
Rolex.setSize(700,700);
Rolex.setVisible(true);
Rolex.setTitle("Rolex Submariner");
Rolex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
The Error message looks as following:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
at semester2.DigiUhr.<init>(DigiUhr.java:26)
at semester2.DigiUhr.main(DigiUhr.java:139)
java eclipse user-interface jbutton actionlistener
add a comment |
I have searched for this Problem and I found some threads, regardless they did not solve my issue since they all used different implementations of the ActionListener Interface. My Program is supposed to display a simple digital watch with a button to choose each position (hour min sec) and when chosen increase by pressing the other button. In order to achieve that I have used the ActionListener Interface. Zustand -> State, basically 'z' registers what state we are in and then changes the action performed when pressed each button. Did I forget importing something, am I just overseeing something?
package semester2;
import javax.swing.*;
import java.awt.event.*;
import java.util.Calendar;
import java.awt.*;
@SuppressWarnings("serial")
public class DigiUhr extends JFrame implements ActionListener {
Container c;
int h, m, s;
JButton choose, inc;
JPanel Display;
Zustand z = new Ausgang();
JLabel hour, min, sec, brand;
public DigiUhr(){
c = getContentPane();
//Buttons
choose = new JButton(">");
choose.setBackground (Color.black);
choose.setForeground(Color.yellow);
inc = new JButton ("+");
inc.setBackground(Color.black);
inc.setForeground(Color.yellow);
choose.addActionListener(this);
inc.addActionListener(this);
choose.setPreferredSize(new Dimension(80,80));
inc.setPreferredSize(new Dimension(80,80));
//Uhrzeit
Calendar jz = Calendar.getInstance();
h = jz.get(Calendar.HOUR_OF_DAY);
m = jz.getMaximum(Calendar.MINUTE);
s = jz.get (Calendar.SECOND);
//Display
Display = new JPanel (new BorderLayout());
Display.setBackground(Color.yellow);
Display.setPreferredSize(new Dimension (300,300));
//Labels
brand = new JLabel ("ROLEX");
hour = new JLabel();
min = new JLabel();
sec = new JLabel();
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
//add Labels to Display
Display.add(brand, BorderLayout.NORTH);
Display.add(hour, BorderLayout.WEST);
Display.add(min, BorderLayout.CENTER);
Display.add(sec, BorderLayout.EAST);
//Configure Labels
hour.setText(getHour());
hour.setHorizontalTextPosition(JLabel.CENTER);
min.setText(getMin());
min.setHorizontalTextPosition(JLabel.CENTER);
sec.setText(getSec());
sec.setHorizontalTextPosition(JLabel.CENTER);
c.setLayout(new FlowLayout(FlowLayout.CENTER, 30, 0));
c.add(inc);
c.add(Display);
c.add(choose);
}
public void actionPerformed (ActionEvent e){
if (e.getSource() == choose){
z.Button1Pressed();
}
if(e.getSource() == inc){
z.Button2Pressed();
}
}
abstract class Zustand {
abstract void Button1Pressed();
abstract void Button2Pressed();
}
class Ausgang extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.GRAY);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new StundenStellen();
}
void Button2Pressed(){}
}
class StundenStellen extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.gray);
sec.setForeground(Color.black);
z = new MinutenStellen();
}
void Button2Pressed(){
h = h++;
hour.setText(getHour());
}
}
class MinutenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.gray);
z = new SekundenStellen();
}
void Button2Pressed(){
m = m++;
min.setText(getMin());
}
}
class SekundenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new Ausgang();
}
void Button2Pressed(){
s = s++;
sec.setText(getSec());
}
}
String getHour(){
return(String.valueOf(h));
}
String getMin(){
return(String.valueOf(m));
}
String getSec(){
return(String.valueOf(s));
}
public static void main (String args){
DigiUhr Rolex = new DigiUhr();
Rolex.setSize(700,700);
Rolex.setVisible(true);
Rolex.setTitle("Rolex Submariner");
Rolex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
The Error message looks as following:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
at semester2.DigiUhr.<init>(DigiUhr.java:26)
at semester2.DigiUhr.main(DigiUhr.java:139)
java eclipse user-interface jbutton actionlistener
add a comment |
I have searched for this Problem and I found some threads, regardless they did not solve my issue since they all used different implementations of the ActionListener Interface. My Program is supposed to display a simple digital watch with a button to choose each position (hour min sec) and when chosen increase by pressing the other button. In order to achieve that I have used the ActionListener Interface. Zustand -> State, basically 'z' registers what state we are in and then changes the action performed when pressed each button. Did I forget importing something, am I just overseeing something?
package semester2;
import javax.swing.*;
import java.awt.event.*;
import java.util.Calendar;
import java.awt.*;
@SuppressWarnings("serial")
public class DigiUhr extends JFrame implements ActionListener {
Container c;
int h, m, s;
JButton choose, inc;
JPanel Display;
Zustand z = new Ausgang();
JLabel hour, min, sec, brand;
public DigiUhr(){
c = getContentPane();
//Buttons
choose = new JButton(">");
choose.setBackground (Color.black);
choose.setForeground(Color.yellow);
inc = new JButton ("+");
inc.setBackground(Color.black);
inc.setForeground(Color.yellow);
choose.addActionListener(this);
inc.addActionListener(this);
choose.setPreferredSize(new Dimension(80,80));
inc.setPreferredSize(new Dimension(80,80));
//Uhrzeit
Calendar jz = Calendar.getInstance();
h = jz.get(Calendar.HOUR_OF_DAY);
m = jz.getMaximum(Calendar.MINUTE);
s = jz.get (Calendar.SECOND);
//Display
Display = new JPanel (new BorderLayout());
Display.setBackground(Color.yellow);
Display.setPreferredSize(new Dimension (300,300));
//Labels
brand = new JLabel ("ROLEX");
hour = new JLabel();
min = new JLabel();
sec = new JLabel();
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
//add Labels to Display
Display.add(brand, BorderLayout.NORTH);
Display.add(hour, BorderLayout.WEST);
Display.add(min, BorderLayout.CENTER);
Display.add(sec, BorderLayout.EAST);
//Configure Labels
hour.setText(getHour());
hour.setHorizontalTextPosition(JLabel.CENTER);
min.setText(getMin());
min.setHorizontalTextPosition(JLabel.CENTER);
sec.setText(getSec());
sec.setHorizontalTextPosition(JLabel.CENTER);
c.setLayout(new FlowLayout(FlowLayout.CENTER, 30, 0));
c.add(inc);
c.add(Display);
c.add(choose);
}
public void actionPerformed (ActionEvent e){
if (e.getSource() == choose){
z.Button1Pressed();
}
if(e.getSource() == inc){
z.Button2Pressed();
}
}
abstract class Zustand {
abstract void Button1Pressed();
abstract void Button2Pressed();
}
class Ausgang extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.GRAY);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new StundenStellen();
}
void Button2Pressed(){}
}
class StundenStellen extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.gray);
sec.setForeground(Color.black);
z = new MinutenStellen();
}
void Button2Pressed(){
h = h++;
hour.setText(getHour());
}
}
class MinutenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.gray);
z = new SekundenStellen();
}
void Button2Pressed(){
m = m++;
min.setText(getMin());
}
}
class SekundenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new Ausgang();
}
void Button2Pressed(){
s = s++;
sec.setText(getSec());
}
}
String getHour(){
return(String.valueOf(h));
}
String getMin(){
return(String.valueOf(m));
}
String getSec(){
return(String.valueOf(s));
}
public static void main (String args){
DigiUhr Rolex = new DigiUhr();
Rolex.setSize(700,700);
Rolex.setVisible(true);
Rolex.setTitle("Rolex Submariner");
Rolex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
The Error message looks as following:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
at semester2.DigiUhr.<init>(DigiUhr.java:26)
at semester2.DigiUhr.main(DigiUhr.java:139)
java eclipse user-interface jbutton actionlistener
I have searched for this Problem and I found some threads, regardless they did not solve my issue since they all used different implementations of the ActionListener Interface. My Program is supposed to display a simple digital watch with a button to choose each position (hour min sec) and when chosen increase by pressing the other button. In order to achieve that I have used the ActionListener Interface. Zustand -> State, basically 'z' registers what state we are in and then changes the action performed when pressed each button. Did I forget importing something, am I just overseeing something?
package semester2;
import javax.swing.*;
import java.awt.event.*;
import java.util.Calendar;
import java.awt.*;
@SuppressWarnings("serial")
public class DigiUhr extends JFrame implements ActionListener {
Container c;
int h, m, s;
JButton choose, inc;
JPanel Display;
Zustand z = new Ausgang();
JLabel hour, min, sec, brand;
public DigiUhr(){
c = getContentPane();
//Buttons
choose = new JButton(">");
choose.setBackground (Color.black);
choose.setForeground(Color.yellow);
inc = new JButton ("+");
inc.setBackground(Color.black);
inc.setForeground(Color.yellow);
choose.addActionListener(this);
inc.addActionListener(this);
choose.setPreferredSize(new Dimension(80,80));
inc.setPreferredSize(new Dimension(80,80));
//Uhrzeit
Calendar jz = Calendar.getInstance();
h = jz.get(Calendar.HOUR_OF_DAY);
m = jz.getMaximum(Calendar.MINUTE);
s = jz.get (Calendar.SECOND);
//Display
Display = new JPanel (new BorderLayout());
Display.setBackground(Color.yellow);
Display.setPreferredSize(new Dimension (300,300));
//Labels
brand = new JLabel ("ROLEX");
hour = new JLabel();
min = new JLabel();
sec = new JLabel();
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
//add Labels to Display
Display.add(brand, BorderLayout.NORTH);
Display.add(hour, BorderLayout.WEST);
Display.add(min, BorderLayout.CENTER);
Display.add(sec, BorderLayout.EAST);
//Configure Labels
hour.setText(getHour());
hour.setHorizontalTextPosition(JLabel.CENTER);
min.setText(getMin());
min.setHorizontalTextPosition(JLabel.CENTER);
sec.setText(getSec());
sec.setHorizontalTextPosition(JLabel.CENTER);
c.setLayout(new FlowLayout(FlowLayout.CENTER, 30, 0));
c.add(inc);
c.add(Display);
c.add(choose);
}
public void actionPerformed (ActionEvent e){
if (e.getSource() == choose){
z.Button1Pressed();
}
if(e.getSource() == inc){
z.Button2Pressed();
}
}
abstract class Zustand {
abstract void Button1Pressed();
abstract void Button2Pressed();
}
class Ausgang extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.GRAY);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new StundenStellen();
}
void Button2Pressed(){}
}
class StundenStellen extends Zustand {
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.gray);
sec.setForeground(Color.black);
z = new MinutenStellen();
}
void Button2Pressed(){
h = h++;
hour.setText(getHour());
}
}
class MinutenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.gray);
z = new SekundenStellen();
}
void Button2Pressed(){
m = m++;
min.setText(getMin());
}
}
class SekundenStellen extends Zustand{
void Button1Pressed(){
hour.setForeground(Color.black);
min.setForeground(Color.black);
sec.setForeground(Color.black);
z = new Ausgang();
}
void Button2Pressed(){
s = s++;
sec.setText(getSec());
}
}
String getHour(){
return(String.valueOf(h));
}
String getMin(){
return(String.valueOf(m));
}
String getSec(){
return(String.valueOf(s));
}
public static void main (String args){
DigiUhr Rolex = new DigiUhr();
Rolex.setSize(700,700);
Rolex.setVisible(true);
Rolex.setTitle("Rolex Submariner");
Rolex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
The Error message looks as following:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (DigiUhr)
at semester2.DigiUhr.<init>(DigiUhr.java:26)
at semester2.DigiUhr.main(DigiUhr.java:139)
java eclipse user-interface jbutton actionlistener
java eclipse user-interface jbutton actionlistener
edited Jan 19 at 14:07
greg-449
89k166398
89k166398
asked Jan 19 at 14:06
Sahil SinghSahil Singh
61
61
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Did you have implements ActionListener
part in your code when you got the error? This error occurs when you don't have this part.
This code you have posted compiles without any errors.
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267910%2faddactionlistener-in-type-abstractbutton-not-applicable-for-arguments-digiuhr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Did you have implements ActionListener
part in your code when you got the error? This error occurs when you don't have this part.
This code you have posted compiles without any errors.
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
add a comment |
Did you have implements ActionListener
part in your code when you got the error? This error occurs when you don't have this part.
This code you have posted compiles without any errors.
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
add a comment |
Did you have implements ActionListener
part in your code when you got the error? This error occurs when you don't have this part.
This code you have posted compiles without any errors.
Did you have implements ActionListener
part in your code when you got the error? This error occurs when you don't have this part.
This code you have posted compiles without any errors.
answered Jan 19 at 15:21
Prasad KarunagodaPrasad Karunagoda
1,1561711
1,1561711
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
add a comment |
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
Hi, yes I copied the code straight out of eclipse. When I try to run it I get the error message.
– Sahil Singh
Jan 20 at 12:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267910%2faddactionlistener-in-type-abstractbutton-not-applicable-for-arguments-digiuhr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown