import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MySecondApp extends JFrame { JPanel panel; JLabel label, label1; JButton button, button1; public MySecondApp() throws HeadlessException { panel = new JPanel(); panel.setLayout(new GridBagLayout()); button = new JButton(); button.setText("Ahoj"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(MySecondApp.this, "AHOJ!"); } }); button1 = new JButton(); button1.setText("Čau"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(MySecondApp.this, "ČAU!"); } }); label = new JLabel("Ahoj:"); label1 = new JLabel("Čau:"); setTitle("My APP"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(1920,1080); setVisible(true); GridBagConstraints g = new GridBagConstraints(); g.gridx = 0; g.gridy = 1; g.gridwidth = 2; g.weightx = 5; g.weighty = 5; panel.add(button, g); g.gridx = 2; g.gridwidth = 1; panel.add(button1, g); g.gridy = 0; g.gridx = 0; panel.add(label,g); g.gridx = 1; panel.add(label1,g); add(panel); } public static void main(String[] args) { new MySecondApp(); } }