Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>When attempting to implement InfoSelectionListener it tells me that the types are different.
Your InfoViewer just needed to implement InfoSelectionListener, then it would have allowed "this" as the parameter.

As far as the rest, I didn't really follow what you were trying to do with the ArrayList.
With the checkbox, you really only need to add a method to InfoObject like

public boolean isSeletected(){
   return chkSelected.isSelected();
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The painting issue is because you're only painting your shapes in the array when currentShapeObject is not null - which is only the case when the mouse button is down. If you change your painting code to this the problem resolves

// draw the shapes
      for (int i = 0; i < numOfShapes; i++) {
        shapeObjects[i].draw( g );
      }

    // If currentShapeObject is null, do nothing
    if ( currentShapeObject != null ) {
      currentShapeObject.draw( g );
    }

Keep in mind that currentShapeObject is the currently drawing object while you're dragging the mouse.

As far as the shape combo box problem, consider that the selection indices are zero-based. Read your event handler with that in mind.

On a more general note, you don't need to preface every call to an inherited method with "super.". You only need to use that if you've overridden the method and you want to execute the code in the parent class' version of that method. You can drop the "super" from most of the method calls in your shape objects.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can easily extend AbstractListModel to be a tiny wrapper around an ArrayList that's passed to it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

To the InfoObject. It would give you a more definitive way than focus gained/lost to select/deselect the items.


If you did want to implement a selection listener for the InfoObjects, you could create one pretty easily with

interface InfoSelectionListener{
    public void selectionChanged(InfoObject info);
}

Then your InfoObject would need to maintain a listener list

List<InfoSelectionListener> listeners = new ArrayList<InfoSelectionListener>();

and have a couple of methods to add listeners and fire events for them

public void addInfoSelectionListener(InfoSelectionListener listener){
    listeners.add(listener);
}
private void fireSelectionChanged(){
    for (InfoSelectionListener sl: listeners){
        sl.selectionChanged(this);
    }
}

and your viewer would just need to implement the InfoSelectionListener interface and add itself as a listener when you created the InfoObject items

ndbo.addInfoSelectionListener(this);

Whenever the selection state of the InfoObject changed, your InfoObject would use the fireSelectionChanged() method to notify the listeners, perhaps on mouseClicked()

addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
        setSelected(!selected);
        if (selected) {
            fireSelectionChanged();
        }
    }
});
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The easiest thing to do would be just add a checkbox to the panel to set a boolean "selected" property on the object. That would allow multiple selection as well.

Here's an article on MVC if you care to read more on that topic: http://java.sun.com/developer/technicalArticles/javase/mvc/?intcmp=3273#3

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm getting a nullPointerException error in the mouseMoved and mouseDragged methods though, which I'm not understanding

Take a look at the order in which you initialize the drawing panel and the status label in your DrawFrame class.

Moved and added everything else, thanks! About looping the shapeObjects array, I have the loop set up like this inside paintComponent():

for (int i = 0; i <= numOfShapes; i++) {
        shapeObjects[i].draw( g );
      }
      currentShapeObject.draw( g );
    }

Is that right?

Mostly. Make sure your shapes aren't null before you try to draw them from the array, since not all of those 100 are created yet. You'll still need the null check on currentShapeObject also, since it's only not null while the mouse button is down.

I have setDefaultCloseOperation(EXIT_ON_CLOSE); on a test class, but thanks anyway!

Ok, just wanted to mention it. I had to make my own main() method to run it, so I didn't know what you had going on in the launch class :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The easiest thing for you to do is loop the InfoObjects in your array to find the "selected" one and remove it.

There is a lot you could do to add listeners, models, etc to make this more MVC, but it would require a decent amount of extra work because your UI objects are your data objects at this point.

You're correct that focus will change when you click the button. Also consider that you don't want to code the InfoViewer operations into the InfoObjects. Keep your separation of responsibilities in mind with the container and the contained items.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, a couple of things to help you get back on track.

First off, take a look at the brace on line 124 of your DrawPanel class. That's wrecking your MouseHandler and I'm sure causing all kinds of confusion as to why those mouse methods don't seem to be doing anything. You effectively only have a mousePressed() method in there. The rest are defined on DrawPanel and not doing you a bit of good.

Second, move numOfShapes++; to mousePressed() , where you actually create a new object. It has nothing to do with painting.

