ActionListener_2022
import javax.swing.*; import java.awt.*; import java.awt.event.*; class A extends JFrame implements ActionListener{ JLabel lbl,lbl1; JTextField txt,txt1; JButton btn; public A(){ lbl = new JLabel("Number1"); txt = new JTextField(20); lbl1 = new JLabel("Number2"); txt1 = new JTextField(20); btn = new JButton("Click Here"); setBackground(Color.RED); setLayout(new FlowLayout()); setSize(500,350); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(lbl); add(txt); add(lbl1);add(txt1); add(btn); btn.addActionListener(this); } public void actionPerformed(ActionEvent owl){ int a = Integer.parseInt(txt.getText()); int b = Integer.parseInt(txt1.getText()); btn.setText(""+(a+b)); for(int i = a;i<=b;i++){ System.out.println(" "+i); } } } class A_demo{ public static void main(String[] owl){ A a = new A(); } }