New to Java GUI. I'm currently working on Java Editor (don´t ask me why, it was the schools decision). I`ve been learning basic Java from a Youtube video by copy pasting what the author was doing and trying to get a grasp of each commands and etc.
I`ve written the code by using 2 different classes. Here they are:
public class ButtonsTutorial_4 {
public static void main(String[] args) {
//JButton = a button that perform an action when clicked on
new MyFrameButtons();
}
}
And the second one:
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
public class MyFrameButtons_4 extends JFrame implements ActionListener {
JButton button;
MyFrameButtons_4() { //this is a constructor
JButton button = new JButton();
button.setBounds(200, 100, 100, 50);
button.addActionListener(this);
button.setText("I`m a button");
button.setFocusable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setSize(500, 500);
this.setVisible(true);
this.add(button);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
System.out.println("okay");
}
}
}
I am trying to make the button.setText("I´m a button"); work which does let the programm compile and run successfully however the text isn't being shown on the button.
And since I'm already at it, can someone tell me how to be able to see the okay (System.out.println("okay");) text pop up somewhere? In the video I saw the guy using a Console in his Eclipse programm and he could see the Outcome when clicking on the button. Is it also possible for Java Editor?