Third, if you want to paint multiple shapes, you have to loop the shapeObjects array and call draw on them, so you need to add that to your paintComponent() method. The currentShapeObject is just going to be painting the one you're dragging with the mouse. (Add a repaint in mouseDragged() also).

That isn't everything, but with some work it should get you to a better place with it. You may also want to add a setDefaultCloseOperation(EXIT_ON_CLOSE); line to your DrawFrame constructor as well, unless you're setting that somewhere else.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is that you are executing all of that code on the event dispatch queue - which also handles repaints - so it can't update the GUI until your current code completes. You need to start a separate thread to for the calcs and then update the UI on the event dispatch thread. You can read about that here: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Print out 'str' just before you execute it. The error message says you have a syntax error in the SQL statement. It's not a java issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You know, you could get by using just one exclamation point or question mark instead of 3-10 each time.

Typing in caps doesn't help your case either - it just irritates people.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, it's certainly not spam ;)

jephthah commented: aha +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Make sure that whatever build script that you're using is including those images in the jar file. This link might help with the getResource() pathing considerations: http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Put some debugging println statements in relevant methods like paintComponent(), draw(), etc. (I assume you aren't using an IDE with a debugger) so you can see what is going on internally.

I glanced through the code and not jumped right out as a problem, but you didn't post the MyShape class, so I can't run the code here to look into it much further.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could:
a) add a 'parent' reference to the InfoObject so that when it's clicked it can set a property such as 'selectedInfo' on the parent to itself.

b) Simply loop the list and find the 'selected' object.

It really depends on the dependencies you're trying to support in your class structure.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try executing it with java -jar BlueHarvest.jar . If it still fails you probably need to fix up the manifest to specify the main-class attribute.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, it's this part

public Person(String firstName, String lastName)
{
   this.firstName = firstName;
   this.lastName = lastName;
}

That is the constructor that is called with the super(firstName, lastName); call in your Employee class. You need to add a constructor like that to Employee, so the super(firstName, lastName); call in your Manager class can access it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You haven't defined a constructor for the Employee class that takes two strings, which is what your Manager class is trying to call.

You need to define that constructor.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the tooltip for the down-vote arrow merely says "This post is unclear", so the down-voters may have simply thought it was a poorly structured question or that he should have been more specific about what he was having trouble with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>This new look is stupid. ...
Yeah! Rabble, rabble, rabble!!11!

