Dear programmers, help! Faced such a problem - the button was created for the whole frame, and when it is expanded (resized), the button changes too! Tell me how to fix it?
package ru.cherkasovs; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Main extends JFrame{ /** * */ private static final long serialVersionUID = 1L; @SuppressWarnings("unused") private int rayon = 1; private static JButton Button1; public static void main(String[] args) { JFrame f = new JFrame(""); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(479,597); f.add(new Map()); f.setVisible(true); JPanel p = new JPanel(); f.add(p); p.add(new JButton("Okay"), BorderLayout.NORTH); Button1 = new JButton(""); f.add(Button1); JButton button = new JButton("Click me!"); button.setVisible(true); button.setLocation(50, 50); button.setSize(50,50); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(Button1, "Don't touch me!", "Warning", JOptionPane.WARNING_MESSAGE); } }); f.add(new Map()); f.add(Button1); f.add(Button1); } }