0% found this document useful (0 votes)
2 views

Figuras Java

Java

Uploaded by

anxge.lpz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Figuras Java

Java

Uploaded by

anxge.lpz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Triángulo:

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Triángulo extends JFrame {

private JPanel contentPane;


private JTextField a;
private JTextField b;
private JTextField c;
private JTextField h;
private JTextField area;
private JTextField perimetro;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Triángulo frame = new Triángulo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public Triángulo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblCalcularreaY = new JLabel("Calcular \u00E1rea y per\u00EDmetro de un Tri\u00E1ngulo");


lblCalcularreaY.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 16));
lblCalcularreaY.setBounds(50, 11, 333, 23);
contentPane.add(lblCalcularreaY);

JLabel lblNewLabel = new JLabel("Lado A:");


lblNewLabel.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel.setBounds(9, 55, 53, 21);
contentPane.add(lblNewLabel);

JLabel lblBase = new JLabel("Base:");


lblBase.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblBase.setBounds(9, 87, 52, 21);
contentPane.add(lblBase);

JLabel lblLadoC = new JLabel("Lado C:");


lblLadoC.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblLadoC.setBounds(9, 119, 52, 21);
contentPane.add(lblLadoC);

JLabel lblAltura = new JLabel("Altura:");


lblAltura.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblAltura.setBounds(9, 151, 49, 21);
contentPane.add(lblAltura);

a = new JTextField();
a.setBounds(72, 57, 86, 20);
contentPane.add(a);
a.setColumns(10);

b = new JTextField();
b.setBounds(71, 89, 86, 20);
contentPane.add(b);
b.setColumns(10);

c = new JTextField();
c.setBounds(71, 121, 86, 20);
contentPane.add(c);
c.setColumns(10);

h = new JTextField();
h.setBounds(71, 153, 86, 20);
contentPane.add(h);
h.setColumns(10);

JButton btnSalir = new JButton("Salir");


btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnSalir.setBounds(335, 228, 89, 23);
contentPane.add(btnSalir);

JButton btnLimpiar = new JButton("Limpiar");


btnLimpiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
a.setText("");
b.setText("");
c.setText("");
h.setText("");
area.setText("");
perimetro.setText("");
}
});
btnLimpiar.setBounds(168, 184, 89, 23);
contentPane.add(btnLimpiar);

JButton btnCalcular = new JButton("Calcular");


btnCalcular.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double la, lb, lc, altura, Area, Perimetro;
la=Integer.parseInt(a.getText());
lb=Integer.parseInt(b.getText());
lc=Integer.parseInt(c.getText());
altura=Integer.parseInt(h.getText());
Area=lb*altura/2;
Perimetro=la+lb+lc;
area.setText(String.valueOf(Area));
perimetro.setText(String.valueOf(Perimetro));
}
});
btnCalcular.setBounds(69, 184, 89, 23);
contentPane.add(btnCalcular);

JLabel lblAngelFidelLpez = new JLabel("Angel Fidel L\u00F3pez Alejandre 304");


lblAngelFidelLpez.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 12));
lblAngelFidelLpez.setBounds(226, 45, 198, 18);
contentPane.add(lblAngelFidelLpez);

JLabel lblÁrea = new JLabel("\u00C1rea:");


lblÁrea.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblÁrea.setBounds(167, 87, 53, 21);
contentPane.add(lblÁrea);

area = new JTextField();


area.setBounds(213, 89, 86, 20);
contentPane.add(area);
area.setColumns(10);

JLabel lblPermetro = new JLabel("Per\u00EDmetro:");


lblPermetro.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblPermetro.setBounds(167, 119, 72, 21);
contentPane.add(lblPermetro);

perimetro = new JTextField();


perimetro.setBounds(249, 121, 86, 20);
contentPane.add(perimetro);
perimetro.setColumns(10);
}
}
Círculo:
package Figuras;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Círculo extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField Radio;
private JTextField Área;
private JTextField Perímetro;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Círculo frame = new Círculo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Círculo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("Calcular área y perímetro de un Círculo");