Sorry to hear that you are feeling sick. Perhaps you just need some fresh air. (This thread didn't though...)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, this thread is old and dead... but since someone pointed out to me a mistake in my post above, I'll address the mistake.

If p==2 , p is prime, for p!=2 if p%2==0 then it's not prime.
Just wanted to clear that up.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

No, it is not different. It is the same error that you inquired about in the other thread. And as far as "bothering anyone", you're violating this clause in the Keep It Organized rule of our forums

Do not flood the forum by posting the same question more than once

Perhaps you should review them before starting more threads for the same issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If they really want to upgrade your skills, they should give you some real work to do, rather than dumping you into more classes to learn more technologies that you will only barely have a grasp on.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

SimpleDateFormat can be used if you want to parse a Date from a String:
http://www.exampledepot.com/egs/java.text/FormatDateDef.html

If you want to set a date programmatically, use a Calendar:
http://www.exampledepot.com/egs/java.util/GetDateFromCalendar.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is there a reason that your other thread on this wasn't sufficient?
http://www.daniweb.com/forums/thread264550.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And now you can see why blocks are indented. Each nested level should be indented from its parent.

Format the code and you'll probably find the problem much easier when you can see the logical hierarchy.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you have further HTML/CSS questions to work through, I'd recommend starting a new thread over in that forum. This one is getting rather long and covering multiple questions. Limiting threads to one topic and making sure they're in the correct forum makes it easier for both the helpers and the helpees. :)

And please mark this one solved if the original issue has been resolved.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This line

poly3.addPoly(poly1,poly2);

will return the result of adding the two parameters - but you aren't storing that result in anything.
To use the result you would use the function like so

Polynomial result = Polynomial.addPoly(poly1,poly2);

and you would then want to print that result.
(Note the different syntax for calling a static method. You use the class name - not an instance.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'd recommend re-thinking your painting logic altogether. You really don't want to be creating new components, adding them to your current container, and then trying to hand their graphics context off to be drawn on all inside the method that is just supposed to be drawing your panel. It's just too much.

Create a small component that can represent your sub-panels and put the painting code in its paintComponent() method. Create some other method that handles the creation/arrangement of those sub-components. Leave paintComponent() to what it is for: painting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Seems like a reasonable comment to me.

I would also add: ask a question or describe the problem. Don't just dump the code and say "fix this".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class LinePanel2 extends JPanel {

    Timer animationTimer;
    int lineLen = 50;   // length of the line
    int x = 65;    // x anchor
    int y = 65;    // y anchor
    float angle = 0f;   // angle of the line
    double angleChange = Math.PI/20;    // rotation per tick

    public LinePanel2() {
        // start the timer firing every 50ms
        animationTimer = new Timer(50, new LineAnimation());
        animationTimer.start();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        // this just makes the line look smoother, less pixelation when at an angle
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // calc the x and y offsets based on the current angle and line length
        double dx = Math.cos(angle) * lineLen;
        double dy = Math.sin(angle) * lineLen;
        // clear the area and draw the line
        g2d.clearRect(0, 0, getWidth(), getHeight());
        g2d.setColor(Color.BLUE);
        g2d.drawLine(x, y, (int)(x + dx), (int)(y - dy));
    }

    class LineAnimation implements ActionListener {
        // this gets called every "tick" of the timer
        public void actionPerformed(ActionEvent e) {
            // change angle and repaint
            // subtracting for clockwise motion
            angle -= angleChange;
            repaint();
        }
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new LinePanel2());
        f.setBounds(100, 100, 200, 200);
        f.setVisible(true);
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here's something to play with

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class LinePanel extends JPanel {

    Timer animationTimer;
    float angle = 0f;
    int lineLen = 60;
    int x = 20;
    int y = 20;
    int moveX = 2;
    int moveY = 2;
    double angleChange = Math.PI/20;

    public LinePanel() {
        animationTimer = new Timer(50, new LineAnimation());
        animationTimer.start();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        double dx = Math.cos(angle) * lineLen;
        double dy = Math.sin(angle) * lineLen;
        g2d.clearRect(0, 0, getWidth(), getHeight());
        g2d.setColor(Color.BLUE);
        g2d.drawLine((int)(x - dx), (int)(y + dy), (int)(x + dx), (int)(y - dy));
    }

    class LineAnimation implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            angle += angleChange;
            x += moveX;
            y += moveY;
            if (x < 0 || x > getWidth()) {
                moveX *= -1;
                angleChange *= -1;
            }
            if (y < 0 || y > getHeight()) {
                moveY *= -1;
                angleChange *= -1;
            }
            repaint();
        }
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new LinePanel());
        f.setBounds(100, 100, 300, 300);
        f.setVisible(true);
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Help with what? You haven't asked a question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Nope.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

On line 45

fieldJPanel.add (fieldJPanel1,BorderLayout.NORTH);

you haven't initialized 'fieldJPanel1'. Looks like you mis-typed it up above and set up 'fieldJPanel' twice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, not as a language feature. Many editors have tags for collapsing section of code though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could also take a look at this post that demonstrates the absolute basics of drawing a couple of lines on a JPanel. If you check the Graphics (and Graphics2D) API, you'll find other methods for drawing other shapes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you actually expect anyone around here to believe that, it is absolutely no wonder that you're having a tough time with pseudocode.

It's practically pseudocode as you have it posted. Show some effort, post what you have so far, and ask specific questions about the part you're having trouble with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So ask a question then. Posting your homework won't cut it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could start with the 2D Graphics tutorial.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So enter the product key. If you don't have one then you have an illegal copy of Vista and you're SOL here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Stating what you need help with on those methods would be useful as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Class.getResource() will locate a resource based on the classpath.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't. Tomcat is a servlet engine - it has nothing to do with PHP. You'll need Apache with PHP installed.
Edit: Scratch that. I spoke too soon. I guess there are ways to hook them up: http://wiki.apache.org/tomcat/UsingPhp

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try System.getProperty("user.dir");

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to review how methods work. To execute the code in a method you must call it, so in main() you would have to add a line

hele();

if you want that code to run. If you want to pass it the array list then you must change your declaration back to take the ArrayList parameter and call it like so

hele(words);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Methods do not execute by themselves - you have to call them. Did you put a call to "hele()" in your main method?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

To call your 'hele' method, it would need to be declared static.

To print the list, loop through the ArrayList and println() each element.