Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>I think there's no one right answer here.
Bingo.
This is the point where design becomes more art than science and you don't really have a set of rules laid out for you. You try to encapsulate functionality and decouple responsibility as best you can given the specifics of your subsystems and requirements. Managing that complexity effectively becomes a career.

Salem commented: Well said, and very true. +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This

java.lang.ArrayIndexOutOfBoundsException: 1

means your code tried to access element index 1 of an array that has less than 2 elements.

This line

HighScoreManager.readHighScores(HighScoreManager.java:22)

shows that it occurred on line 22 of HighScoreManager in the readHighScores method.
So check your array access there.

jollyton12 commented: thanks +3
stephen84s commented: Short and bang on target as usual. +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

localhost/aldo/index.php should suffice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'mo going to come clean here: I don't think that separation of the controller and the view works well in a typical Swing app, and I personally rarely do it. The controller needs so much access to the fields in the view that the code is far simpler when they are in the same class.

I agree. It's pretty much just model and view in most cases.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That would be Glenn Beck and GrimJack brought him up.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, thanks James, that's a good point to mention on the asynchronous update. It definitely adds some concurrency concerns which need to be weighed against any perceived performance gains.

I should probably clarify that I didn't link the article in a sense of "here's an even better way to do it" so much as here's another example that goes even further - and it has diagrams! :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I had nut-job Beck stupidity like this: http://www.youtube.com/watch?v=rM4xqnukQrM&feature=related
and this: http://www.youtube.com/watch?v=ex695VSHmSs&feature=related
more in mind...
Loser is still apt though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are very close there: int[][] apostas = new int[n][7]; You want 'n' elements that each contain an array of 7 elements. Your outer loop for(int i=0;i<n;i++) then denotes that first dimension, so aposta[i]=geraAposta();

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
public int compareTo(E other){
  // return negative int if this object less than "other"
  // etc... 
}

The generics pretty much just alleviate the need for you to cast "other" to your class type before comparing. "other" is already an object of that type and can be used directly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, Beck has really gone off the deep end lately so I wouldn't pay much attention anything he was screaming at this point.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A class that implements Comparable actually says that in it's declaration

class Blah<E> implements Comparable<E> {

and implements the compareTo() method as required by that interface: http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html#compareTo(T)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm not certain if I understand what you are trying to do exactly, but perhaps it is this: http://faq.javaranch.com/java/BackgroundImageOnJPanel ?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, your class doesn't actually implement Comparable and your syntax in the declaration of the comp() method is a bit off. Perhaps looking over this article on generic types which shows a Comparable implementation would help: http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index1.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to glance through this article as well, which shows a simple pattern of even further separating the observers from the observed with a message queue on a separate thread: http://www.javaworld.com/javaworld/javatips/jw-javatip29.html

It's probably overkill for what you have in mind, but it does present another example of separating the state of one thing from other things that may want to observe and react to that state.

(And it has pictures, which my plain example does not :P )

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's the simplest example I can piece together of a listener (which is an observer). You've used it quite a bit in Swing and I'm sure you will recognize the elements immediately

import java.util.ArrayList;
import java.util.List;

public class mainTest {

    public static void main(String[] args) {
        Model model = new Model();
        View view = new View();

        /** add the view as a listener */
        model.addListener(view);

        /** do something to the model */
        model.updateSomething();
    }
}

class Model {
    /** list of interested listeners (observers, same thing) */
    List<ModelListener> listeners = new ArrayList<ModelListener>();

    /** add a new ModelListener observer for this Model */
    public void addListener(ModelListener listener) {
        listeners.add(listener);
    }

    /** called internally when you need to tell the observer stuff changed */
    private void fireStuffChanged() {
        for (ModelListener listener : listeners) {
            listener.stuffChanged();
        }
    }

    /** method that results in a change in the model */
    public void updateSomething() {
        // do whatever
        System.out.println("Model: I'm changin stuff in here...");
        // notify observers
        fireStuffChanged();
    }
}

/** interface for the listeners/observers callback method */
interface ModelListener {

    void stuffChanged();
}

class View implements ModelListener {

