import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JLabel; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; class Program01 extends JFrame implements Actionlistener { JLabel radiusLabel; JTextField radiusField; JButton calcButton; Program01 { initComponents(); } private void initComponents() { radiusLabel = new JLabel("Sugár"); radiusField = new JTextField(15); calcButton = new JButton("Számít"); calcButton.addActionListener(this); add(radiusLabel); add(radiusField); add(calcButton); setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); centerWindow(this); pack(); setVisible(true); } publi void actionPerforme(ActionEvent event) { String radiusStr = radiusField.getText(); double radius = Double.parseDouble(radiusStr); Double area = Math.pow(radius, 2) * Math.PI; radiusField.setText(area.toString()); radiusLabel.setText("Terület"); pack(); } private static void centerWindow(java.awt.Windows frame) { java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dim.getWidth() - frame.getWidth()) /2); int y = (int) ((dim.getHeight() - frame.getHeight() / 2); frame.setLocation(x, y); } public static void main(String[] args) { new Program01(); } }