I'm trying to make a code in Eclipse that change the color and text on MyButton when clicked.
Edit: Got some help and the problem Error got solved. I now know that the code need "public static void main(String[] args)" where should that be put?
After I try to run this code I get the Error "The selection can't be launched, and there are no recent launches". However, I've googled it and saw that the error may be a common problem in eclipse. I am, although new to java and presume it would be more logical if there's wrong with my code rather than eclipse hate me.
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Makke extends JFrame implements ActionListener{
private JButton MyButton;
public Makke(){
setLayout(null);
setSize(300, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyButton = new JButton("Tryck För Blå!");
MyButton.setBackground(Color.YELLOW);
MyButton.setBounds(100, 190, 60, 30);
MyButton.addActionListener(this);
add (MyButton);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == MyButton) {
MyButton = new JButton("Tryck För Gul!");
MyButton.setBackground(Color.BLUE);
}
}
}
Translation: There is some Swedish in the code "Tryck för blå" = "Click to get blue", "Tryck för gul" = "Click to get yellow" ^^