├── Calculator ├── src │ ├── App.java │ ├── JtabbedPane.java │ ├── Jframe.java │ └── Calculadora_IMC.java ├── .vscode │ └── settings.json └── README.md └── README.md /Calculator/src/App.java: -------------------------------------------------------------------------------- 1 | public class App { 2 | public static void main(String[] args) throws Exception { 3 | 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Calculator/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # I developed this calculator in this project here: Calculators Layout 2 | # To find out more about this project, just access the README from the link above 3 | -------------------------------------------------------------------------------- /Calculator/src/JtabbedPane.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | 3 | public class JtabbedPane extends JTabbedPane{ 4 | public JtabbedPane() { 5 | super(); 6 | this.add("Calculadora IMC", new Calculadora_IMC()); 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Calculator/src/Jframe.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | 3 | public class Jframe extends JFrame{ 4 | public Jframe() { 5 | super("SA3 GUI Layout"); 6 | this.add(new JtabbedPane()); 7 | 8 | 9 | // set frame 10 | this.setBounds(500, 250, 500, 500); 11 | this.setDefaultCloseOperation(2); 12 | this.setVisible(true); 13 | this.pack(); 14 | } 15 | } -------------------------------------------------------------------------------- /Calculator/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Calculator/src/Calculadora_IMC.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import javax.swing.border.LineBorder; 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | 6 | // import javafx.event.ActionEvent; 7 | 8 | import java.awt.*; 9 | 10 | public class Calculadora_IMC extends JPanel { 11 | public Calculadora_IMC() { 12 | // criação dos componentes 13 | JLabel alturaUsuario = new JLabel("Digite sua altura (m): "); 14 | JLabel pesoUsuario = new JLabel("Digite seu peso (kg): "); 15 | JTextField campoAltura = new JTextField(10); 16 | JTextField campoPeso = new JTextField(10); 17 | JButton botaoCalcular = new JButton("Calcular"); 18 | JLabel resultadoIMC = new JLabel("IMC: "); 19 | JTextField campoResultado = new JTextField(10); 20 | JLabel mensagemAbaixoPeso = new JLabel("Abaixo do Peso"); 21 | mensagemAbaixoPeso.setForeground(Color.RED); 22 | JLabel mensagemPesoIdeal = new JLabel("Peso Ideal"); 23 | mensagemPesoIdeal.setForeground(Color.DARK_GRAY); 24 | JLabel mensagemAcimaPeso = new JLabel("Acima do Peso"); 25 | mensagemAcimaPeso.setForeground(Color.BLUE); 26 | campoResultado.setEditable(false); 27 | mensagemAbaixoPeso.setVisible(false); 28 | mensagemPesoIdeal.setVisible(false); 29 | mensagemAcimaPeso.setVisible(false); 30 | 31 | // Criação dos painéis 32 | JPanel painelPrincipal = new JPanel(new BorderLayout()); // Border Layout 33 | JPanel painelBotoes = new JPanel(); 34 | JPanel painelInputs = new JPanel(new GridLayout(2, 2)); 35 | JPanel painelResultado = new JPanel(); 36 | 37 | 38 | // adicionando os componentes aos painéis 39 | painelInputs.add(alturaUsuario); 40 | painelInputs.add(campoAltura); 41 | painelInputs.add(pesoUsuario); 42 | painelInputs.add(campoPeso); 43 | 44 | botaoCalcular.setBackground(Color.GREEN); 45 | painelBotoes.add(botaoCalcular); 46 | 47 | campoResultado.setBorder(new LineBorder(Color.BLACK)); 48 | 49 | painelResultado.add(resultadoIMC); 50 | painelResultado.add(campoResultado); 51 | painelResultado.add(mensagemAbaixoPeso); 52 | painelResultado.add(mensagemPesoIdeal); 53 | painelResultado.add(mensagemAcimaPeso); 54 | 55 | // adicionando os painéis ao painel principal 56 | painelPrincipal.add(painelInputs, BorderLayout.NORTH); 57 | painelPrincipal.add(painelBotoes, BorderLayout.CENTER); 58 | painelPrincipal.add(painelResultado, BorderLayout.SOUTH); 59 | 60 | this.add(painelPrincipal); 61 | 62 | botaoCalcular.addActionListener(new ActionListener() { 63 | @Override 64 | public void actionPerformed(ActionEvent e) { 65 | try { 66 | double altura = Double.parseDouble(campoAltura.getText()); 67 | double peso = Double.parseDouble(campoPeso.getText()); 68 | 69 | double imc = peso / (altura * altura); 70 | 71 | if (imc < 18.5) { 72 | mensagemAbaixoPeso.setVisible(true); 73 | mensagemPesoIdeal.setVisible(false); 74 | mensagemAcimaPeso.setVisible(false); 75 | campoResultado.setText(String.format("%.2f", imc, "Você está abaixo do peso")); 76 | 77 | } 78 | 79 | else if (imc >= 18.5 && imc <= 24.9) { 80 | mensagemAbaixoPeso.setVisible(false); 81 | mensagemPesoIdeal.setVisible(true); 82 | mensagemAcimaPeso.setVisible(false); 83 | campoResultado.setText(String.format("%.2f", imc, "Você está no peso ideal")); 84 | } 85 | else { 86 | mensagemAbaixoPeso.setVisible(false); 87 | mensagemPesoIdeal.setVisible(false); 88 | mensagemAcimaPeso.setVisible(true); 89 | campoResultado.setText(String.format("%.2f", imc, "Você está acima do peso")); 90 | } 91 | 92 | 93 | } catch (NumberFormatException ex) { 94 | campoResultado.setText("Valores inválidos"); 95 | } 96 | 97 | } 98 | }); 99 | 100 | } 101 | } --------------------------------------------------------------------------------