BestJewSinceJC 700 Posting Maven

I have no problem with posting more code, but I don't see how anyone could possibly sift through all of it. Over the past 6 months I have pretty much lived on Java Sun's tutorials, so I've been trying to follow their examples as closely as possible. I thought that the other problem my user experienced with her Teams disappearing might be some kind of memory inconsistency error, but I looked at all of my code for a few more hours, THEN I checked to make sure everything was scheduled on the Event Dispatch Thread, and it all is. Is this practice of having everything on the EDT wrong? Because Java Sun says the only problem that can occur with that is 'freezing' or non-responsiveness of the GUI, but I have not experienced that at all, so I haven't created any worker threads.

Also, one more question: how should I go about updating my JTable after a Game is deleted? I was using frame.dispose and then simply re-creating the entire window, but this seems to cause problems?


Also, if the problem you were describing above was really the problem, one would expect that there would be consistency: such as the GUI always displaying a certain number of times. There is no consistency - sometimes it displays once, sometimes twice, sometimes 5 times.

BestJewSinceJC 700 Posting Maven

I'm 99.9% sure this isn't the case, having checked myself numerous times, but I will paste the code anyway.

The actionPerformed method where the GUI is called:

public void actionPerformed(ActionEvent ae){
	  Object source = (JButton)ae.getSource();
	  if (source == viewStats){
		  int row = -1;
		  int[] allrows = table.getSelectedRows();
		  if (allrows.length != 0)
		  row = allrows[0];
		  
		  if (allrows.length == 0 || row == -1 || row < 0 || row > Matchups.allTeams.size()){
			  return;
		  }
		  else{
			  String name = (String)table.getValueAt(row, 0);
			  for (int i = 0; i < Matchups.allTeams.size(); i++){
				  if (Matchups.allTeams.get(i).name.equals(name)){
					  DisplayTeamsPlayed.setTeam(Matchups.allTeams.get(i));
					  DisplayTeamsPlayed.main(new String[0]); 
				  return;
				  }
			  }
		  }
	  }

The line where it says DisplayTeamsPlayed.setTeam passes in a 'Team' as an argument, and sets the static variable Team in DisplayTeamsPlayed to the argument that was passed in. When DisplayTeamsPlayed.main() is called, it creates a JTable which consists of a list of all the 'Games' (another object) that the Team (the static variable I described earlier) has played. In main, a new Runnable() is created and then createAndShowGUI, shown below, is called.

public static void createAndShowGUI(){
		frame = new JFrame("Matches the team \"" + team.name + "\" has played:");
		frame.setSize(550, 600);
		frame.setLocation(200, 100);
		frame.setUndecorated(true);
		frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      
		//Add contents to the window.
		frame.add(new DisplayTeamsPlayed(team));
   
		//Display the window.
		frame.setVisible(true);
	}

The DisplayTeamsPlayed constructor that is called from createAndShowGUI:

public DisplayTeamsPlayed(Team getStats){
	  super();
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	print.addActionListener(this);
	deleteGame.addActionListener(this);
    int index = Matchups.allTeams.indexOf(getStats);
    int rows = Matchups.allTeams.get(index).gamesPlayed.size(); 
    int columns = 6;
    String data[][] = new String[rows][columns];
    String col[] = {"Team Played", "Your score", …
BestJewSinceJC 700 Posting Maven

if you register your JButtons like this

buttonName.addActionListener(this);

then they will fire an event when they are clicked. Also, you will need for your class to implement ActionListener. In the method actionPerfmored, do something likr

Object source = e.getSource(); // where e is the ActionEvent object being passed in. And then have a bunch of if statements like if (buttonName == source){ //do something}


...

BestJewSinceJC 700 Posting Maven

All I can think is that there's something fundamentally wrong with how I programmed my GUIs. I have a program that initially displays a GUI which has 6 buttons. Each of these buttons, when clicked, displays a GUI. One of these GUIs in particular is a JTable of "Teams". Each of these Teams has "Games played". You can click on the Team and click a button, "Display Games", to pop open another GUI that shows what games the team has played. When the user clicks "display games", anywhere from 1-7 copies of the SAME GUI are being displayed. In addition, when the user 'deletes' the games from the GUI (if he/she entered a game by accident) the number of times the program attempts to delete the game = the number of copies of the GUI that popped up. This happens despite the user only clicking "delete game" once. Everything in my program is scheduled on the Event Dispatch Thread. Java Sun says that the EDT for displaying GUIs and Worker Threads (for more time intensive tasks) are recommended.

I have spent over 75 hours building this GUI, all the background code/code that runs when the user makes entries is what I want it to be. I seem to be having problems with my GUIs though, I'm not sure exactly what the problems are. One of my users has complained that her Teams were completely lost, despite her not telling the GUI to 'delete' any of them. This seems like …

BestJewSinceJC 700 Posting Maven

Also, I could be wrong, but it seems like you never set duplicate back to false. You will need to do that, otherwise once it is set to true, everything in your file will be treated like it is a duplicate.

BestJewSinceJC 700 Posting Maven

Your question is very confusing. Here is an example of how to set up a Socket, which is one end of a connection/pipeline to send stuff back and forth, basically. If you want the client to be on your own computer, then it would be 'localhost'. Otherwise, the String hostname would be set to the web address of wherever.


int port = 1235;
String hostname = "localhost";
Socket connectionSock = new Socket(hostname, port);
out = new ObjectOutputStream(connectionSock.getOutputStream());
in = new ObjectInputStream(connectionSock.getInputStream());


Also, google 'Java Socket' and 'Java ServerSocket'

BestJewSinceJC 700 Posting Maven

What is your question? You didn't specify any portion of the code that you want us to look at. Do you just want us to give you random number generating techniques in general, because for that, you can use google.