Wait never mind, I fixed it, the program code that'll work is:
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import java.awt.Component; import java.awt.Container; import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.AbstractButton; import java.util.*; import javax.swing.*; class NewClass1 extends JFrame implements ActionListener{ private JTextField t; JLabel l; private JButton j, j1, j2; // JFrame f; public NewClass1() { // JFrame f =new JFrame("faria"); t= new JTextField(15); l = new JLabel("Label: ", SwingConstants.RIGHT); JButton j= new JButton("a"); j.addActionListener(this); JButton j1= new JButton("b"); j1.addActionListener(this); JButton j2= new JButton("c"); j2.addActionListener(this); // l.setLayout(new FlowLayout()); // f.add(l); // l.add(t); // l.add(j); // l.add(j1); // l.add(j2); setTitle("farria"); Container pane = getContentPane(); pane.add(l); pane.add(t); pane.add(j); pane.add(j1); pane.add(j2); // j.addActionListener(new A()); // j1.addActionListener(new B()); // j2.addActionListener(new C()); pane.setLayout(new GridLayout(4,4)); setVisible(true); setSize(400,400); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String args[]){ NewClass1 refVar = new NewClass1(); } public void actionPerformed(ActionEvent e) { // JTextField t = new JTextField(); if (e.getActionCommand().equals("a")) { System.out.println("hiii" ); t.setText("hi"); } else if (e.getActionCommand().equals("b")) { System.out.println("hello" ); t.setText("hello"); } else if (e.getActionCommand().equals("c")) { System.out.println("how r u" ); t.setText("how r u"); } } }