[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

Table sortin

Asked by Animal11 in Java Programming Language

Tags: sortin, sorted

hi, i have a football league system that allows data to be placed into a jtable, im having trouble sortin the table tho, does any1 know how 2 sort the data first by points then by goal differece n then by goals scored? thanx

first class:


// Game.java

// Java core packages
import javax.swing.JOptionPane;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

// Java exntension packages
import javax.swing.*;
import javax.swing.table.*;

// Beginning of class
public class Menu{
  private Object home;
  private Object away;
  private Object homeScore;
  private Object awayScore;
 
  LeagueTable league = new LeagueTable();
     
  // Array lists
     String mainmenus[] = {"Enter Result", "Display Results", "Display Table", "Exit"};
     String options[] = {"Arsenal", "Everton", "Watford", "Chelsea"};
     String goaloptions[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
     
     JTextArea text = new JTextArea(6,100);
     JFrame frame = new JFrame("Football League Results List");
     
  // set up GUI
     public Menu()
     {
         results_list();
         boolean finish = false;  
         do{
             int mainmenu = JOptionPane.showOptionDialog(null, "Please Select An Option:", "Main Menu", 0, JOptionPane.PLAIN_MESSAGE, null, mainmenus, mainmenus [0]);
             if (mainmenu == 0)
             {
                 //Entering a result
                 home = JOptionPane.showInputDialog(null, "Enter Home Team", "Home Team", 0, null, options, options[0]);
                 homeScore = JOptionPane.showInputDialog(null, "Enter Home Goals", "Home Team", 0, null, goaloptions, goaloptions[0]);
                 away = JOptionPane.showInputDialog(null, "Enter Away Team", "Away Team", 0, null, options, options[0]);
                 awayScore = JOptionPane.showInputDialog(null, "Enter Away Goals", "Away Team", 0, null, goaloptions, goaloptions[0]);
                 
                 if (home != away){
                     league.insertleaguetable ( home,  homeScore,  away,  awayScore);
                     update();
                 }
                 else {JOptionPane.showMessageDialog(null, "Home team and away team can't be the same");}
             }
             
             if (mainmenu == 1)
             {
                 display();
             }
             
             if (mainmenu == 2)
             {
                 LeagueTable league = new LeagueTable();
             }
             
             if (mainmenu == 3)
             {
                 System.exit(0);
             }
         }
         while (finish == false);
     }
     
     public void results_list()
     {
         text.append("Home Team  Goals      Away Team  Goals\n");
     }
     
     public void update()
     {
         text.append(home.toString());
         text.append("               ");
         text.append(homeScore.toString());  
         text.append("           ");
         text.append(away.toString());
         text.append("             ");
         text.append(awayScore.toString());
         text.append("\n");
     }
     
     public void display()
     {
         frame.getContentPane().add(BorderLayout.CENTER, text);
         
         // Exit application when frame is closed
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
         frame.setSize(350,500);
         frame.setVisible(true);
     }
     
     public static void main(String args[])
     {
         Menu menu = new Menu();
     }
}
//End of class



second class:



// LeagueTable.java

// Java core packages
import java.awt.*;
import java.awt.event.*;

// Java exntension packages
import javax.swing.*;
import javax.swing.table.*;

public class LeagueTable extends JFrame{
  //Constructs the JTable and displays automatically
 
  private DefaultTableModel footballTeams;
  private JTable table;
 
  // LeagueTable constructor
  public LeagueTable() {
      super("Football League Table");
      initTable();
     
      // create a JTable for footballTeams DefaultTableModel
      table = new JTable(footballTeams);
     
      // layout GUI components
      Container container = getContentPane();
      container.add(new JScrollPane(table), BorderLayout.CENTER);
     
      setSize(500,300);
      setDefaultCloseOperation(EXIT_ON_CLOSE);  
      setVisible(true);
  }
  // end of LeagueTable constructor
 
  private void initTable() {
     
      //TableSorter sorter = new TableSorter(aTableModel);
      //initTable.setModel(sorter);
      //sorter.addMouseListenerToHeaderInTable(initTable);
     
      //creates a DefaultTableModel to hold the footballTeams records
      footballTeams = new DefaultTableModel();
   
    // add columns to DefaultTableModel
    footballTeams.addColumn(" Name ");
    footballTeams.addColumn( "Played");
    footballTeams.addColumn("Won");
    footballTeams.addColumn("Drawn");
    footballTeams.addColumn("Lost");
    footballTeams.addColumn("For");
    footballTeams.addColumn("Against");
    footballTeams.addColumn("GD");
    footballTeams.addColumn("Pts");
   
    // add names and default data to DefaultTableModel
    String[] arsenal = { "Arsenal", "0", "0", "0", "0", "0", "0", "0", "0"};
    footballTeams.addRow(arsenal);
    String[] everton = { "Everton", "0", "0", "0", "0", "0", "0", "0", "0"};
    footballTeams.addRow(everton);
    String[] watford = { "Watford", "0", "0", "0", "0", "0", "0", "0", "0"};
    footballTeams.addRow(watford);
    String[] chelsea = { "Chelsea", "0", "0", "0", "0", "0", "0", "0", "0"};
    footballTeams.addRow(chelsea);
  }
 
  //Inserts data in to the table in the correct place
  public void insertleaguetable(Object home, Object homeScore, Object away, Object awayScore)
  {
      String homeTeam = home.toString();
      int homeGoals = Integer.parseInt(homeScore.toString());
      String awayTeam = away.toString();
      int awayGoals = Integer.parseInt(awayScore.toString());
      for(int i=0; i<4; i++){
         
      if (home == footballTeams.getValueAt(i, 0)){

          int played = Integer.parseInt(footballTeams.getValueAt(i, 1).toString());
          footballTeams.setValueAt(new Integer(played + 1), i, 1);
         
          int won = Integer.parseInt(footballTeams.getValueAt(i, 2).toString());
          int points = Integer.parseInt(footballTeams.getValueAt(i, 8).toString());
         
          int goalsFor = Integer.parseInt(footballTeams.getValueAt(i, 5).toString());
          footballTeams.setValueAt(new Integer(goalsFor + homeGoals), i, 5);
          int goalsAgainst = Integer.parseInt(footballTeams.getValueAt(i, 6).toString());
          footballTeams.setValueAt(new Integer(goalsAgainst + awayGoals), i, 6);
          int gD = Integer.parseInt(footballTeams.getValueAt(i, 7).toString());
          footballTeams.setValueAt(new Integer(gD + homeGoals - awayGoals), i, 7);
         
          if (homeGoals > awayGoals) {
          footballTeams.setValueAt(new Integer(won + 1), i, 2);
          footballTeams.setValueAt(new Integer(points + 3), i, 8);
          }
          int scoredraw = Integer.parseInt(footballTeams.getValueAt(i, 3).toString());
          if (homeGoals == awayGoals && homeGoals !=0 && awayGoals !=0) {
          footballTeams.setValueAt(new Integer(scoredraw + 1), i, 3);
          footballTeams.setValueAt(new Integer(points + 2), i, 8);
          }
          int draw = Integer.parseInt(footballTeams.getValueAt(i, 3).toString());
          if (homeGoals == awayGoals && homeGoals ==0 && awayGoals == 0) {
          footballTeams.setValueAt(new Integer(draw + 1), i, 3);
          footballTeams.setValueAt(new Integer(points + 1), i, 8);
          }
          int lost = Integer.parseInt(footballTeams.getValueAt(i, 4).toString());
          if (homeGoals < awayGoals) {
          footballTeams.setValueAt(new Integer(lost + 1), i, 4);
          }
      }
     
      if (away == footballTeams.getValueAt(i, 0)){
         
          int points = Integer.parseInt(footballTeams.getValueAt(i, 8).toString());
             
          int played = Integer.parseInt(footballTeams.getValueAt(i, 1).toString());
          footballTeams.setValueAt(new Integer(played + 1), i, 1);

          int goalsFor = Integer.parseInt(footballTeams.getValueAt(i, 5).toString());
          footballTeams.setValueAt(new Integer(goalsFor + awayGoals), i, 5);
          int goalsAgainst = Integer.parseInt(footballTeams.getValueAt(i, 6).toString());
          footballTeams.setValueAt(new Integer(goalsAgainst + homeGoals), i, 6);
          int gD = Integer.parseInt(footballTeams.getValueAt(i, 7).toString());
          footballTeams.setValueAt(new Integer(gD + awayGoals - homeGoals), i, 7);
         
          int won = Integer.parseInt(footballTeams.getValueAt(i, 2).toString());
          if (homeGoals < awayGoals) {
          footballTeams.setValueAt(new Integer(won + 1), i, 2);
          footballTeams.setValueAt(new Integer(points + 3), i, 8);
          }
       
          int scoredraw = Integer.parseInt(footballTeams.getValueAt(i, 3).toString());
          if (homeGoals == awayGoals && homeGoals !=0 && awayGoals !=0) {
          footballTeams.setValueAt(new Integer(scoredraw + 1), i, 3);
          footballTeams.setValueAt(new Integer(points + 2), i, 8);
         
   }
          int draw = Integer.parseInt(footballTeams.getValueAt(i, 3).toString());
          if (homeGoals == awayGoals && homeGoals ==0 && awayGoals == 0) {
          footballTeams.setValueAt(new Integer(draw + 1), i, 3);
          footballTeams.setValueAt(new Integer(points + 1), i, 8);
   }
          int lost = Integer.parseInt(footballTeams.getValueAt(i, 4).toString());
          if (homeGoals > awayGoals) {
          footballTeams.setValueAt(new Integer(lost + 1), i, 4);
          }
          }
      }
  }
}
[+][-]03/25/04 03:46 PM, ID: 10682900Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 03:53 PM, ID: 10682950Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 03:54 PM, ID: 10682955Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 03:58 PM, ID: 10682982Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/25/04 03:59 PM, ID: 10682990Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Java Programming Language
Tags: sortin, sorted
Sign Up Now!
Solution Provided By: objects
Participating Experts: 3
Solution Grade: A
 
[+][-]03/25/04 04:09 PM, ID: 10683057Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 04:17 PM, ID: 10683100Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/25/04 04:19 PM, ID: 10683107Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 04:21 PM, ID: 10683125Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 04:25 PM, ID: 10683148Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 04:38 PM, ID: 10683195Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/25/04 04:44 PM, ID: 10683219Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/04 05:31 PM, ID: 10683413Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/25/04 06:37 PM, ID: 10683685Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03/25/04 06:46 PM, ID: 10683737Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/26/04 02:44 AM, ID: 10685846Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/29/04 01:17 PM, ID: 10708081Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/21/04 06:50 AM, ID: 10878239Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/21/04 07:00 AM, ID: 10878350Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/23/04 01:43 AM, ID: 10897369Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/23/04 02:04 AM, ID: 10897476Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/23/04 02:36 AM, ID: 10897647Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/23/04 02:49 AM, ID: 10897703Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/25/04 10:07 PM, ID: 10915507Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81