in case the code doesn't show up right, use this url:
My Java Code
import java.awt.*; import java.awt.event.*; import java.swing.*; import java.swing.event.*; public class Calories extends JFrame implements ActionListener { private JTextArea caloriesJT, fatJT, percentJT; private JLabel calorieJL, fatJL, percent JL, introJL; private JButton calculateJB; private Container c; public Calories() { super("Calories from Fat"); c=getContentPane(); c.setBackground(Color.grey); c.setLayout(new BorderLayout(5,5)); JLabel introJL=("This will help you to determine the amount of\n calories that come from fat in a food.\n Please enter the total calories followed by the\n total grams of fat and press 'Calculate' when done."); JLabel calorieJL=("Total amount of calories: "); JLabel fatJL=("Total grams of fat: "); JLabel percentJL=("Percentage of Calories from Fat: "); c.add(introJL, BorderLayout.NORTH); introJL.setFont(newFont("Courier", Font.BOLD, 18); c.add(calorieJL, BorderLayout.WEST); calorieJL.setFont(newFont("Courier", Font.BOLD, 18); c.add(calorieJT, BorderLayout.WEST); c.add(fatJL, BorderLayout.WEST); fatJL.setFont(newFont("Courier", Font.BOLD, 18); c.add(fatJT, BorderLayout.WEST); c.add(percentJL, BorderLayout.EAST); percentJL.setFont(newFont("Courier", Font.BOLD, 18); c.add(percentJT, BorderLayout.EAST); JButton calculateJB=("Calculate"); calculateJB.setFont(newFont("Courier", Font.BOLD, 18); c.add(calculateJB, BorderLayout.SOUTH); calculate.addActionListener(this); setSize(350, 350); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } private void displayPercent() { int calorie, fat, percent; percent.setEditable(false); percent.setText(""); //read in calorie and fat percent=(int)((fat*9)/calorie)*100; percentJT.append(percent+"%"); repaint(); } public void actionPerformed(ActionEvent event) { if(event.getActionCommand().equals("Calculate"))displayPercent(); } public static void main(String[] args) { Calories alc= new Calories(); } }