lblNewLabel.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 16));
lblNewLabel.setBounds(61, 11, 312, 23);
contentPane.add(lblNewLabel);

JLabel lblNewLabel_1 = new JLabel("Radio: ");


lblNewLabel_1.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_1.setBounds(10, 84, 48, 21);
contentPane.add(lblNewLabel_1);

Radio = new JTextField();


Radio.setBounds(61, 86, 86, 20);
contentPane.add(Radio);
Radio.setColumns(10);

JLabel lblNewLabel_2 = new JLabel("Área:");


lblNewLabel_2.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_2.setBounds(10, 151, 39, 21);
contentPane.add(lblNewLabel_2);

JLabel lblNewLabel_3 = new JLabel("Perímetro:");


lblNewLabel_3.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_3.setBounds(10, 183, 72, 21);
contentPane.add(lblNewLabel_3);

Área = new JTextField();


Área.setBounds(61, 153, 86, 20);
contentPane.add(Área);
Área.setColumns(10);

Perímetro = new JTextField();


Perímetro.setBounds(92, 185, 86, 20);
contentPane.add(Perímetro);
Perímetro.setColumns(10);

JButton btnSalir = new JButton("Salir");


btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnSalir.setBounds(335, 227, 89, 23);
contentPane.add(btnSalir);

JButton btnLimpiar = new JButton("Limpiar");


btnLimpiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Área.setText("");
Perímetro.setText("");
Radio.setText("");
}
});
btnLimpiar.setBounds(187, 152, 89, 52);
contentPane.add(btnLimpiar);

JLabel lblNewLabel_4 = new JLabel("Angel Fidel López Alejandre 304 ");


lblNewLabel_4.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 12));
lblNewLabel_4.setBounds(231, 45, 193, 18);
contentPane.add(lblNewLabel_4);

JButton btnCalcular = new JButton("Calcular");


btnCalcular.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double r, area, perimetro;
r=Integer.parseInt(Radio.getText());
area=3.14*r;
perimetro=2*3.14*r;
Área.setText(String.valueOf(area));
Perímetro.setText(String.valueOf(perimetro));
}
});
btnCalcular.setBounds(61, 117, 89, 23);
contentPane.add(btnCalcular);
}
}
Cuadrado:
package Figuras;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Cuadrado extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField Lado;
private JTextField Área;
private JTextField Perímetro;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Cuadrado frame = new Cuadrado();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Cuadrado() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("Calcular área y perímetro de un cuadrado");


lblNewLabel.setBounds(50, 11, 333, 23);
lblNewLabel.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 16));
contentPane.add(lblNewLabel);

JLabel lblNewLabel_1 = new JLabel("Angel Fidel López Alejandre 304");


lblNewLabel_1.setBounds(230, 45, 194, 18);
lblNewLabel_1.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 12));
contentPane.add(lblNewLabel_1);

JLabel lblNewLabel_2 = new JLabel("Lado:");


lblNewLabel_2.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_2.setBounds(10, 73, 37, 21);
contentPane.add(lblNewLabel_2);

Lado = new JTextField();


Lado.setBounds(57, 75, 86, 20);
contentPane.add(Lado);
Lado.setColumns(10);

JLabel lblNewLabel_3 = new JLabel("Área:");


lblNewLabel_3.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_3.setBounds(10, 162, 39, 21);
contentPane.add(lblNewLabel_3);

JLabel lblNewLabel_4 = new JLabel("Perímetro:");


lblNewLabel_4.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_4.setBounds(10, 194, 72, 21);
contentPane.add(lblNewLabel_4);

Área = new JTextField();


Área.setBounds(57, 164, 86, 20);
contentPane.add(Área);
Área.setColumns(10);

Perímetro = new JTextField();


