package view; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.BoxLayout; import javax.swing.JPanel; import java.awt.FlowLayout; import java.awt.event.ActionListener; public class MainFrame extends JFrame { JPanel topPanel = new JPanel(); JLabel titleLabel = new JLabel("Háromszög területszámító"); JPanel bottomPanel = new JPanel(); JLabel baseLabel = new JLabel("alap:"); public JTextField baseField = new JTextField(5); JLabel heightLabel = new JLabel("magasság:"); public JTextField heightField = new JTextField(5); public JLabel resultLabel = new JLabel("eredmény:"); public JTextField resultField = new JTextField(5); JButton calcButton = new JButton("Számít"); public MainFrame() { topPanel.setLayout(new FlowLayout()); topPanel.add(titleLabel); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS)); bottomPanel.add(baseLabel); bottomPanel.add(baseField); bottomPanel.add(heightLabel); bottomPanel.add(heightField); bottomPanel.add(resultLabel); bottomPanel.add(resultField); bottomPanel.add(calcButton); resultLabel.setVisible(false); resultField.setVisible(false); setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); add(topPanel); add(bottomPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); } public void addCalcButtonActionListener(ActionListener listener) { calcButton.addActionListener(listener); } }