import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyFirstBigApp extends JFrame { private JPanel panel; private JButton button1, button2, button3; public MyFirstBigApp(String title) throws HeadlessException { super(title); setVisible(true); Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); setSize(size.width,size.height); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); panel = new JPanel(); panel.setLayout(new GridBagLayout()); button1 = new JButton("Ahoj"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(MyFirstBigApp.this, "Ahoj"); } }); button2 = new JButton("Čau"); button3 = new JButton ("Nazdar"); GridBagConstraints g = new GridBagConstraints(); g.gridy = 0; g.gridx = 0; g.ipadx = 20; g.ipady = 20; g.gridwidth = 2; g.fill = MAXIMIZED_HORIZ; panel.add(button1, g); g.gridy = 1; g.gridwidth = 1; panel.add(button2, g); g.gridx = 1; panel.add(button3, g); add(panel); } public static void main(String[] args) { new MyFirstBigApp("My app"); } }