Perímetro.setBounds(92, 196, 86, 20);
contentPane.add(Perímetro);
Perímetro.setColumns(10);

JButton btnCalcular = new JButton("Calcular");


btnCalcular.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double l, area, perimetro;
l=Integer.parseInt(Lado.getText());
area=l*l;
perimetro=4*l;
Área.setText(String.valueOf(area));
Perímetro.setText(String.valueOf(perimetro));
}
});
btnCalcular.setBounds(57, 106, 86, 23);
contentPane.add(btnCalcular);

JButton btnSalir = new JButton("Salir");


btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnSalir.setBounds(335, 227, 89, 23);
contentPane.add(btnSalir);

JButton btnLimpiar = new JButton("Limpiar");


btnLimpiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Lado.setText("");
Área.setText("");
Perímetro.setText("");
}
});
btnLimpiar.setBounds(188, 163, 89, 52);
contentPane.add(btnLimpiar);
}
}
Rectángulo:
package Figuras;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Rectángulo extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField Base;
private JTextField Altura;
private JTextField Área;
private JTextField Perímetro;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Rectángulo frame = new Rectángulo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Rectángulo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("Calcular área y perímetro de un Rectángulo");


lblNewLabel.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 16));
lblNewLabel.setBounds(46, 11, 342, 23);
contentPane.add(lblNewLabel);

JLabel lblNewLabel_1 = new JLabel("Angel Fidel López Alejandre 304 ");


lblNewLabel_1.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 12));
lblNewLabel_1.setBounds(231, 45, 193, 18);
contentPane.add(lblNewLabel_1);

JLabel lblNewLabel_2 = new JLabel("Base:");


lblNewLabel_2.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_2.setBounds(10, 67, 38, 21);
contentPane.add(lblNewLabel_2);

JLabel lblNewLabel_3 = new JLabel("Altura:");


lblNewLabel_3.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_3.setBounds(10, 99, 49, 21);
contentPane.add(lblNewLabel_3);

JLabel lblNewLabel_4 = new JLabel("Área:");


lblNewLabel_4.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_4.setBounds(20, 185, 39, 21);
contentPane.add(lblNewLabel_4);

JLabel lblNewLabel_5 = new JLabel("Perímetro:");


lblNewLabel_5.setFont(new Font("Comic Sans MS", Font.BOLD | Font.ITALIC, 14));
lblNewLabel_5.setBounds(10, 217, 72, 21);
contentPane.add(lblNewLabel_5);

Base = new JTextField();


Base.setBounds(69, 69, 86, 20);
contentPane.add(Base);
Base.setColumns(10);

Altura = new JTextField();


Altura.setBounds(69, 101, 86, 20);
contentPane.add(Altura);
Altura.setColumns(10);

Área = new JTextField();


Área.setBounds(92, 187, 86, 20);
contentPane.add(Área);
Área.setColumns(10);

Perímetro = new JTextField();


Perímetro.setBounds(92, 219, 86, 20);
contentPane.add(Perímetro);
Perímetro.setColumns(10);

JButton btnCalcular = new JButton("Calcular");


btnCalcular.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double b, h, area, perimetro;
b=Integer.parseInt(Base.getText());
h=Integer.parseInt(Altura.getText());
area=b*h;
perimetro=2*(b+h);
Área.setText(String.valueOf(area));
Perímetro.setText(String.valueOf(perimetro));
}
});
btnCalcular.setBounds(66, 132, 89, 23);
contentPane.add(btnCalcular);

JButton btnSalir = new JButton("Salir");


btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnSalir.setBounds(335, 227, 89, 23);
contentPane.add(btnSalir);

JButton btnLimpiar = new JButton("Limpiar");


btnLimpiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.setText("");
Altura.setText("");
Área.setText("");
Perímetro.setText("");
}
});
btnLimpiar.setBounds(188, 185, 89, 56);
contentPane.add(btnLimpiar);
}
}

You might also like