galera to implementando uma calculadora, para mim testar meus conhecimentos com interface gráfica.
mas os meus botões estão espalhados pela janela e naum tenho a menor ideia de como organiza-los.
alguem poderia me ajudar o cod vai abaixo.
Classe Janela
import javax.swing.*;
import java.awt.*;
public class Janela extends JFrame{
private JLabel total, n1 ,n2;
private JButton zero, um, dois, tres, quatro, cinco, seis, sete, oito, nove;
private JButton somar, dividir, subtrair, multiplicar;
private JTextField x, y;
public Janela(){
super("Calculadora");
JPanel painel = new JPanel();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setBounds(100,150,420,500);
painel.setLayout(new GridLayout(10,5));
this.getContentPane().add(painel);
JPanel painelN1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painelN1);
n1 = new JLabel("Insira o 1° Numero");
painelN1.add(n1);
JPanel painelX = new JPanel();
painel.add(painelX);
x = new JTextField(5);
painelX.add(x);
JPanel painelN2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painelN2);
n2 = new JLabel("Insira o 2° Numero");
painelN2.add(n2);
JPanel painelY = new JPanel();
painel.add(painelY);
y = new JTextField(5);
painelY.add(y);
JPanel painelSoma = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painelSoma);
somar = new JButton("+");
painelSoma.add(somar);
JPanel painelSubtrai = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painelSoma);
subtrair = new JButton("-");
painelSoma.add(subtrair);
JPanel painelMultiplica = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painelMultiplica);
multiplicar = new JButton("*");
painelMultiplica.add(multiplicar);
JPanel painelDivide = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painelDivide);
dividir = new JButton("/");
painelDivide.add(dividir);
JPanel painel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel1);
um = new JButton("1");
painelSoma.add(um);
JPanel painel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel2);
dois = new JButton("2");
painelSoma.add(dois);
JPanel painel3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel3);
tres = new JButton("3");
painelMultiplica.add(tres);
JPanel painel4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel4);
quatro = new JButton("4");
painelDivide.add(quatro);
JPanel painel5 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel5);
cinco = new JButton("5");
painelSoma.add(cinco);
JPanel painel6 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel6);
seis = new JButton("6");
painelSoma.add(seis);
JPanel painel7 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel7);
sete = new JButton("7");
painelMultiplica.add(sete);
JPanel painel8 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel8);
oito = new JButton("8");
painelDivide.add(oito);
JPanel painel9 = new JPanel(new FlowLayout(FlowLayout.LEFT));
painel.add(painel9);
nove = new JButton("9");
painelDivide.add(nove);
}
}
PS.: jah tentei todas as combinações possiveis no gridLayout :?
