Skip to content

Instantly share code, notes, and snippets.

@mrspucches
Last active June 29, 2018 18:17
Show Gist options
  • Save mrspucches/f74cc0b629fbe069ec32094c07d6158d to your computer and use it in GitHub Desktop.
Save mrspucches/f74cc0b629fbe069ec32094c07d6158d to your computer and use it in GitHub Desktop.
/*Dominic Spucches
*29JUN2018
*Blood Drive takes input of pints of blood donated
*and averages the number
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class bdrive extends JFrame implements ActionListener
{
JLabel title = new JLabel("HVCC Blood Drive");
Font insfont = new Font("Courier", Font.ITALIC, 18);
JLabel instruct = new JLabel("Enter pints donated for each department.");
Font insfont1 = new Font("Courier", Font.ITALIC, 13);
JLabel dept1 = new JLabel("Dept 1");
JTextField dept1field = new JTextField(6);
JLabel dept2 = new JLabel("Dept 2");
JTextField dept2field = new JTextField(6);
JLabel dept3 = new JLabel("Dept 3");
JTextField dept3field = new JTextField(6);
JLabel dept4 = new JLabel("Dept 4");
JTextField dept4field = new JTextField(5);
JLabel dept5 = new JLabel("Dept 5");
JTextField dept5field = new JTextField(5);
JButton avg = new JButton("Average");
JButton clr = new JButton("Clear");
JLabel anslab = new JLabel("");
Container c;
FlowLayout flow = new FlowLayout();
public bdrive()
{
setSize(335, 225);
c = getContentPane();
c.setLayout(flow);
c.setBackground(Color.cyan);
title.setFont(insfont);
title.setForeground(Color.blue);
c.add(title);
instruct.setFont(insfont1);
instruct.setForeground(Color.blue);
c.add(instruct);
dept1.setForeground(Color.blue);
c.add(dept1);
dept1field.setForeground(Color.blue);
c.add(dept1field);
dept2.setForeground(Color.blue);
c.add(dept2);
dept2field.setForeground(Color.blue);
c.add(dept2field);
dept3.setForeground(Color.blue);
c.add(dept3);
dept3field.setForeground(Color.blue);
c.add(dept3field);
dept4.setForeground(Color.blue);
c.add(dept4);
dept4field.setForeground(Color.blue);
c.add(dept4field);
dept5.setForeground(Color.blue);
c.add(dept5);
dept5field.setForeground(Color.blue);
c.add(dept5field);
avg.setForeground(Color.blue);
c.add(avg);
clr.setForeground(Color.blue);
c.add(clr);
anslab.setForeground(Color.blue);
c.add(anslab);
dept1field.requestFocus();
dept1field.addActionListener(this);
dept2field.addActionListener(this);
dept3field.addActionListener(this);
dept4field.addActionListener(this);
dept5field.addActionListener(this);
avg.addActionListener(this);
clr.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int d1, d2, d3, d4, d5;
double average;
if(e.getSource() == avg || e.getSource() == dept5field)
{
d1 = Integer.parseInt(dept1field.getText());
d2 = Integer.parseInt(dept2field.getText());
d3 = Integer.parseInt(dept3field.getText());
d4 = Integer.parseInt(dept4field.getText());
d5 = Integer.parseInt(dept5field.getText());
average = ((d1+d2+d3+d4+d5)/5);
anslab.setText("Average pint donated " + average);
}
else if(e.getSource() == clr)
{
dept1field.setText("");
dept2field.setText("");
dept3field.setText("");
dept4field.setText("");
dept5field.setText("");
anslab.setText("");
}
}
public static void main(String[] args)
{
bdrive f = new bdrive();
}
}
@mrspucches
Copy link
Author

mrspucches commented Jun 29, 2018

I need to add some code to make the Average and clear button work, I will do after work today or while at work.

@mrspucches
Copy link
Author

mrspucches commented Jun 29, 2018

Up to date, having an issue with the flow of dept3textfield wrapping to the next line, will fix. Other than that, the application works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment