these are all the classes and methods and what not (super14 is a rugby tornament in newzealand i want it so i can display the program in a gui by clicking a button and displaying one of the methods output in a jTextArea.
i have created an action listener for a button and there is a jTextArea aswell i just dont know what to write in the button actionlistner area to make a methods output go into the textarea. look for this im assuming you can search for keywords but this is where im having trouble "TROUBLE IS HERE"
Super14. java
package psuper14;
/**
*
* @author Brad
*/
public class Super14
{
String date,team1,team2,location,time;
int score1,score2;
/**constructor sets all data values for each team*/
public Super14(String date,String team1,String team2,String location, String time,int score1,int score2)
{
this.date = date;
this.location = location;
this.score1 = score1;
this.score2 = score2;
this.team1 = team1;
this.team2 = team2;
this.time = time;
}
/**Returns all data for one game*/
public String toString()
{
return "date: "+date+". "+team1+" vs. "+team2+". time: "+time+". location: "+location+" score: "+score1+"-"+score2+".\n";
}
}
Super14App
package psuper14;
import java.io.*;
/**
*
* @author Brad
*/
public class Super14App
{
public static void main(String[] args)
{
Super14[] myTeam = new Super14[93];
//Super14 myTeam = new Super14("10-May","Blues","Hurricanes","Auckland","7.35pm",19,37);
//System.out.println(myTeam.toString());
int count = 0;
String line = "";
try
{
BufferedReader in = new BufferedReader(new FileReader("super14.csv"));
while (((line = in.readLine()) != null) && (count<93))
{String[] fields = line.split(",");
String date = fields[0];
String team1 = fields[1];
String team2 = fields[2];
String location = fields[3];
String time = fields[4];
int score1 = Integer.parseInt(fields[5]);
int score2 = Integer.parseInt(fields[6]);
myTeam[count] = new Super14(date,team1,team2,location,time,score1,score2);
count++;
}
}
catch (IOException e)
{
System.out.println("There was a problem with the file");
e.printStackTrace();
}
SuperMethods worker = new SuperMethods();
System.out.println(worker.Max(myTeam));
System.out.println(worker.trysScored(myTeam));
worker.scoreSort(myTeam);
for (count=0;count<myTeam.length;count++){
System.out.println(myTeam[count].score1);
}
}
}
Super14Methods
package psuper14;
/**
*
* @author KAYB2
*/
public class SuperMethods {
/**Finds highest score and returns to screen*/
public String Max(Super14[] myTeam) {
int max=0, count;//initializing variables
for(count=0;count<myTeam.length;count++)//loop to sort through score1 to find higest score
{
if (myTeam[count].score1>max)
{
max=myTeam[count].score1;
}
}
for(count=0;count<myTeam.length;count++)//loop to sort through score2 to find higest score
{
if (myTeam[count].score2>max)
{
max=myTeam[count].score2;
}
}
count = 0;
while((max!=myTeam[count].score1)&&(max!=myTeam[count].score2))
{
count++;
//System.out.println(max);
}
return myTeam[count].toString()+"\nThe above team had the highest score in a single match \n";
}
/**Method trysScored adds up total points from the season and divides
result by five returning total trys scored throughout season by all teams*/
public String trysScored(Super14[] myTeam)
{
int count = 0;
int count2 = 0;
int points1 = 0;
int points2 = 0;
int result = 0;
for(count=0;count<myTeam.length;count++)
{
points1 = points1+myTeam[count].score1;
}
for(count2=0;count2<myTeam.length;count2++)
{
points2 = points2+myTeam[count2].score2;
}
result = points1+points2;
result = result/5;
return result+" Trys were score throughout the season";
}
/**Method scoreSort sorts the points into order from smallest to largest
and returns to output*/
public void scoreSort(Super14[] myTeam)
{
int i,j, temp = 0;
for(i=0; i><myTeam.length-1; i++)
{
for(j=0; j><(myTeam.length-1)-i; j++)
{
if (myTeam[j].score1>myTeam[j+1].score1)
{
temp=myTeam[j+1].score1;
myTeam[j+1].score1=myTeam[j].score1;
myTeam[j].score1=temp;
}
}
}
}
}
Super14GUI
package psuper14;
/**
*
* @author KAYB2
*/
public class Super14GUI extends javax.swing.JApplet {
/** Initializes the applet Super14GUI */
public void init()
{
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("trys scored");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("exit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2)
.addComponent(jButton1))
.addContainerGap(14, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jButton1)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(49, 49, 49))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(45, Short.MAX_VALUE))
);
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
SuperMethods worker = new SuperMethods();
jTextArea1.add(System.out.println(worker.trysScored((Super14[]) myTeam)));
String input = jTextArea1.getText().trim();
//if input is integer or double then use Integer.parseInt()
jTextArea1.setText(input);
/**TROUBLE IS HERE what do i type in here to call the method trysScored and make its output go to jTextArea1*/
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
private Object myTeam;
}