- #1
Santa_Laws
- 1
- 0
Build a GUI to accept integers (when the ENTER key is depressed) into an arr
ay of 15 int; have a button called AVERAGE; when AVERAGE is selected, there
is a display of the count and the current average; have a button called CLEA
R; when CLEAR is selected, count is set to 0 and so are all the array elemen
ts and then there is another display: count is 0 and average is 0.0.
package argui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ArrayGUIPanel extends JPanel
{
private JLabel inputLabel, outputLabel, resultLabel, countLabel, averageL
abel;
private JTextField nums;
private JButton average, clear;
private int count;
private double avg;
//-----------------------------------------------------------------
// Constructor: Sets up the main GUI components.
//-----------------------------------------------------------------
public ArrayGUIPanel()
{
count = 0;
avg=0.0;
inputLabel = new JLabel ("Enter integers: " );
resultLabel = new JLabel ("---");
countLabel = new JLabel ("Count: " + count);
averageLabel = new JLabel ("Average: " + avg);
average = new JButton ("AVERAGE");
clear = new JButton ("CLEAR");
AvgListener listener = new AvgListener();
average.addActionListener (listener);
clear.addActionListener(listener);
add (inputLabel);
add (average);
add (clear);
add (resultLabel);
add (countLabel);
add (averageLabel);
setPreferredSize (new Dimension(300, 75));
setBackground (Color.white);
}
am i going right direction here?
ay of 15 int; have a button called AVERAGE; when AVERAGE is selected, there
is a display of the count and the current average; have a button called CLEA
R; when CLEAR is selected, count is set to 0 and so are all the array elemen
ts and then there is another display: count is 0 and average is 0.0.
package argui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ArrayGUIPanel extends JPanel
{
private JLabel inputLabel, outputLabel, resultLabel, countLabel, averageL
abel;
private JTextField nums;
private JButton average, clear;
private int count;
private double avg;
//-----------------------------------------------------------------
// Constructor: Sets up the main GUI components.
//-----------------------------------------------------------------
public ArrayGUIPanel()
{
count = 0;
avg=0.0;
inputLabel = new JLabel ("Enter integers: " );
resultLabel = new JLabel ("---");
countLabel = new JLabel ("Count: " + count);
averageLabel = new JLabel ("Average: " + avg);
average = new JButton ("AVERAGE");
clear = new JButton ("CLEAR");
AvgListener listener = new AvgListener();
average.addActionListener (listener);
clear.addActionListener(listener);
add (inputLabel);
add (average);
add (clear);
add (resultLabel);
add (countLabel);
add (averageLabel);
setPreferredSize (new Dimension(300, 75));
setBackground (Color.white);
}
am i going right direction here?