import java.applet.Applet; import java.awt.Dimension; import java.awt.GridLayout; import javax.swing.*; import java.io.FileNotFoundException; import java.util.Formatter; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.util.Scanner; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.Timer; public class applet extends JApplet { @Override public void init() { start(); } public class UserInterface { JLabel Bmi= new JLabel("Your Bmi is:"); JLabel BMIOutPut= new JLabel("BMIOUTPUT"); JLabel image1= new JLabel(); JLabel image2= new JLabel("IMAGE"); JTextArea Goal= new JTextArea("Please Enter Your Goal Weight:"); JTextArea GoalInput = new JTextArea("Delete this text"); JTextArea Week= new JTextArea("Please Enter How Many Weeks \n untill you plan to reach your goal"); JTextArea WeekInput = new JTextArea("Delete this text"); JButton Write = new JButton("Calculate"); JTextArea Safe= new JTextArea("Default"); JTextArea colarieOutPut= new JTextArea("Default"); public void Interface() { JPanel Panel = new JPanel(); Panel.setMaximumSize(new Dimension(400, 400)); Panel.setSize(800,500); Panel.setLocation(300,150); Panel.setVisible(false); GridLayout Layout = new GridLayout(0,4); Panel.setLayout(Layout); Panel.add(Bmi); Panel.add(BMIOutPut); Panel.add(image1); ImageIcon Icon = new ImageIcon("Default.jpg"); image1.setIcon(Icon); Panel.add(image2); Goal.setEditable(false); Goal.setCursor(null); Goal.setOpaque(false); Goal.setFont(UIManager.getFont("Label.font")); Panel.add(Goal); GoalInput.setOpaque(false); GoalInput.setFont(UIManager.getFont("Label.font")); Panel.add(GoalInput); Week.setEditable(false); Week.setCursor(null); Week.setOpaque(false); Week.setFont(UIManager.getFont("Label.font")); Panel.add(Week); WeekInput.setOpaque(false); WeekInput.setFont(UIManager.getFont("Label.font")); Panel.add(WeekInput); Panel.add(Write); Write.setSize(10,10); Write.setOpaque(false); Write.setFont(UIManager.getFont("Label.font")); Safe.setEditable(false); Safe.setCursor(null); Safe.setOpaque(false); Safe.setSize(1, 1); Safe.setFont(UIManager.getFont("Label.font")); Panel.add(Safe); JTextArea colarie= new JTextArea("To Obtain your target \n weight you need to consume:"); colarie.setEditable(false); colarie.setCursor(null); colarie.setOpaque(false); colarie.setSize(1, 1); Panel.add(colarie); colarie.setFont(UIManager.getFont("Label.font")); colarieOutPut.setEditable(false); colarieOutPut.setCursor(null); colarieOutPut.setOpaque(false); colarieOutPut.setSize(1, 1); Panel.add(colarieOutPut); colarieOutPut.setFont(UIManager.getFont("Label.font")); Panel.setVisible(true); Panel.repaint(); } } public class MainCode extends UserInterface { ImageIcon Icon_T = new ImageIcon("Thin.jpg"); ImageIcon Icon_n = new ImageIcon("normal.jpg"); ImageIcon Icon_F = new ImageIcon("Fatty.jpg"); int delay1 = 250; int delay2 = 500; private double Bmi_Output = 0; private int height = 0; private int weight = 0; private int calorie_input = 0; private int calorie = 0; private int calorie_temp = 0; private int CALORIE = 3500; private int BMI = 703; private int weight_goal= 0; private int weeks = 0; public int gain_lose_or_maintain = 0; private boolean saftey = false; private Scanner input;; public void openFile() { try { input = new Scanner(new File("User")); }//try catch( FileNotFoundException fileNotFoundException ) { System.err.println("Error opening file."); System.exit(1); }//catch }//openFile public double calculate_BMI() { height = input.nextInt(); weight = input.nextInt(); height = height * height; Bmi_Output = weight / height; Bmi_Output = Bmi_Output * BMI; return Bmi_Output ; }//calc BMI public int calorie_calc() { UserInterface You_Told_me_not_to_use_trololol_so_i_didnt = new UserInterface(); calorie_input= input.nextInt(); String temp_input= You_Told_me_not_to_use_trololol_so_i_didnt.GoalInput.getText(); weight_goal = Integer.parseInt(temp_input); weight = input.nextInt(); ; if (weight > weight_goal) { calorie_temp = (weight-weight_goal) * CALORIE; gain_lose_or_maintain = 1; } else if (weight < weight_goal) { calorie_temp = (weight_goal-weight) * CALORIE; gain_lose_or_maintain = 2; } else { calorie_temp = 0; gain_lose_or_maintain = 3; } String Temp_input = You_Told_me_not_to_use_trololol_so_i_didnt.WeekInput.getText(); weeks = Integer.parseInt(Temp_input); calorie = calorie_input - (calorie_temp / weeks); return calorie; }//calorie calc public boolean determine_if_safe() { double temp = weight_goal / height; if (temp > 18.5 && temp < 24.9) { if (calorie < 1200) { saftey = false; } else if (calorie >= 1200 && calorie_temp > (calorie_input*.2)) { saftey = true; } else { saftey = false; } } else { saftey = false; } return saftey; }//safe public void Change_Bmi() { BMIOutPut.setText("" + Bmi_Output); if(Bmi_Output < 18.5) { ActionListener Thin_Pic_label1 = new ActionListener() { public void actionPerformed(ActionEvent evt) { image1.setIcon(Icon_T); image2.setText(null); } }; ActionListener Thin_Pic_label2 = new ActionListener() { public void actionPerformed(ActionEvent evt) { image2.setIcon(Icon_T); image1.setText(null); } }; new Timer (delay1,Thin_Pic_label1).start(); new Timer (delay2,Thin_Pic_label2).start(); } else if(Bmi_Output > 18.5 && Bmi_Output < 24.9) { ActionListener Normal_Pic_label1 = new ActionListener() { public void actionPerformed(ActionEvent evt) { image1.setIcon(Icon_n); image2.setText(null); } }; ActionListener Normal_Pic_label2 = new ActionListener() { public void actionPerformed(ActionEvent evt) { image2.setIcon(Icon_n); image1.setText(null); } }; new Timer (delay1,Normal_Pic_label1).start(); new Timer (delay2,Normal_Pic_label2).start(); } else { ActionListener Fatty_Pic_label1 = new ActionListener() { public void actionPerformed(ActionEvent evt) { image1.setIcon(Icon_F); image2.setText(null); } }; ActionListener Fatty_Pic_label2 = new ActionListener() { public void actionPerformed(ActionEvent evt) { image2.setIcon(Icon_F); image1.setText(null); } }; new Timer (delay1,Fatty_Pic_label1).start(); new Timer (delay2,Fatty_Pic_label2).start(); } } public void Change_safe() { if (saftey = true) Safe.setText("It Is safe to reach that goal!"); else Safe.setText("It Is NOT safe to reach that goal"); } public void Change_Calorie() { colarieOutPut.setText("" + calorie); } public void Change_InterFace() { Write.addActionListener(new ActionListener(){ public void actionPerformed( ActionEvent event) { Change_Bmi(); Change_safe(); Change_Calorie(); WhatToOpen runs =new WhatToOpen(); try { runs.write_What_To_Open_Runner(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } }//end public class WhatToOpen { private Formatter output; public void openFile() throws FileNotFoundException { output = new Formatter( "LoseMaintainOrGain" ); }//open public void write_What_To_Open() { MainCode main = new MainCode(); output.format("%f",main.gain_lose_or_maintain); }//whattowrite public void closeFile() { if ( output != null ) output.close(); } // end method closeFile public void write_What_To_Open_Runner() throws FileNotFoundException { openFile(); write_What_To_Open(); closeFile(); } }//end public class Client { public void main(String[] args) { UserInterface runner = new UserInterface(); runner.Interface(); MainCode run = new MainCode(); run.Change_InterFace(); } } }