Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you simply search on "i_m_rude" you will have all the posts to peruse at your leisure.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should not have a repaint() call in your paint() method. Also, you should really be overridding paintComponent() on a JPanel or something instead of paint() on a JFrame. If you really must override paint, make sure you call super.paint() first or other components in the frame won't render correctly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sure, you can connect to MySQL with JDBC. MySQL has info on their site: http://dev.mysql.com/usingmysql/java/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Since you've moved the origin to the middle of where you want the rectangle, draw the rectangle centered about the new origin.

Old rect:

g2d.drawRect(100,100,10,10);

translating to center of rect and drawing the same shape:

g2d.translate(105,105);
g2d.drawRect(-5,-5,10,10);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you translate your origin to where you want the center of the rectangle to be, are you drawing the rectangle relative to the new origin location?

If you have a rectangle centered at say (2,2) and you translate to that point and draw the rectangle with the same (x,y) values, you will now have a rectangle centered at (4,4) because you have shifted the entire coordinate system to a new location.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are basically undoing your translation on line 7 by restoring the original transform. You are rotating the original context.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It works just like any other Java library. Perhaps you can install a player bean in Netbeans, I don't know, but really it's just an API. Use it like any other API.

Read the extensive docs if you're unsure of how to work with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try the Java Media Framework

There is one example of using it with Swing here in the code samples section.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Call the dispose() method on the frame you want to close.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Unless you want to deal with a fixed span for the second dimension, use an ArrayList of ArrayLists.

Also, don't ever use 'aa', 'bb', 'aaa' for names of anything. Name your classes and variables with descriptive, meaningful names and it will be much easier for you and anyone else reading the code to follow your logic.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use H2 for your database. Problem solved.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just put the alias after the table name in your FROM clause and use those in place of the table name:
select a.f_name, a.l_name, b.f_name, b.l_name from user a, user b where a.id = '1' and b.id = '12'

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't define methods within methods. Check your braces and code block organization.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look in the Properties window at the 'border' property. Click the builder button "..." on the right-hand side.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might take a look at the transform() and inverseTransform() methods on AffineTransform.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The buttons may only show posts which are currently negative or positive, so if someone voted down and someone else voted up, the net result would not be visible on either button.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, if you wish to discuss a particular question, please confine it to a single thread so that the answers don't get spread around all over the place.

Closing this thread. Please direct further discussion to the thread linked above by JorgeM.

JorgeM commented: thanks! +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'd recommend switching to H2 for your database. You wouldn't need to mess with the Jet drivers or data sources at all. All you need is the H2 jar.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Java's rules about braces and blocks are nearly identical to C++, so if you did write that C++ code, you should see why your Java version is quite broken.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No one is going to explain this line by line. Make an effort yourself and ask specific questions about the portions that you are unclear on.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Either Wiki is lying or you didn't double your facts before you post that?

As pritaeas has noted above, it's a MySQL driver API for PHP, not an actual database. I'm fine on the facts.

But Java also have that too:

JDBC is Java's generic database API. It is a set of abstract interfaces to define interactions with many different database drivers. There is nothing in it that is specific to MySql. In that regard, it's similar to PDO.

Questions about these language-specific APIs belong in their respective language forums, rather than the more general Databases forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Mysqli and PDO are PHP modules - not databases. It is entirely appropriate to post them in the PHP forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you have a question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Where would people ask about a challange/project that is posted in the thread? Would they have to open a new thread for example?

Yes, they would need to start their own thread. If questions about the projects were allowed in the sticky thread, it would very quickly grow to an enormous mess.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@diceadmin: Then why are you bothering to post here on an open discussion board? These forums aren't here to collect private business.

If the questions and answers cannot be openly shared, they don't belong here at all.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

To cast the reference, you just need to add the class name in parenthesis in front of the method call, ie.
MyClass obj = (MyClass)s.readObject();

You can read a bit more about the ObjectInputStream and see a couple of examples here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's some example code that I didn't have time to finish up yesterday. It may clarify some of what I mentioned above:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;

public class BallCollision extends JPanel {

    Timer animationTimer;
    Ball ball;
    BadLands badlands;

    public BallCollision() {
        ball = new Ball(10,10,5);
        badlands = new BadLands(50,50,90,60);

        animationTimer = new Timer(50, new BallAnimation());
        animationTimer.start();
    }

    class Ball {
        Ellipse2D shape;
        float speedX = 5;
        float speedY = 3;

        public Ball(int x, int y, int radius){
            shape = new Ellipse2D.Float(x, y, radius*2, radius*2);
        }

        public void draw(Graphics2D g){
            g.setColor(Color.BLUE);
            g.fill(shape);
        }

        public void updatePosition(){
            if (shape.getX()<0 || shape.getMaxX()>getWidth()){
                speedX *= -1;
            }
            if (shape.getY()<0 || shape.getMaxY()>getHeight()){
                speedY *= -1;
            }
            shape.setFrameFromCenter(
                    new Point2D.Double(
                        shape.getCenterX()+speedX,
                        shape.getCenterY()+speedY),
                    new Point2D.Double(
                        shape.getX()+speedX,
                        shape.getY()+speedY));
        }

        public boolean collidesWith(Shape otherShape){
            return shape.intersects(otherShape.getBounds());
        }

