Hi guys i'm trying to create my own calculator and i have a problem with graphic part... i create a label and a button, and i set it in a label. they appear but i can't set their location what is the problem?? thanks for help
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class calc extends JFrame {
public calc(String string) {
this.setResizable(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("calculator");
this.setPreferredSize(new Dimension(300, 400));
JButton button1 = new JButton("calculate");
button1.setBackground(Color.cyan);
button1.setLocation(200, 100);
button1.setPreferredSize(new Dimension(100, 20));
JLabel label1 = new JLabel();
label1.setText(main.main.text); // main.main.text is a text in main class it works XD
JPanel panel1 = new JPanel();
panel1.add(label1);
panel1.add(button1);
panel1.setPreferredSize(new Dimension(300, 400));
this.getContentPane().add(panel1);
this.pack();
panel1.setVisible(true);
button1.setVisible(true);
label1.setVisible(true);
}
}