import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyPanel extends JPanel implements ActionListener { private JTextField readTf, writeTf; public MyPanel(){ setSize(300, 300); setLayout(null); readTf = new JTextField("Type an integer here"); readTf.setSize(200,40); readTf.setLocation(40,40); readTf.setEditable(true); readTf.addActionListener(this); add(readTf); writeTf = new JTextField(); writeTf.setSize(200,40); writeTf.setLocation(40,120); writeTf.setEditable(false); add(writeTf); JButton jb = new JButton("Click here"); jb.setSize(200,40); jb.setLocation(40,200); jb.addActionListener(this); add(jb); setVisible(true); } private int f (int x){ return 2*x*x + 3*x +1; } public void actionPerformed(ActionEvent e){ if(e.getSource() == readTf){ String text = readTf.getText(); int n = Integer.parseInt(text); writeTf.setText("" + f(n)); readTf.setText("Type something here"); } else writeTf.setText("No, hit return"); } }