Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- import javax.swing.*;
- import java.awt.*;
- /**
- * @author reedpl1
- *
- */
- public class GPACalcDriver {
- /**
- * @param args
- */
- public static void main(String[] args)
- {
- GPACalcGUI gc = new GPACalcGUI();
- }
- }
- -------------------------------------------------------------------------------------------------------
- /**
- *
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.text.DecimalFormat;
- /**
- * @author reedpl1
- *
- */
- public class GPACalcGUI extends JFrame
- {
- private static final long serialVersionUID = 1L;
- private JPanel panel;
- private JLabel label1,
- label2,
- label3;
- private JButton calculate;
- private JButton quit;
- private final int WINDOW_WIDTH = 190;
- private final int WINDOW_HEIGHT = 153;
- private JTextField cred;
- private JTextField hour;
- private JTextField gpa;
- /**
- * @param args
- * @return
- */
- public GPACalcGUI()
- {
- super("GPA Calculator");
- cred = new JTextField(4);
- hour = new JTextField(4);
- gpa = new JTextField(4);
- setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- label1 = new JLabel("Credits Completed");
- label2 = new JLabel("Hours completed ");
- label3 = new JLabel("GPA ");
- calculate = new JButton("Calculate");
- quit = new JButton("Quit");
- calculate.addActionListener(new CalculateListener());
- quit.addActionListener(new QuitListener());
- panel = new JPanel();
- panel.add(label1);
- panel.add(cred);
- panel.add(label2);
- panel.add(hour);
- panel.add(label3);
- panel.add(gpa);
- panel.add(calculate);
- panel.add(quit);
- add(panel);
- setLocationRelativeTo(null);
- setVisible(true);
- }
- private class CalculateListener implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent arg0)
- {
- DecimalFormat df = new DecimalFormat("0.00");
- double calculatedGPA;
- calculatedGPA = (Double.parseDouble(cred.getText())) / (Double.parseDouble(hour.getText()));
- gpa.setText(new Double(df.format(calculatedGPA)).toString());
- }
- }
- private class QuitListener implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent arg0)
- {
- JOptionPane.showMessageDialog(null, "Thank you for using the program.");
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement