Java tutorial
/* ----------------------------------------------------------------- @file fridgeApplet.java @author Juan Hernandez Garcia ----------------------------------------------------------------- Copyright (C) 2014 Modesto Modesto T Lopez-Lopez Francisco Nogueras Lara Juan Hernandez Garcia University of Granada -------------------------------------------------------------------- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.juanhg.fridge; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.ImageIcon; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.BevelBorder; import javax.swing.border.CompoundBorder; import javax.swing.border.EtchedBorder; import javax.swing.border.LineBorder; import javax.swing.border.MatteBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.jfree.chart.annotations.XYAnnotation; import com.raccoon.easyjchart.Grafica; import com.raccoon.easyjchart.JPanelGrafica; public class FridgeApplet extends JApplet implements Runnable { private static final long serialVersionUID = -3017107307819023599L; private final String fridge = "fridge.png"; private final String fish = "fish.png"; private final String milk = "milk2.png"; private final String metal = "metal.png"; final int pistonY0 = 3; final int pistonY1 = 7; //Control variables long sleepTime = 300; boolean end = false; //Inputs double P, T1, T2, Qo; int type = 1; int n, phase; //Thread that executed the simulation private Thread flujo = null; //Model private FridgeModel model; //Charts private Grafica chartfridge; //Panels private JPanelGrafica panelGrafica; int supXLimit = 10; int infXLimit = 0; int supYLimit = 10; int infYLimit = 0; //Images BufferedImage fridgeImage, fishImage, metalImage, milkImage; //Annotations XYAnnotation exampleAnnotation = null; //Labels private JLabel lblTValue; private JLabel lblT1Value, lblT2Value, lblPValue, lblEValue, lblQcValue, lblOffValue; private JLabel lblO1; //Sliders private JSlider sliderP, sliderT1, sliderT2, sliderQc; //Buttons JButton btnLaunchSimulation, btnMilk, btnFish, btnMetal, btn1, btn2; public FridgeApplet() { } public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } repaint(); } public void initComponents() { setSize(800, 590); this.autogeneratedCode(); //Obtain values from interface this.readInputs(); this.initSimulation(); } private void sliderI1Event() { //350 - 450 if (sliderP.getValueIsAdjusting()) { lblPValue.setText(Integer.toString(sliderP.getValue())); } } private void sliderI2Event() { //270-330 if (sliderT1.getValueIsAdjusting()) { double staticF; staticF = (double) sliderT1.getValue(); lblT1Value.setText("" + staticF); } } private void sliderI3Event() { //1-5 double dynamicF; if (sliderT2.getValueIsAdjusting()) { dynamicF = -(double) sliderT2.getValue(); lblT2Value.setText("" + dynamicF); } } private void sliderI4Event() { //6-10 double dynamicF; if (sliderQc.getValueIsAdjusting()) { dynamicF = (double) sliderQc.getValue(); lblQcValue.setText("" + dynamicF); } } void btnLaunchSimulationEvent(ActionEvent event) { boolean buttonsOn = false; if (flujo != null && flujo.isAlive()) { end = true; buttonsOn = true; while (flujo.isAlive()) { } this.readInputs(); this.finishSimulation(); btnLaunchSimulation.setText("Iniciar"); sliderP.setEnabled(buttonsOn); sliderT2.setEnabled(buttonsOn); sliderQc.setEnabled(buttonsOn); sliderT1.setEnabled(buttonsOn); repaint(); } else { buttonsOn = false; btnLaunchSimulation.setText("Finalizar"); //Obtain values from interface this.readInputs(); this.initSimulation(); //Initializes and runs the thread (Run()) flujo = new Thread(); flujo = new Thread(this); sliderP.setEnabled(buttonsOn); sliderT2.setEnabled(buttonsOn); sliderQc.setEnabled(buttonsOn); sliderT1.setEnabled(buttonsOn); btnMilk.setEnabled(false); btnFish.setEnabled(false); btnMetal.setEnabled(false); btn1.setEnabled(false); btn2.setEnabled(true); flujo.start(); } } private void btnFishFunction() { btn1.setEnabled(false); btn2.setEnabled(false); btnMilk.setEnabled(false); btnMetal.setEnabled(false); if (n >= 4) { btnFish.setEnabled(false); } else { n++; } type = 1; BufferedImage image = selectImage(); Point2D point = null; switch (n) { case 1: point = new Point2D.Double(5.4, 3.3); break; case 2: point = new Point2D.Double(5.4, 4.3); break; case 3: point = new Point2D.Double(5.4, 5.8); break; case 4: point = new Point2D.Double(5.4, 7.4); break; } chartfridge.setImageAtPoint(image, point); repaint(); } private void btnMetalFunction() { btn1.setEnabled(false); btn2.setEnabled(false); btnMilk.setEnabled(false); btnFish.setEnabled(false); if (n >= 4) { btnMetal.setEnabled(false); } else { n++; } type = 3; BufferedImage image = selectImage(); Point2D point = null; switch (n) { case 1: point = new Point2D.Double(5.4, 3.3); break; case 2: point = new Point2D.Double(5.4, 4.3); break; case 3: point = new Point2D.Double(5.4, 5.8); break; case 4: point = new Point2D.Double(5.4, 7.4); break; } chartfridge.setImageAtPoint(image, point); repaint(); } private void btnMilkFunction() { btn1.setEnabled(false); btn2.setEnabled(false); btnFish.setEnabled(false); btnMetal.setEnabled(false); if (n >= 4) { btnMilk.setEnabled(false); } else { n++; } type = 2; BufferedImage image = selectImage(); Point2D point = null; switch (n) { case 1: point = new Point2D.Double(4.8, 4.6); break; case 2: point = new Point2D.Double(5.8, 4.6); break; case 3: point = new Point2D.Double(6.8, 4.6); break; case 4: point = new Point2D.Double(3.8, 4.6); break; } chartfridge.setImageAtPoint(image, point); repaint(); } private BufferedImage selectImage() { switch (type) { case 1: return fishImage; case 2: return milkImage; case 3: return metalImage; } return null; } void drawMeal(BufferedImage image) { Point2D point = null; switch (n) { case 1: point = new Point2D.Double(5.4, 3.3); break; case 2: point = new Point2D.Double(5.4, 4.3); break; case 3: point = new Point2D.Double(5.4, 5.8); break; case 4: point = new Point2D.Double(5.4, 7.4); break; } if (n > 0) { chartfridge.setImageAtPoint(image, point); } repaint(); } public String dToString(double value, int precision) { String x = String.valueOf(value); if (x.length() > precision) { return (x.substring(0, precision)); } else { return x; } } @Override public void run() { end = false; while (!end) { //Begin step of simulation model.simulate(); //End Step of simulation lblTValue.setText(dToString(model.getT(), 6)); lblEValue.setText(dToString(model.getE(), 6)); lblOffValue.setText(dToString(model.getTd(), 6)); this.updatePanels(); repaint(); try { Thread.sleep(sleepTime); } catch (InterruptedException ex) { Logger.getLogger(FridgeApplet.class.getName()).log(Level.SEVERE, null, ex); } } } /** * Read the input values from the interface and loads its * in the variable of the class */ private void readInputs() { P = sliderP.getValue(); T1 = sliderT1.getValue(); T2 = -sliderT2.getValue(); Qo = sliderQc.getValue(); } private void finishSimulation() { Point2D[] nullArray = new Point2D[0]; //Crear modelo model = new FridgeModel(T1, T2, P, Qo, type, n, phase); // Inicializar charts chartfridge = new Grafica(nullArray, "", "", "V", "P", false, Color.BLUE, 1f, false); chartfridge.setRangeAxis(infXLimit, supXLimit, infYLimit, supYLimit); chartfridge.fijaFondo(Color.WHITE); chartfridge.setAxisVisible(false); //Load Images fridgeImage = loadImage(fridge); fishImage = loadImage(fish); milkImage = loadImage(milk); metalImage = loadImage(metal); //Set Images chartfridge.setImageAtPoint(fridgeImage, (infXLimit + supXLimit) / 2.0, (infYLimit + supYLimit) / 2.0); btnMilk.setEnabled(false); btnFish.setEnabled(false); btnMetal.setEnabled(false); btn1.setEnabled(false); btn2.setEnabled(true); phase = 1; n = 0; lblTValue.setText("-"); lblEValue.setText("-"); lblOffValue.setText("-"); //Actualize panels updatePanels(); repaint(); } //Init the elements of the simulation private void initSimulation() { Point2D[] nullArray = new Point2D[0]; if (model == null) { //Crear modelo model = new FridgeModel(T1, T2, P, Qo, type, n, phase); // Inicializar charts chartfridge = new Grafica(nullArray, "", "", "V", "P", false, Color.BLUE, 1f, false); chartfridge.setRangeAxis(infXLimit, supXLimit, infYLimit, supYLimit); chartfridge.fijaFondo(Color.WHITE); chartfridge.setAxisVisible(false); //Load Images fridgeImage = loadImage(fridge); fishImage = loadImage(fish); milkImage = loadImage(milk); metalImage = loadImage(metal); //Set Images chartfridge.setImageAtPoint(fridgeImage, (infXLimit + supXLimit) / 2.0, (infYLimit + supYLimit) / 2.0); } else { model.restart(T1, T2, P, Qo, type, n, phase); } btnMilk.setEnabled(false); btnFish.setEnabled(false); btnMetal.setEnabled(false); btn1.setEnabled(false); btn2.setEnabled(true); phase = 1; n = 0; //Actualize panels updatePanels(); repaint(); } /** * Load a image in the specified path * @param fileName Absolute or relative path to the image * @return BufferedImage that contains the image */ public BufferedImage loadImage(String fileName) { BufferedImage buff = null; try { buff = ImageIO.read(getClass().getResourceAsStream(fileName)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return buff; } int obtainExponent(double number) { int exponent = 0; while (0 == (int) number) { exponent--; number *= 10; } return exponent; } private void updatePanels() { panelGrafica.actualizaGrafica(chartfridge); } public double normalize(double x, double a, double b, double c, double d) { return (x * (d - c)) / (b - a) + (c * b - a * d) / (b - a); } private void autogeneratedCode() { JPanel panel_control = new JPanel(); panel_control.setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.RAISED, null, null), new BevelBorder(BevelBorder.RAISED, null, null, null, null))); JPanel panelInputs = new JPanel(); panelInputs.setToolTipText(""); panelInputs.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); JPanel panelOutputs = new JPanel(); panelOutputs.setToolTipText(""); panelOutputs.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); JPanel panelTitleOutputs = new JPanel(); panelTitleOutputs.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null)); JLabel labelOutputData = new JLabel("Datos de la Simulaci\u00F3n"); labelOutputData.setFont(new Font("Tahoma", Font.PLAIN, 14)); panelTitleOutputs.add(labelOutputData); lblO1 = new JLabel("Tiempo On:"); lblO1.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblTValue = new JLabel(); lblTValue.setText("0"); lblTValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel lblO2 = new JLabel("Eficiencia:"); lblO2.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblEValue = new JLabel(); lblEValue.setText("0"); lblEValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel lblTiempoOff = new JLabel("Tiempo Off:"); lblTiempoOff.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblOffValue = new JLabel(); lblOffValue.setText("0"); lblOffValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); GroupLayout gl_panelOutputs = new GroupLayout(panelOutputs); gl_panelOutputs.setHorizontalGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addComponent(panelTitleOutputs, GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE) .addGroup(gl_panelOutputs.createSequentialGroup().addGap(22) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addComponent(lblO2, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) .addComponent(lblO1, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addComponent(lblEValue, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE) .addGroup(gl_panelOutputs.createSequentialGroup() .addComponent(lblTValue, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE) .addGap(31) .addComponent(lblTiempoOff, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(lblOffValue, GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE))) .addContainerGap())); gl_panelOutputs .setVerticalGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelOutputs.createSequentialGroup() .addComponent(panelTitleOutputs, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addComponent(lblOffValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(lblTiempoOff, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addGroup(gl_panelOutputs.createSequentialGroup() .addGroup(gl_panelOutputs.createParallelGroup(Alignment.BASELINE) .addComponent(lblO1).addComponent(lblTValue)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.BASELINE) .addComponent(lblO2, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(lblEValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)))))); panelOutputs.setLayout(gl_panelOutputs); JPanel panelLicense = new JPanel(); panelLicense.setBorder(new LineBorder(new Color(0, 0, 0))); JPanel panel_6 = new JPanel(); panel_6.setBorder(new LineBorder(new Color(0, 0, 0))); GroupLayout gl_panel_control = new GroupLayout(panel_control); gl_panel_control .setHorizontalGroup(gl_panel_control.createParallelGroup(Alignment.TRAILING) .addGroup(Alignment.LEADING, gl_panel_control.createSequentialGroup().addContainerGap() .addGroup(gl_panel_control.createParallelGroup(Alignment.LEADING) .addComponent(panelOutputs, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(panelInputs, GroupLayout.PREFERRED_SIZE, 346, Short.MAX_VALUE) .addComponent(panel_6, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 346, Short.MAX_VALUE) .addComponent(panelLicense, GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)) .addContainerGap())); gl_panel_control.setVerticalGroup(gl_panel_control.createParallelGroup(Alignment.TRAILING) .addGroup(gl_panel_control.createSequentialGroup().addContainerGap() .addComponent(panelInputs, GroupLayout.PREFERRED_SIZE, 305, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(panelOutputs, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(panel_6, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED).addComponent(panelLicense, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(24))); btnLaunchSimulation = new JButton("Iniciar"); btnLaunchSimulation.setFont(new Font("Tahoma", Font.PLAIN, 16)); btnLaunchSimulation.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { btnLaunchSimulationEvent(event); } }); GroupLayout gl_panel_6 = new GroupLayout(panel_6); gl_panel_6.setHorizontalGroup(gl_panel_6.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, gl_panel_6.createSequentialGroup().addContainerGap() .addComponent(btnLaunchSimulation, GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE) .addContainerGap())); gl_panel_6.setVerticalGroup(gl_panel_6.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_6 .createSequentialGroup().addContainerGap().addComponent(btnLaunchSimulation, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE) .addContainerGap(69, Short.MAX_VALUE))); panel_6.setLayout(gl_panel_6); JLabel lblNewLabel = new JLabel("GNU GENERAL PUBLIC LICENSE"); panelLicense.add(lblNewLabel); JLabel LabelI1 = new JLabel("Potencia"); LabelI1.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel labelI2 = new JLabel("T1"); labelI2.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel labelI3 = new JLabel("T2"); labelI3.setFont(new Font("Tahoma", Font.PLAIN, 14)); JPanel panelTitle = new JPanel(); panelTitle.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null)); lblT1Value = new JLabel("20"); lblT1Value.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblT2Value = new JLabel("-15"); lblT2Value.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblPValue = new JLabel("700"); lblPValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); sliderP = new JSlider(); sliderP.setMinimum(500); sliderP.setMaximum(1000); sliderP.setMinorTickSpacing(50); sliderP.setValue(700); sliderP.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { sliderI1Event(); } }); sliderT1 = new JSlider(); sliderT1.setMinimum(18); sliderT1.setMaximum(30); sliderT1.setMinorTickSpacing(1); sliderT1.setValue(20); sliderT1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sliderI2Event(); } }); sliderT2 = new JSlider(); sliderT2.setMinimum(10); sliderT2.setMaximum(30); sliderT2.setValue(15); sliderT2.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sliderI3Event(); } }); JLabel lblQo = new JLabel("Qo"); lblQo.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblQcValue = new JLabel("25"); lblQcValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); sliderQc = new JSlider(); sliderQc.setMinimum(10); sliderQc.setMaximum(50); sliderQc.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { sliderI4Event(); } }); sliderQc.setValue(25); sliderQc.setMinorTickSpacing(1); btn1 = new JButton("1"); btn1.setFont(new Font("Tahoma", Font.PLAIN, 21)); btn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { btnMilk.setEnabled(false); btnFish.setEnabled(false); btnMetal.setEnabled(false); btn1.setEnabled(false); btn2.setEnabled(true); sliderQc.setEnabled(true); lblQcValue.setText("" + sliderQc.getValue()); } }); btn2 = new JButton("2"); btn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnMilk.setEnabled(true); btnFish.setEnabled(true); btnMetal.setEnabled(true); btn1.setEnabled(true); btn2.setEnabled(false); phase = 2; sliderQc.setEnabled(false); lblQcValue.setText("-"); } }); btn2.setFont(new Font("Tahoma", Font.PLAIN, 21)); fishImage = loadImage(fish); btnFish = new JButton(new ImageIcon(fishImage)); btnFish.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { btnFishFunction(); } }); milkImage = loadImage(milk); btnMilk = new JButton(new ImageIcon(milkImage)); btnMilk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnMilkFunction(); } }); metalImage = loadImage(metal); btnMetal = new JButton(new ImageIcon(metalImage)); btnMetal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnMetalFunction(); } }); GroupLayout gl_panelInputs = new GroupLayout(panelInputs); gl_panelInputs .setHorizontalGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addComponent(panelTitle, GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE) .addGroup(gl_panelInputs.createSequentialGroup().addGap(38).addGroup(gl_panelInputs .createParallelGroup(Alignment.LEADING).addGroup( gl_panelInputs.createSequentialGroup().addGap(36) .addComponent(btn1, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(btn2, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panelInputs.createSequentialGroup().addGroup(gl_panelInputs .createParallelGroup(Alignment.LEADING, false) .addComponent(lblQo, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(labelI3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(labelI2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(LabelI1, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)) .addGap(18) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING, false) .addGroup(gl_panelInputs.createSequentialGroup() .addGroup(gl_panelInputs .createParallelGroup(Alignment.LEADING) .addComponent(lblPValue, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE) .addComponent(lblT1Value, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE) .addComponent(lblT2Value, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_panelInputs .createParallelGroup(Alignment.LEADING, false) .addComponent(sliderT1, 0, 0, Short.MAX_VALUE) .addComponent(sliderP, GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE) .addComponent(sliderT2, 0, 0, Short.MAX_VALUE))) .addGroup(gl_panelInputs.createSequentialGroup() .addComponent(lblQcValue, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE) .addGap(18) .addComponent(sliderQc, 0, 0, Short.MAX_VALUE))))) .addContainerGap(14, Short.MAX_VALUE)) .addGroup(Alignment.TRAILING, gl_panelInputs.createSequentialGroup() .addContainerGap(28, Short.MAX_VALUE) .addComponent(btnFish, GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnMilk, GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnMetal, GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE) .addGap(25))); gl_panelInputs.setVerticalGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createSequentialGroup() .addComponent(panelTitle, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(18) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(LabelI1).addComponent(lblPValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addComponent(sliderP, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(labelI2).addComponent(lblT1Value, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addComponent(sliderT1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(11) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING).addComponent(labelI3) .addComponent(lblT2Value, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(sliderT2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(lblQo, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(lblQcValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addComponent(sliderQc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addComponent(btn1, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE) .addComponent(btn2, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING, false) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addComponent(btnMetal, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE) .addComponent(btnMilk, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panelInputs.createSequentialGroup().addGap(1).addComponent(btnFish, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap(12, Short.MAX_VALUE))); JLabel lblDatosDeEntrada = new JLabel("Datos de Entrada"); lblDatosDeEntrada.setFont(new Font("Tahoma", Font.PLAIN, 14)); panelTitle.add(lblDatosDeEntrada); panelInputs.setLayout(gl_panelInputs); panel_control.setLayout(gl_panel_control); JPanel panel_visualizar = new JPanel(); panel_visualizar.setBackground(Color.WHITE); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addContainerGap() .addComponent(panel_control, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(panel_visualizar, GroupLayout.PREFERRED_SIZE, 398, GroupLayout.PREFERRED_SIZE) .addGap(452))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addGroup(groupLayout .createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addGap(12).addComponent(panel_visualizar, GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE)) .addGroup(groupLayout.createSequentialGroup().addContainerGap().addComponent(panel_control, GroupLayout.PREFERRED_SIZE, 568, GroupLayout.PREFERRED_SIZE))) .addContainerGap())); JPanel panel = new JPanel(); panelGrafica = new JPanelGrafica(); GroupLayout gl_panel = new GroupLayout(panel); gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGap(0, 384, Short.MAX_VALUE) .addComponent(panelGrafica, GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE)); gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGap(0, 241, Short.MAX_VALUE) .addComponent(panelGrafica, GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)); panel.setLayout(gl_panel); GroupLayout gl_panel_visualizar = new GroupLayout(panel_visualizar); gl_panel_visualizar.setHorizontalGroup(gl_panel_visualizar.createParallelGroup(Alignment.LEADING) .addComponent(panel, GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)); gl_panel_visualizar.setVerticalGroup(gl_panel_visualizar.createParallelGroup(Alignment.LEADING) .addComponent(panel, GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE)); panel_visualizar.setLayout(gl_panel_visualizar); getContentPane().setLayout(groupLayout); } }