FlexibleData.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package ui.view;
  2. import javax.swing.JPanel;
  3. import javax.swing.JLabel;
  4. import java.awt.Font;
  5. import java.awt.Dimension;
  6. import java.awt.Color;
  7. public class FlexibleData extends JPanel {
  8. private JLabel name_lbl;
  9. private JLabel lblProdVal;
  10. private JLabel lblConsVal;
  11. private JLabel lblProdConsVal;
  12. public FlexibleData(String name, float prod, float cons) {
  13. setPreferredSize(new Dimension(614, 100));
  14. setMinimumSize(new Dimension(600, 150));
  15. setLayout(null);
  16. name_lbl = new JLabel();
  17. name_lbl.setFont(new Font("Tahoma", Font.PLAIN, 13));
  18. name_lbl.setBounds(10, 11, 125, 27);
  19. setlblName(name);
  20. add(name_lbl);
  21. JLabel lblFlProd = new JLabel("Flex. Prod. :");
  22. lblFlProd.setForeground(new Color(0, 128, 0));
  23. lblFlProd.setBounds(31, 46, 65, 27);
  24. add(lblFlProd);
  25. JLabel lblFlexCons = new JLabel("Flex. Cons. :\r\n");
  26. lblFlexCons.setForeground(new Color(255, 0, 0));
  27. lblFlexCons.setBounds(181, 46, 65, 27);
  28. add(lblFlexCons);
  29. JLabel lblProdCons = new JLabel("Prod./Cons. :");
  30. lblProdCons.setForeground(new Color(218, 165, 32));
  31. lblProdCons.setBounds(327, 46, 65, 27);
  32. add(lblProdCons);
  33. lblProdVal = new JLabel();
  34. setProd(prod);
  35. lblProdVal.setBounds(100, 47, 72, 24);
  36. add(lblProdVal);
  37. lblConsVal = new JLabel();
  38. setCons(cons);
  39. lblConsVal.setBounds(252, 47, 72, 24);
  40. add(lblConsVal);
  41. lblProdConsVal = new JLabel();
  42. if(cons != 0 && prod != 0){
  43. lblProdConsVal.setText(Float.toString((prod/cons)*(-1)));
  44. }else if(prod == 0 && cons == 0){
  45. lblProdConsVal.setText("not producing or consuming...");
  46. }else if(prod == 0){
  47. lblProdConsVal.setText("only consuming...");
  48. }else if(cons == 0){
  49. lblProdConsVal.setText("only producing...");
  50. }
  51. lblProdConsVal.setBounds(402, 46, 173, 24);
  52. add(lblProdConsVal);
  53. }
  54. public void setProd(float p){
  55. lblProdVal.setText(Float.toString(p));
  56. }
  57. public void setCons(float c){
  58. lblConsVal.setText(Float.toString(c));
  59. }
  60. public void setProdConsVal(float prod, float cons){
  61. if(cons != 0 && prod != 0){
  62. lblProdConsVal.setText(Float.toString((prod/cons)*(-1)));
  63. }else if(prod == 0 && cons == 0){
  64. lblProdConsVal.setText("not producing or consuming...");
  65. }else if(prod == 0){
  66. lblProdConsVal.setText("only consuming...");
  67. }else if(cons == 0){
  68. lblProdConsVal.setText("only producing...");
  69. }
  70. }
  71. public void setlblName(String name){
  72. name_lbl.setText(name);
  73. }
  74. }