Inheritance, class types, and possibly some more where that came from

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 864 Views - Last Post: 27 January 2013 - 06:32 AM Rate Topic: -----

#16 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Inheritance, class types, and possibly some more where that came from

Posted 16 January 2013 - 04:52 AM

Yes you can call actionPerformed() directly if it is not an anonymous class
In your case where you have only one button and you don't use the ActionEvent you can simp;ly pass null as ActionEvent

The JButton class has also a doClick() class that simnulates a click in the JButton which will fired the actionPerformed()

For the paintComponent() you can always added the paintComponent at the JPanel creation but I think this is horrible code practice to add execution code in a constructor. Then you can call repaint() in your panel. You cannot just invent a Graphics object as you do and call directly paintComponent().

     	    panel = new JPanel() {
	    	public void paintComponent(Graphics g) {
	    	   // code	
	    	}
	    };
        }

        panels[0].repaint();


Was This Post Helpful? 1
  • +
  • -

#17 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 186
  • Joined: 28-August 12

Re: Inheritance, class types, and possibly some more where that came from

Posted 17 January 2013 - 06:36 PM

Oh, and also I have heard from both my Java textbook and my professor that you can write an entire object to a class (object serialization). I also heard that this was a basic in Java. However, when I did some research on it, it seems like a "sketchy" idea. Yes, I could, in essence make an object containing all the data from beta-tests, but if it is as these guys, http://www.ibm.com/d...ngs1/index.html , say it, I would also have to look into how to SECURE such data...

EDIT: I know I could use the algorithm talked about in that document (Wikipedia mentions it as a popular algorithm in digital cryptography), but the article itself was talking about more secure algorithms.

This post has been edited by IceHot: 17 January 2013 - 07:34 PM

Was This Post Helpful? 0
  • +
  • -

#18 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Inheritance, class types, and possibly some more where that came from

Posted 17 January 2013 - 07:42 PM

And the question is ?
Unless you work for the CIA, the DEA, the FBI, the Canadian CRS, the MI5, Tsahal or the Deuxieme Bureau don't over-paranoid over that article and ignore it.
Was This Post Helpful? 1
  • +
  • -

#19 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 186
  • Joined: 28-August 12

Re: Inheritance, class types, and possibly some more where that came from

Posted 18 January 2013 - 09:39 PM

Thanks for this advice! By the way, I found a simple data encryption algorithm, so it won't be a problem. I should just focus on learning more about object serialization so I can finish this game!
Was This Post Helpful? 0
  • +
  • -

#20 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 186
  • Joined: 28-August 12

Re: Inheritance, class types, and possibly some more where that came from

Posted 21 January 2013 - 04:16 PM

EDIT: Now that I think about it, I do have a legitimate question, about JTables. I read through the documentation, and there doesn't seem to be a way to make them uneditable. This is important because I will most likely get feedback about the beta-test by having the beta-testers send me screenshots of their progress. I was thinking JTables would be the answer because it would have allowed me to let the user see detailed feedback about their game history. This detail would, in turn, help me by assessing the true difficulty of each game mode. I am getting quite good at my Human Calculator difficulty, and as consequence, sometimes fail to see the difficulties of other players. Hence, the primary reason for the test.

This post has been edited by IceHot: 22 January 2013 - 01:23 AM

Was This Post Helpful? 0
  • +
  • -

#21 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 186
  • Joined: 28-August 12

Re: Inheritance, class types, and possibly some more where that came from

Posted 25 January 2013 - 02:24 AM

Oh, and does EVERY FREAKING DATA MEMBER IN THE JTable need to be an Object?
Was This Post Helpful? 0
  • +
  • -

#22 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 186
  • Joined: 28-August 12

Re: Inheritance, class types, and possibly some more where that came from

Posted 27 January 2013 - 06:32 AM

My questions just don't seem to end. These seem to be all, essentially, data problems, either directly or indirectly. I stumbled upon the answer to my above question: yes, they all need to be Objects (my guess is that the people at Sun Microsystems want the developer to use Objects (the whole initial motivation for Java!) and that forcing everything to be an Object will make for smoother Table design because you can just use a two-dimensional array to store the data. Also, I found out that the data is all row-based data (which forces me to, in my case declare more heap memory, which is going to make my program slower...), but I think their motivation for that is that JTables are oftentimes used to manipulate databases, and a row-data-format is best used for that purpose. Oh, and I also found out that it is possible to make a JTable uneditable; you just need to call the constructor with the AbstractTableModel as the sole argument. (In my case, I capitalized on that and just made a new class file that extends this AbstractTableModel, and just called the class.)

All that stuff being aside, I have a few questions/concerns. First, I have a way to convert time in long format to a String "hh:mm:ss" format. The problem is that I have it in the Game.java, and I need it in the class that is the AbstractTableModel. I might also need a method like this in the future, which leaves me with three options:

1.) Packaging it and importing the package. This is a concept that I don't understand with Java, and
I would need some questions answered before I go doing this, like "Can I still use the default package for this MathReflexesGame project?"
2.) Defining it in the MathReflexesGame.java file and making EVERY FREAKING CLASS A SUBCLASS OF THIS FILE. This option would leave me having to rewrite EVERY LAST FREAKING CLASS.
3.) Rewriting it every time I need to use it (us programmers already know that this is the WORST option).
4.) Making it a separate class, putting the code into that class, and just calling that Object every time I need to use it. This seems like a quick easy fix, but again, this will cost me in terms of execution speed. Also, being predominantly a C++ programmer, I don't know how much heap data the JVM could handle.

I know that, if you have gotten this far in the text, you are probably thinking "You seem to know the best option." or "We are not here to do your work for you." I know that you are not here to make the decisions for me; I am simply asking for input (this is because I know that programmers are like martial artists in the sense that they have a distinct sense of strategy/style).

Also, I was wondering if using Eclipse IDE (I know that it is simply the sum of all the resources you need to make a Java program) to make an executable JAR file would be the best way to make a stand-alone executable. I now know that a JAR is simply a ZIP++, which leads me to asking this question. (The last thing I would want is someone who is running Linux to be able to unzip the JAR, access what's inside, and reverse-engineer my program. That would be a nightmare in-the-making.)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2