You calling new menuFrame() class, but just bellow it you have only method with similar signature. You need to make up your mind if you want to call class or just method. In case of class call your code may look like this
import javax.swing.*;
import java.awt.event.*;
class MyFrame {
public static void main(String[] args) {
new MenuFrame();
}
public static class MenuFrame extends JFrame implements ActionListener {
private JPanel menuPanel;
private JButton btnStart;
public MenuFrame() {
menuPanel = new JPanel();
menuPanel.setLayout(null);
JLabel lblName = new JLabel("Name: ");
lblName.setBounds(30, 20, 100, 20);
JTextField txtName = new JTextField(15);
txtName.setBounds(80, 20, 150, 20);
JButton btnStart = new JButton("Start");
btnStart.setBounds(90, 60, 100, 20);
menuPanel.add(lblName);
menuPanel.add(txtName);
menuPanel.add(btnStart);
setDefaultProperties();
}
public void setDefaultProperties() {
this.setTitle("Hello World!");
this.setSize(300, 200);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.add(menuPanel);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnStart)
btnStart.setText("lol");
}
}
} peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902