        public void processCollision(Shape otherShape){
            Rectangle2D otherBounds = otherShape.getBounds2D();
            if ((shape.getCenterX()-speedX<otherBounds.getX() 
                    && shape.getCenterY()+speedY>otherBounds.getMinY()) 
                || (shape.getCenterX()-speedX>otherBounds.getX()+otherBounds.getWidth() 
                    && shape.getCenterY()+speedY>otherBounds.getMinY())) {
                // left/right collision
                speedX *= -1;
            }
            if ((shape.getCenterX()+speedX>otherBounds.getX() 
                    && shape.getCenterY()-speedY<otherBounds.getMinY()) 
                || (shape.getCenterX()+speedX>otherBounds.getX() 
                    && shape.getCenterY()+speedY>otherBounds.getMinY()+otherBounds.getHeight())) {
                // top/bottom collision
                speedY *= -1;
            }
        }
    }

    class BadLands {
        Rectangle2D shape;

        public BadLands(int x, int y, int width, int height){
            shape = new Rectangle2D.Float(x, y, width, height);
        }

        public void draw(Graphics2D g){
            g.setColor(Color.BLACK);
            g.fill(shape);
        }
    }

    @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 …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That sounds reasonable for a "bounce off" response. It's generally just a reversal of dx and/or dy. You can shortcut those easily with expressions like dx *= -1; to change the direction of delta x, etc. The various sides are just a matter of determining the surface of incidence.

Regarding the inner class question, yes, that is how you refer to the current instance of the parent class: ParentClassName.this.whatever()

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, as JorgeM mentioned, try clearing your cache. I saw the kitten until I hit Ctrl-F5 in Firefox to clear the cache and reload.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I guess that depends on what you intend the behavior "kick something out" to mean. Does it bounce backward? Slide sideways? Pop out on the other side?

If you maintain a directional vector of any kind or separate x,y velocities, then you can determine the resulting position based upon the vector of incidence and whatever rules you decide for the outcome as I mentioned above.

You just need to examine the state at the time of collision. If you aren't saving it in a way that allows that, you may need to alter your objects to keep that information handy.

DavidKroukamp commented: helpful and concise +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It really shouldn't be any different from other collisions. Once you know the collision occurred, you just change the state of the colliding object to whatever result you intend. That may involve adjusting its velocity and position.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

and no this question is not Homework what so ever

How do you expect anyone to buy that when you are obviously in a Java class currently?

Show some effort and at least make a start on it or ask specific questions about what you are confused about.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Seems like your friend who said it could easily be done in a few lines of code would be the best place to start.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Welcome aboard!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, this thread is going nowhere fast.

The bottom line is that the syntax that MARIE expects has no resemblance at all to Java and therefore the Java forum will be of no help whatsoever. Computer Science or Legacy and Other Languages might yield something.

Edit: I'm going to move this into Computer Science, since it seems to be related to teaching architecture.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So everyone is supposed to know what some obscure "MARIE" simulator is? As bibki pointed out, you're in the Java forum - which MARIE is not. "Written in Java" != Java.

No need to be a jerk when you are the one posting in the wrong forum about some simulator syntax.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Components placed in BorderLayout.CENTER expand to fill the available space in the container.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't show where you have declared x, but in your loop it doesn't need to be public anyway. Just declare int x=0; in your loop. It's only needed locally.

Other things to note:
-You also want to reconsider your increment x by one unless you really want to color the whole area black.
- The calls to super.paintComponent() and draw() shouldn't be in the loop.
- Loop variables don't do much for you when you hard-code the coordinates in drawLine().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Want to share what it says is not public?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Break it down to a simple loop that draws the vertical lines stepping across from x=0 to x=width, adding 10 each time. After that write a second loop that draws your horizontal lines, from y=0 adding 10 until y=height. You don't need an array for that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is there a reason not to just use JInternalFrames for this? It seems that is what you're trying to mimic.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You do realize what e.getSource() returns? Read the method description again, because changing it to what you did makes no sense at all.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to show some effort if asking for homework help. Post your current code and specific questions.

If you don't know what a float data type is, you need to read your book or a basic Java tutorial.

stultuske commented: no good work without a solid basis indeed .. +12
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, well there is the problem: Java 1.4.2

Auto-boxing was introduced in 1.5. Without auto-boxing, the compiler doesn't convert primitive variables to their object wrappers, like Integer, automatically. You have to create those object instances yourself: new Integer(yourInt) Java 1.5 was officially at End-of-life status in 2009. You (meaning your class most likely) need to use a version of Java that is still supported. There is absolutely no reason at all to still be teaching students with anything prior to Java 1.5. Java 6.0 has been out since 2005.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What are you using to compile the program and which version of Java? That should resolve just fine to putClientProperty(Object,Object).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Java 1.4.2 docs do seem to come up near the top of search results fairly often, so it's an easy mistake to make if you don't glance at the version.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Cross-posted here: http://www.daniweb.com/web-development/databases/ms-sql/threads/407231/1738343#post1738343

Please direct any further discussion to that thread. Closing this one.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is really not a difficult problem

pButtonarray [x] [row].putClientProperty("x",x);
pButtonarray [x] [row].putClientProperty("row",row);
pButtonarray [x] [row].addActionListener (this);
public void actionPerformed(ActionEvent e) {
    JButton btn = (JButton)e.getSource();
    System.out.println("clicked x " + btn.getClientProperty("x") 
       + ",row " + btn.getClientProperty("row"));
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@mKorbel: I think the OP could go either way just fine. For more complex behaviors like your example of changing state on mouse events along with holding the data values, the inner class works well. For just attaching a couple of extra data values to a JButton, putClientProperty() is very handy and simple.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

putClientProperty(java.lang.Object,java.lang.Object) is just a key-value pair mapping. Strings are often used for the key values, but they don't have to be. You can use any Object as a key, which allows for some pretty clever mapping schemes in some cases.

In your case, strings would be fine: setClientProperty("row", row) This would set an Integer value of row with a key named "row".