All generations.

class from descriptionSun, 18 Jun 2023

Create a class named Celda which extends JLabel and is intended to be in the same position as its attribute JLabel etiqueta, also has int id, num, where num is 2 to the power of id

import javax.swing.JLabel; public class Celda extends JLabel{ private JLabel etiqueta; private int id,num; public Celda(JLabel etiqueta, int id) { super(); this.etiqueta = etiqueta; this.id = id; this.num = (int)Math.pow(2, id); } public JLabel getEtiqueta() { return etiqueta; } public void setEtiqueta(JLabel etiqueta) { this.etiqueta = etiqueta; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } }

Java
View
class from descriptionSun, 18 Jun 2023

Create a class named Celda which extends JLabel and is intended to be in the same position as its attribute JLabel etiqueta, also has int id, num, where num is 2 to the power of id, and text is the num, also has a method to add 1 to id and refresh num and text

public class Celda extends JLabel { // attributes int id; int num; String text; // constructor public Celda(JLabel etiqueta, int id) { super(); this.setId(id); this.setNum(this.calculaNum(this.id)); this.setText(String.valueOf(this.num)); this.setBounds(etiqueta.getBounds()); this.setBackground(Color.BLUE); this.setOpaque(true); this.setHorizontalAlignment(SwingConstants.CENTER); this.setFont(new Font("Arial", Font.PLAIN, 26)); } // methods public int getId() { return this.id; } public void setId(int id) { this.id = id; } public int getNum() { return this.num; } public void setNum(int num) { this.num = num; } public String getText() {

Java
View

Questions about programming?Chat with your personal AI assistant