'Lo everyone, I am having some pretty frustrating issues that I can not seem to get rid of.
The main goal of my program is to make a GUI with buttons that trigger custom events.
C:\Java Tests>javac JGUITest.java
JGUITest.java:13: cannot find symbol
symbol : class ButtonHandler
location: class LabelFrame
private ButtonHandler handler = new ButtonHandler();
^
JGUITest.java:13: cannot find symbol
symbol : class ButtonHandler
location: class LabelFrame
private ButtonHandler handler = new ButtonHandler();
^
JGUITest.java:18: call to super must be first statement in constructor
super("Testing Event Capturing");
^
JGUITest.java:70: cannot find symbol
symbol : constructor JList(int[])
location: class javax.swing.JList
jList1 = new JList(intArray);
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.util.EventObject;
class LabelFrame extends JFrame
{
private JButton newNumber;
private JButton dispAll;
private JButton totalNumber;
private ButtonHandler handler = new ButtonHandler();
public void LabelFrame()
{
super("Testing Event Capturing");
setLayout(new FlowLayout());
Icon testIcon2 = new ImageIcon(getClass().getResource("icon_test2"));
Icon testIcon3 = new ImageIcon(getClass().getResource("icon_test3"));
Icon testIcon4 = new ImageIcon(getClass().getResource("icon_test4"));
newNumber = new JButton("New Number", testIcon2);
add(newNumber);
dispAll = new JButton("Display All Numbers", testIcon3);
add(dispAll);
totalNumber = new JButton("Total All Numbers",testIcon4);
add(totalNumber);
newNumber.addActionListener(handler);
dispAll.addActionListener(handler);
totalNumber.addActionListener(handler);
}
}
class custEvents
{
int[] intArray = {0,0,0,0,0,0,0,0,0,0};
int total;
JList jList1;
public void addNumber()
{
if (intArray[9] != 0)
{
for (int i = 0; i < intArray.length; i++)
{
if (intArray[i] == 0)
{
String uInput = JOptionPane.showInputDialog("Please enter a number");
intArray[i] = Integer.parseInt(uInput);
i = 10;
}
}
}
else
{
JOptionPane.showMessageDialog(null,"The number array is full! (10)", "WARNING!",JOptionPane.PLAIN_MESSAGE);
}
}
public void displayNumbers()
{
jList1 = new JList(intArray);
jList1.setVisibleRowCount(10);
//JOptionPane.showMessageDialog(null,JList1.setVisible(true),"List of Numbers",JOptionPane.PLAIN_MESSAGE);
JFrame newFrame = new JFrame("List of Numbers");
JPanel newPanel = new JPanel();
newPanel.add(jList1);
newFrame.add(newPanel);
newFrame.setSize(400,400);
newFrame.setVisible(true);
}
public void addNumbers()
{
total = 0;
for (int i = 0; i < intArray.length; i++)
{
if (intArray[i] == 0)
{
i = 10;
}
else
{
total += intArray[i];
}
}
JOptionPane.showMessageDialog(null,"The sum of the numbers in the array are " + total,"Sum of Array",JOptionPane.PLAIN_MESSAGE);
total = 0;
}
public void error()
{
JOptionPane.showMessageDialog(null,"Message not detected or not sent!!!","ERROR",JOptionPane.PLAIN_MESSAGE);
}
}
class custListener
{
custEvents cEvents = new custEvents();
public void actionPreformed(ActionEvent cust)
{
if ((cust.getActionCommand()) .equals ("newNumber"))
{
cEvents.addNumber();
}
else if ((cust.getActionCommand()) .equals ("dispAll"))
{
cEvents.displayNumbers();
}
else if ((cust.getActionCommand()) .equals ("totalNumber"))
{
cEvents.addNumbers();
}
else
{
cEvents.error();
}
}
}
public class JGUITest
{
public static void main (String args[])
{
LabelFrame newFrame = new LabelFrame();
newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFrame.setSize(600,600);
newFrame.setVisible(true);
}
}