Calculadora
import java.awt.event.*;
import javax.swing.*;
public class CalculadoraPrueba1 extends JFrame
{
private Container cont;
private GridBagLayout esquema;
privateGridBagConstraints restriccion;
public CalculadoraPrueba1()
{
super("Mauricio");
cont=getContentPane();
esquema=new GridBagLayout();
cont.setLayout(esquema);
restriccion=new GridBagConstraints();restriccion=new GridBagConstraints();
restriccion.weightx=5;
restriccion.weighty=5;
restriccion.fill=GridBagConstraints.BOTH;
JTextField cTexto=new JTextField("",78);restriccion.gridwidth=GridBagConstraints.REMAINDER;
agregarComponente(cTexto);
String nombre[]={"N1","N2","N3","N4","N5","N6","N7","N8","N9","N0","N+","N-","N*","N/","N.","N="};
JButton botones[]=newJButton[nombre.length];
for (int C=0; C<botones.length;C++)
botones[C]=new JButton(nombre[C]);
//A partir de aca tiene que comenzar a agregar los componentes
restriccion.gridwidth=1;agregarComponente(botones[6]);
restriccion.gridwidth=1;
agregarComponente(botones[7]);
restriccion.gridwidth=GridBagConstraints.RELATIVE;
agregarComponente(botones[8]);restriccion.gridwidth=GridBagConstraints.REMAINDER;
agregarComponente(botones[13]);
restriccion.gridwidth=1;
agregarComponente(botones[3]);
restriccion.gridwidth=1;
agregarComponente(botones[4]);restriccion.gridwidth=GridBagConstraints.RELATIVE;
agregarComponente(botones[5]);
restriccion.gridwidth=GridBagConstraints.REMAINDER;
agregarComponente(botones[12]);
restriccion.gridwidth=1;agregarComponente(botones[0]);
restriccion.gridwidth=1;
agregarComponente(botones[1]);
restriccion.gridwidth=GridBagConstraints.RELATIVE;
agregarComponente(botones[2]);restriccion.gridwidth=GridBagConstraints.REMAINDER;
agregarComponente(botones[11]);
restriccion.gridwidth=1;
agregarComponente(botones[9]);
restriccion.gridwidth=1;
agregarComponente(botones[14]);...
Regístrate para leer el documento completo.