    public void stuffChanged() {
        System.out.println("View: Oh, something changed. I better show the new stuff!");
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Five Finger Death Punch - Ashes

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You only posted portions of the code, but it looked like you had two loops running through the result set where you only need one. It doesn't matter which one of them you remove really - just don't loop them twice.

It you actually look at and think about what the loop that you changed is doing, you'll see why your row colors don't alternate. Setting the $bg_color 'mysql_num_rows' times doesn't really do much if you aren't using that variable in the loop. If you are using $i as a counter, use that in the bg_color expression instead and take the $j loop out completely.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could start with the Sun tutorial on networking: http://java.sun.com/docs/books/tutorial/networking/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It did take a little fiddling around with it before suspecting the AWT Label thing. The behavior was just odd enough to suspect some mixing of AWT and Swing components and sure enough he was using Label. The missing "J" certainly didn't just jump right out of all that code :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just as well, I suppose. It seems a rather silly thing to say.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And a Map could prove useful in aggregating the values after you have parsed them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I believe you should be able to cast the Node to an Element and use Element.getAttribute(java.lang.String)
(Just guessing though - we use JDOM here instead of that api)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, I had a few minutes to play with the code. The main problem is that you are using java.awt.Label instead of javax.swing.JLabel for the labels in AddRecord. It' not a good idea to mix heavyweight AWT components with Swing components in the same UI. That was causing the problems with painting your menu properly.

Here's some revised code that behaves properly. Note that I put some of the separate classes inside "TheFrame" as inner classes just for my own convenience. You can certainly move them back out.

////// main , the frame ///////
import java.text.MessageFormat;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;

public class TheFrame extends JFrame
{
	private JPanel menuPanel;
	private JPanel text;
	private BorderLayout bl = new BorderLayout();


	public TheFrame()
	{

		JLabel one = new JLabel("Java Final Project: Employee Record");
		one.setAlignmentX(0.5f);
		one.setAlignmentY(1f);
		JLabel two = new JLabel("Written by Henry Li");
		two.setAlignmentX(0.5f);
		two.setAlignmentY(1f);

		text = new JPanel();
		text.setBackground(java.awt.Color.white);
		LayoutManager boxLayout = new BoxLayout(text, BoxLayout.Y_AXIS);

		text.setLayout(boxLayout);
		text.add(one);
		text.add(two);

        // add the menu
        createMenu();
        // set close op also
        setDefaultCloseOperation(EXIT_ON_CLOSE);
// don't need
//		add(menuPanel, BorderLayout.NORTH);
		getContentPane().add(text, BorderLayout.CENTER);
		validate();

		setBounds(400, 400, 600, 300);
		setVisible(true);

	}

    // Moved everything from menu panel here
    private void createMenu(){
	 JMenuBar menuBar;
	 JMenu menuFile, menuEdit;
	 JMenuItem closeMenuItem, printMenuItem, showTableMItem, addRecordMItem;

		menuFile = new JMenu("File");           // menu file
		menuFile.setForeground(java.awt.Color.black);
		closeMenuItem = new JMenuItem("Close"); // menu closeItem
		menuFile.add(closeMenuItem);            // menu file with closeItem
		closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
		closeMenuItem.addActionListener(new closeMenuHandler());


		printMenuItem = new JMenuItem("Print");  // menu printItem
		menuFile.add(printMenuItem);            // menu file with printItem
		printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', …
BestJewSinceJC commented: Noticing a 'J' missing on JLabel is good stuff. Nice. +3
Salem commented: Nicely done +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Peter is correct that you would need the same package declaration for the Person class - or you can remove the package statement from Testing. You can read more about using pakages to organize code here: http://java.sun.com/docs/books/tutorial/java/package/index.html

The easiest thing for you to do at this point is to remove the package statement from the top of your Testing class (and from Person if you have added one).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can disagree with the rule all that you like - it's still a rule that you must adhere in your postings.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I just quickly glanced through the code, so perhaps I missed something, but it looks like you've added a JMenuBar to a JPanel and added that to your JFrame. I would recommend using setJMenuBar() method on JFrame to add the menu to the frame.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Stating why you are unable to execute that code might prove useful to someone inclined to offer advice on it.

Your file names are just fine, but I would remove the package declaration from "Testing", unless you have re-created the directory structure of those files.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Though it has nothing to do with your local job market:
Programming Language Popularity

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just a couple of minor but important changes in your setGui() method

public void setGui() {
        JFrame frame = new JFrame();
// remove this, you want to use your current class instance here
//        JPanel drawP = new JPanel();  

       // again, current instance
        addMouseListener(this);

        // same here
        frame.getContentPane().add(BorderLayout.CENTER, [B]this[/B]);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 500);
        frame.setVisible(true);
    }

You were creating a new JPanel object and putting that in your frame and using your existing "pad" object as a mouse listener. Since your class extends JPanel, you really want to use this instead of a new JPanel object.

Edit: heh, same time as Vernon.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
uhm can u give me advice about cs thesis??

uhm... don't just skip it or you may fail?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The thing is... the choice of an IDE is a very personal subject, maybe you like some features that other IDE doesn't have, there isn't anyone perfect and preferences will vary for example if you work at home, or a company. I have seen several developers disposing hours at some function that shouldn't take much only because they don't remember everyday functions or API. If you use notepad or editor like vi, you will not pass frequently for things like this. Status or not... 'the best IDE tool' will not you to convert in an expert, advanced programmer, rather lazy or comfortable one. In PHP, command-line compilers simply doesn't exist, so extras tool beyond syntax coloring or remembering doesn't make any great difference. If you have trouble with some code, DaniWeb or php.net for that.

I agree. The tool does not make you good at using it. However, IDE's and editors that provide functionality such as syntax highlighting, etc. are a net positive in productivity for development, especially for large projects. Knowing some of an API (you certainly aren't going to know all of them) by heart doesn't make you a good developer either. If productivity is your main goal, intentionally not using tools that increase it just because you consider them a crutch is ridiculous. As a developer, my employer is much more concerned with how much quality work I can get done rather than how I would fare on a pop quiz on the order of …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A hammer is a hammer, maybe you want one lightweight, ergonomic, rubber handle with micropore, it's the same.

And by your analogy, you're using a rock, but that is certainly your choice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You're trying to access element 43 of a vector that only contains 2 elements.

Also, this code opVect.removeElementAt(opVect.lastElement()); is using an object parameter, lastElement(), instead of an int index parameter for removeElementAt(). You are doing that in several places and really the only reason it even compiles is a nuance of auto-boxing and upcasting of char. You need to supply an index parameter for those calls or use remove(Object) instead of removeElementAt(int).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, any text editor works for editing code. That is not the same thing as being a good tool for development.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Chisel/Stone is better than Notepad. Please don't use Notepad

Yes, Notepad bad...
Notepad++ good :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Definitely.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

We're just a blip in the timescale so far. The dinosaurs were dominant for ~160 million years. The Homo genus only has about 2.5 million under its belt so far and I don't think that I would bet on even seeing 3 million.

jephthah commented: good point. +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's also promotion of your own software, which is against the rules of the forums.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you're using 5.0, then do you have a version of that class named "Vector" (in caps, not lower case) in that directory? Because, as James mentioned, you may have namespace collision problems.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This call opndVect.get(opndVect.lastElement()); isn't valid because lastElement() returns an Object and get() requires an int index parameter. lastElement() itself returns the last element in that Vector, so really the get() is redundant anyway.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you compiling against java 1.5 or later? Those declarations of Vector are perfectly valid post-1.5. You have other issues with using get(Object) calls that are not valid, but the declarations are fine.

Grn Xtrm commented: Thanks for the help. +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Netbeans does support PHP now and it does have a visual designer, but I have not used it for PHP and can't speak to it's strengths/limitations.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why not mark it solved yourself? The link is right there at the bottom of the thread :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

My use of 'should' is merely in the terms of a suggestion, not an imperative. That may be a usage difference that is more subtle to a non-native speaker of English. :)

I have no moral difficulties eating the meat of animals. I'm sure that most other carnivores don't lose too much sleep over it either. If you prefer veggies, great, more veggie-power to ya - I'll stick to getting my protein from cute, furry critters.

Nick Evan commented: Hmmm... baked cute & furry critters; sounds delicious! +15
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's ok. I'll clean out the first two. I didn't want to delete them if there actually was a slight edit in the code that you intended.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is there any difference in those or did you post three copies of the exact same thing?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I believe he wants to redisplay the values that the user entered if the form fails validation and needs to be edited and resubmitted.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Check my edit. I forgot that you have to click that link above the form :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can view all of your reputation from the User Control Panel. Click the link for Latest Repuation Received.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What you are wanting to do has absolutely nothing to do with a for() loop. You need a simple if() check on a counter variable that is incremented by your click event - something like

int clickCount=0;

void mouseClicked(){
  ++clickCount;
  if (clickCount > 0){
    // do whatever
  } else {
    // do something else
  }
}