package healthintensifies; import javax.swing.*; import java.util.Scanner; import java.util.ArrayList; import java.awt.*; import java.awt.event.*; import java.io.*; import java.lang.Object; public class Health extends JPanel{ private static double calories; private static double weight; // once every 2 days private static double height; // once a month private static String notification; private static double BMI; private static String feedback; private static ArrayList foodsItems; private static boolean firstTime; public static void main (String[] args) { firstTime = true; showOpeningBox(); getInfo(); homescreen(); } public static double getBMI() { double heightInMeters = height * 0.01; // convert from feet to meters double weightInKG = weight * 0.45359237; // convert from lbs to kg double BMI = weightInKG/(heightInMeters * heightInMeters); return BMI; } public Health(double w, double h, double cal) { calories = cal; height = h; weight = w; BMI = getBMI(); } public static void showOpeningBox() { JOptionPane.showMessageDialog(null, "Welcome to manGO!", "Welcome!", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Your personal health tracker app", "Welcome!", JOptionPane.INFORMATION_MESSAGE); } public static void getInfo() { if (firstTime) { JOptionPane.showMessageDialog(null, "Before we start, let's get some information", "Welcome!", JOptionPane.INFORMATION_MESSAGE); } JTextField field1 = new JTextField(); JTextField field2 = new JTextField(); JTextField field3 = new JTextField(); Object[] fields = { "Weight", field1, "Height", field2, "Calories", field3 }; JOptionPane.showConfirmDialog(null, fields, "Your health", JOptionPane.OK_CANCEL_OPTION); if (field1.getText().trim().isEmpty()||field2.getText().trim().isEmpty()||field3.getText().trim().isEmpty()) { JOptionPane.showMessageDialog(null, "It seems that you left one field blank. Please remember to enter all the values", "Error", JOptionPane.INFORMATION_MESSAGE); firstTime = false; getInfo(); } Health u = new Health((double)(Double.valueOf(field1.getText().trim())),(double)(Double.valueOf(field2.getText().trim())),(double)(Double.valueOf(field3.getText().trim()))); } public static void homescreen() { JFrame f=new JFrame("Home"); JButton a = new JButton("My Information"); a.setBounds(10,100,150, 70); /*Distance from left, Distance from top,length of button, height of button*/ JButton b = new JButton("Alternate Food Options"); b.setBounds(170,100,170, 70); JButton c = new JButton("Map"); c.setBounds(350,100,150, 70); JButton d = new JButton ("Log Out"); d.setBounds(510,100,150,70); f.add(a); f.add(b); f.add(c); f.add(d); JLabel v = new JLabel(""); v.setText("Hello"); // v.setFont(font); JPanel p = new JPanel(); p.add(v); f.add(p); f.setSize(700,600); f.setLayout(null); f.getContentPane().setBackground(Color.orange); f.setVisible(true); a.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myInformation(f); } }); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OtherOptions(f); } }); c.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { map(f); } }); d.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { logOut(f); } }); } public static void myInformation(JFrame g) { g.setVisible(false); JFrame window = new JFrame("Your Information"); JPanel panel=new JPanel (); JLabel l1= new JLabel ("Weight = " + weight + " lbs"); l1.setFont(new Font("Verdana", Font.PLAIN, 18)); JLabel l2= new JLabel("Height = " + height + " centimeters"); l2.setFont(new Font("Verdana", Font.PLAIN, 18)); JLabel l3= new JLabel("BMI = " + BMI ); l3.setFont(new Font("Verdana", Font.PLAIN, 18)); panel.setPreferredSize(new Dimension(640, 480)); panel.setVisible(true); panel.setBorder(BorderFactory.createLineBorder(Color.gray,10)); panel.add(l1); l1.setHorizontalAlignment(JLabel.CENTER); panel.add(l2); l2.setHorizontalAlignment(JLabel.CENTER); panel.add(l3); l3.setHorizontalAlignment(JLabel.CENTER); window.setLayout(new FlowLayout()); panel.setPreferredSize(new Dimension (300,300)); panel.setBackground(Color.red); window.add(panel, BorderLayout.WEST); window.setSize(400,400); if (BMI<=18) { feedback = "You are Underweight"; } else if (BMI<=24&&BMI>18) feedback = "Healthy"; else if (BMI>24&&BMI<=29) feedback = "You are overweight"; else if (BMI>29&&BMI<=39) { feedback = "You are obsese"; } else { feedback = "You are extremely obese"; } JLabel l4 = new JLabel(feedback); l4.setFont(new Font("Verdana", Font.PLAIN, 18)); panel.add(l4); l4.setHorizontalAlignment(JLabel.CENTER); JButton a = new JButton("Home"); a.setBounds(30,150,250,150); panel.add(a); /*Distance from left, Distance from top,length of button, height of button*/ window.setVisible(true); a.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setVisible(false); homescreen(); } }); } public static void OtherOptions(JFrame g) { g.setVisible(false); } public static void map(JFrame g) { g.setVisible(false); } public static void logOut(JFrame f) { f.setVisible(false); } }