NEED HELP with project, uses GUI.
Here's the coding first of all:
Code:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Scanner;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class collegefinal extends JFrame
{
public collegefinal()
{
////////////////////CREATES BUTTONS///////////////////////////////////////////////////////
JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
JButton Help = new JButton("HELP");
JButton SetP = new JButton("SET PARAMETERS");
JButton Fill = new JButton("FILL ARRAY");
JButton Disp = new JButton("DISPLAY RESULTS");
JButton Quit = new JButton("QUIT");
///////////////////CREATES DESCRIPTIONS FOR BUTTONS//////////////////////////////////////
Help.setToolTipText("Displays Instructions on how to use this program.");
SetP.setToolTipText("Promps user for number of students and quizzes.");
Fill.setToolTipText("Inserts Values pre-set in SET PAREMETERS.");
Disp.setToolTipText("Displays the Results");
Quit.setToolTipText("Close Program");
////////////////////ADDS BUTTONS TO JFRAME/////////////////////////////////////////////////
p1.add(Help);
p1.add(SetP);
p1.add(Fill);
p1.add(Disp);
p1.add(Quit);
p1.setBorder(new TitledBorder( "Grade Compiling Program"));
////////////////////ADJUSTS THE FONT AND BORDER OPTIONS FOR JFRAME/////////////////////////
Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
Border lineBorder = new LineBorder(Color.BLACK, 2);
////////////////////ADDS ALL OF THE ABOVE INTO GUI FIELD//////////////////////////////////
add(p1);
///////////////////REGISTERS EVENT LISTENERS WITH ALL 5 BUTTONS///////////////////////////
Help.addActionListener(new HelpButtonListener());
SetP.addActionListener(new SetPButtonListener());
Fill.addActionListener(new FillButtonListener());
Disp.addActionListener(new DispButtonListener());
Quit.addActionListener(new QuitButtonListener());
}
public static void main(String[] args)
{
///////////////////CREATES JFRAME AND PAREMETERS FOR JFRAME/////////////////////////////
JFrame frame = new collegefinal();
frame.setTitle("College Final Project");
frame.setSize(750, 500);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
///////////////////PROGRAMMING FOR WHEN THE "HELP BUTTON" IS PRESSED////////////////////
private class HelpButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println();
String output = "\n______________________HELP MENU__________________________" +///This is the output that will be diplayed when the HELP button is pressed
"\n Welcome to the Help Menu, here you will find tips to using this program." +
"\n" +
"\n The first step is to click the 'SET PARAMETERS' button. Here you will " +
"\n input the number of students (up to 50) and number of quizzes for each " +
"\n student (up to 5.) " +
"\n " +
"\n Next you will select the 'FILL ARRAY' button. This button will open up" +
"\n the menu to select the ID numbers and quiz grades for each student and " +
"\n quiz, then store them within the paremeters set in 'SET PARAMETERS'." +
"\n " +
"\n Finally you will click the 'DISPLAY' button. This button will compile all" +
"\n the data you entered in the last two sections and display the results." +
"\n This program computes and displays the lowest, highest, average, and" +
"\n medium for each grade of each set of quizzes." +
"\n " +
"\n As an added note if you wish to quit this program at any time, simply" +
"\n press the 'QUIT' button and the program will close";
JOptionPane.showMessageDialog(null,output); //Dispays the above information for the user in a seperate window that closes when OK is pressed.
}
}
///////////////////PROGRAMMING FOR WHEN THE "SET PARAMETERS BUTTON" IS PRESSED////////////////////
private class SetPButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String studentString = JOptionPane.showInputDialog("Enter number of students (up to 50)");
int student = Integer.parseInt(studentString);
String numString = JOptionPane.showInputDialog("Enter number of quizzes for each student (up to 5)");
int num = Integer.parseInt(numString);
}
}
///////////////////PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED//////////////
private class FillButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int[][] quizzes = new int[student][num];
}
}
///////////////////PROGRAMMING FOR WHEN THE "DISPLAY BUTTON" IS PRESSED//////////////////
private class DispButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
///////////////////PROGRAMMING FOR WHEN THE "QUIT BUTTON" IS PRESSED////////////////////
private class QuitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
}
It's pretty simple, click a button to make parameters for an array, then press another to input data into that array based on the parameters. The issue I am having is getting the input variables from SetPButtonListener and keeping them while I execute the programming in FillButton Listener.
I tried using "implements" and such, but that would cause the reptition of the SetP programming when I pressed the Fill Array button.
I've spent all night trying to figure this out, I'm really lost.
In case I'm being a little confusing in my requst (confusing myself at least)
I need to take the parameters I input via dialogue box in SetPButtonListener and somehow be able to keep and use them in FillButtonListener
If that makes any sense.
Advice would be appreciate.