Universidad Tecnológica de Honduras
Asignatura
Programación avanzada I
Catedrático
PhD. Carlos Hugo Estrada
Alumno
Marco Antonio Vásquez Mendoza
Número de Cuenta:
202220110037
Asignación:
Examen deL segundo parcial
Fecha de límite entrega:
16 de marzo de 2024
import javax.swing.*;
import java.awt.*;
public class CirculosConcentricosApp6 {
public static void main(String[] args) {
JFrame frame = new JFrame("Círculos Concéntricos");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CirculosConcentricosPanel6 panel = new CirculosConcentricosPanel6();
frame.getContentPane().add(panel);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
class CirculosConcentricosPanel6 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int radio = 10;
int separacion = 10;
for (int i = 0; i < 8; i++) {
int diametro = radio * 2;
int x = (getWidth() - diametro) / 2;
int y = (getHeight() - diametro) / 2;
g.drawArc(x, y, diametro, diametro, 0, 360);
radio += separacion;
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
public class CirculosConcentricosApp7 {
public static void main(String[] args) {
JFrame frame = new JFrame("Círculos Concéntricos");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CirculosConcentricosPanel7 panel = new CirculosConcentricosPanel7();
frame.getContentPane().add(panel);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
class CirculosConcentricosPanel7 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int radio = 10;
int separacion = 10;
for (int i = 0; i < 8; i++) {
int diametro = radio * 2;
int x = (getWidth() - diametro) / 2;
int y = (getHeight() - diametro) / 2;
Ellipse2D.Double circulo = new Ellipse2D.Double(x, y, diametro, diametro);
g2d.draw(circulo);
radio += separacion;
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Line2D;
import java.util.Random;
public class LineasAleatoriasApp8 {
public static void main(String[] args) {
JFrame frame = new JFrame("Líneas Aleatorias");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LineasAleatoriasPanel8 panel = new LineasAleatoriasPanel8();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Line2D;
import java.util.Random;
class LineasAleatoriasPanel8 extends JPanel {
private final Random random = new Random();
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int numLineas = 10;
for (int i = 0; i < numLineas; i++) {
int x1 = random.nextInt(getWidth());
int y1 = random.nextInt(getHeight());
int x2 = random.nextInt(getWidth());
int y2 = random.nextInt(getHeight());
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
g2d.setColor(color);
float grosor = random.nextFloat() * 5 + 1; // Grosor entre 1 y 6
g2d.setStroke(new BasicStroke(grosor));
Line2D.Double linea = new Line2D.Double(x1, y1, x2, y2);
g2d.draw(linea);
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.util.Random;
public class TriangulosAleatoriosApp9 {
public static void main(String[] args) {
JFrame frame = new JFrame("Triángulos Aleatorios");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TriangulosAleatoriosPanel9 panel = new TriangulosAleatoriosPanel9();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.util.Random;
class TriangulosAleatoriosPanel9 extends JPanel {
private final Random random = new Random();
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int numTriangulos = 8;
for (int i = 0; i < numTriangulos; i++) {
int[] xPoints = {random.nextInt(getWidth()), random.nextInt(getWidth()),
random.nextInt(getWidth())};
int[] yPoints = {random.nextInt(getHeight()), random.nextInt(getHeight()),
random.nextInt(getHeight())};
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
g2d.setColor(color);
GeneralPath triangulo = new GeneralPath();
triangulo.moveTo(xPoints[0], yPoints[0]);
for (int j = 1; j < xPoints.length; j++) {
triangulo.lineTo(xPoints[j], yPoints[j]);
}
triangulo.closePath();
g2d.fill(triangulo);
}
}
}
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class CaracteresAleatoriosApp10 {
public static void main(String[] args) {
JFrame frame = new JFrame("Caracteres Aleatorios");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CaracteresAleatoriosPanel10 panel = new CaracteresAleatoriosPanel10();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.util.Random;
class CaracteresAleatoriosPanel10 extends JPanel {
private final Random random = new Random();
private final String[] fonts =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int numCaracteres = 10;
for (int i = 0; i < numCaracteres; i++) {
int x = random.nextInt(getWidth());
int y = random.nextInt(getHeight());
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
g2d.setColor(color);
int size = random.nextInt(36) + 12;
String fontName = fonts[random.nextInt(fonts.length)];
Font font = new Font(fontName, Font.PLAIN, size);
g2d.setFont(font);
char caracter = (char) (random.nextInt(26) + 'A');
g2d.drawString(Character.toString(caracter), x, y);
}
}
}
import javax.swing.*;
import java.awt.*;
public class CuadriculaApp11 {
public static void main(String[] args) {
JFrame frame = new JFrame("Cuadrícula");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CuadriculaPanel11 panel = new CuadriculaPanel11();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
class CuadriculaPanel11 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int size = Math.min(getWidth(), getHeight());
int cellSize = size / 8;
for (int i = 0; i < 8; i++) {
int x = i * cellSize;
int y = i * cellSize;
g2d.drawLine(x, 0, x, size);
g2d.drawLine(0, y, size, y);
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Line2D;
public class CuadriculaApp12 {
public static void main(String[] args) {
JFrame frame = new JFrame("Cuadrícula");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CuadriculaPanel12 panel = new CuadriculaPanel12();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Line2D;
class CuadriculaPanel12 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int size = Math.min(getWidth(), getHeight());
int cellSize = size / 8;
for (int i = 0; i < 8; i++) {
int x = i * cellSize;
int y = i * cellSize;
g2d.draw(new Line2D.Double(x, 0, x, size));
g2d.draw(new Line2D.Double(0, y, size, y));
}
}
}
import javax.swing.*;
import java.awt.*;
public class CuadriculaApp13 {
public static void main(String[] args) {
JFrame frame = new JFrame("Cuadrícula");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CuadriculaPanel13 panel = new CuadriculaPanel13();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
class CuadriculaPanel13 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int size = Math.min(getWidth(), getHeight());
int cellSize = size / 10;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
int x = i * cellSize;
int y = j * cellSize;
g2d.drawRect(x, y, cellSize, cellSize);
}
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class CuadriculaApp14 {
public static void main(String[] args) {
JFrame frame = new JFrame("Cuadrícula");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CuadriculaPanel14 panel = new CuadriculaPanel14();
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
class CuadriculaPanel14 extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int size = Math.min(getWidth(), getHeight());
int cellSize = size / 10;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
int x = i * cellSize;
int y = j * cellSize;
g2d.draw(new Rectangle2D.Double(x, y, cellSize, cellSize));
}
}
}
}