Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you haven't already, you may want to look through the Ellipse2D API. It has methods related to containment and intersection that may prove useful.

dickersonka commented: good find, forgot all about this +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why would you wait for more instead of checking out the references you've already been given? Have you tried searching any out on your own? Waiting for others to hand you information is not a habit I'd recommend if you wish to be productive at programming.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

518

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So perhaps you should close this thread, since you have already started another on the exact same topic.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Put that call to addMouseListener() in your frame class and pass your MeltingSnowman instance as the parameter.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, they really won't, because they just posted their homework assignment without demonstrating any effort whatsoever - which runs afoul of the announcement in all of the dev forums: http://www.daniweb.com/forums/announcement8-2.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Of course it does - you aren't saving what is read anywhere:

reader.read();

If you want the data read into a char[] buffer then you have to supply it as an argument to the read() method. Check the API for read(). There are a few variations available depending on your needs.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

None of your classes implement MouseListener, which has a couple more methods than just mousePressed(). If your MeltingSnowman class implemented MouseListener, you could add it as a mouse listener to your Frame. Or you could add an anonymous inner class that extends MouseAdapter and forward the mousePressed() event to your own mousePressed() method in the MeltingSnowman class, but your professor probably isn't looking for things like that right now.

This tutorial on writing a mouse listener might help a bit: http://java.sun.com/docs/books/tutorial/post1.0/ui/mouselistener.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could simple email a link to your "frds", you know.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What code? You aren't making a bit of sense. If it's some applet that someone else wrote, you need to ask them what's wrong with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Unfortunately, the fruit

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

514

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do you mean that depending on what the contents are of the XML file, different panels would appear which are created from classes that have their own content... but that the type and size of the panel are always the same? Because I don't see how you could use different sized panels each time, that would mess up the layout.

Layout and/or size are nothing more than attributes that you can put in an xml descriptor like any other property. We place one or more panels in a frame, with whatever attributes are required. The only part that needs reflection at all is the instantiation of a class by name with a specific constructor and the specification of the constructor parameters.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why?

We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

We ditched VSS for Subversion as well. Very happy with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

512

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, that's what objects are for and you can place any object type you want into a combo box. The toString() value of the object will be displayed as the text if the object is not itself a String. So consider how a small class like this could be used

class DormPlan {

    private String name;
    private int cost;

    public DormPlan(String name, int cost) {
        this.name = name;
        this.cost = cost;
    }

    @Override
    public String toString() {
        return name + ": $" + cost + "/semester";
    }

    public int getCost(){
        return cost;
    }
}

(Edit: Example class intentionally left a little bit incomplete.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

508

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the interview questions here and perhaps someone will oblige to answer them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

These two are free online:
http://hudzilla.org/phpwiki/index.php?title=Main_Page
http://www.techotopia.com/index.php/PHP_Essentials

I don't think they are downloadable though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

506

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Upgrade to Firefox3 for starters.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

504

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then when the user inputs (1,2) later for display not input, it displays the details in (1,2).

That was the point of the skeletal code above. The details are the "Attribute" object. You can call it whatever you want. All you are doing is storing and retrieving a single object at a position in a 2D array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You missed the ! (not) operator in my code to toggle the glass pane on/off. You aren't ever setting it visible :)
Do this

getGlassPane().setVisible( !getGlassPane().isVisible() );
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to add a call to repaint() after you update your coordinates in the KeyListener.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I just added System.out.println() calls in your KeyListener and ran it in both the applet viewer and a web page and they worked fine as long as it had the focus.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What do you mean by "can't get it to work"? Because your key listener does respond as long as you make sure it has focus (i.e. click in the panel). You can add a call to requestFocusInWindow() in init() if you want to make sure it gets focus without the click.

I couldn't say if any of the other parts work because they reference variables and classes that do not exist in the code you posted. I just commented those out when I ran it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Oprah is the devil.

I always thought the devil would be taller...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

500

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So what you really want is something similar to this perhaps? Assuming you have a 2D array "attributeArray" of "Attribute" objects that contain your data

private Attribute getAttribute() {
  int x = [I]promptForX()[/I];
  int y = [I]promptForY()[/I];
  return attributeArray[x][y];
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So he's chosen as his Chief of Staff someone who was very much in bed with Freddie and Fannie

Conservatives are quite upset, as they only approve of bedding Fannie.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

im bored.
im posting this because im bored.
yup...
ughhhhhhhhhh....
im soooooooooooooooooooooo bored...
is there anyone out there that wants to chat???
anyone???
at all?
=|

All of these people do. They're bored as well, I imagine.

Nick Evan commented: I think you might be right! +11
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you don't ever change x or y, it's going to keep overwriting the same element forever.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

try once more

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are wanting to paint the line over a grid of JButtons, you'll need to create a small component to install as the glass pane (you read about glass pane here). The code to paint the lines will go in the paintComponent() method of that class. Here is a small example of that to give you a start:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;

public class TicTacToe extends javax.swing.JFrame {

    public TicTacToe() {
        initComponents();
        
        // intall the OverlayPane as this frame's glass pane
        setGlassPane(new OverlayPane());
        
        // installing a listener on jButton1 to toggle 
        // the glass pane painting on/off just for an example.
        jButton1.addActionListener(new ButtonListener());
    }

    /** This component will serve as the glass pane overlay to 
     * paint over all of the other components.
     */
    class OverlayPane extends JComponent{
        /** This is an example of painting a line from button1
         * to button9 over the existing components.
         */
        protected void paintComponent(Graphics g) {
            // from center to center of buttons if you want
            // int x0 = jButton1.getX()+jButton1.getWidth()/2;
            // int y0 = jButton1.getY()+jButton1.getHeight()/2;
            // int x1 = jButton9.getX()+jButton9.getWidth()/2;
            // int y1 = jButton9.getY()+jButton9.getHeight()/2;
            
            // from corner to corner of buttons
            int x0 = jButton1.getX();
            int y0 = jButton1.getY();
            int x1 = jButton9.getX()+jButton9.getWidth();
            int y1 = jButton9.getY()+jButton9.getHeight();
            g.setColor(Color.BLACK);
            g.drawLine(x0, y0, x1, y1);            
        }
    }
    
    class ButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            // toggle line on/off
            getGlassPane().setVisible( !getGlassPane().isVisible() );
        }
    }
    
    /** Everything below here is just the code to generate …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then basically like the array loop I posted, but you just check against the input and change the values if needed

int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
while ( [I]userInput()[/I] ){
    if (i<min) min = i;
    if (i>max) max = i;
}

Of course, that still leaves it to you to get the input value and check against -1 as you loop.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if they are four individual variables you could use nested min/max calls

int a = 2;
int b = 22;
int c = 3;
int d = 345;
System.out.println(String.valueOf(Math.min(Math.min(a, b), Math.min(c, d))));
System.out.println(String.valueOf(Math.max(Math.max(a, b), Math.max(c, d))));

If they are an array, you could just call Arrays.sort() and pull the first and last, or loop them and find them yourself.

Unless you're doing it in a tight loop, it probably won't make much difference for just 4 values.

Edit: Actually, I wouldn't bother sorting if they are an array. It's just unnecessary overhead. Just loop them

int[] arr = {2,22,3,345};
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
for (int i : arr){
    if (i<min) min = i;
    if (i>max) max = i;
}
System.out.println("min: "+min);
System.out.println("max: "+max);
jbennet commented: helpful +32
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm saying that you need to actually assign those variables the value you want them to have. If you want to store what "readData()" returns in the variable "lbs", then you have to use that statement lbs = readData(); . You have all zeros in your program because you haven't changed their values after you initialized them. Those methods you have written will not fill in the values of the parameters you have passed them.

I'd recommend re-reading all your notes on using methods and perhaps this as well: http://www.codeguru.com/java/tij/tij0036.shtml

programmingme commented: Thank You so much for your help! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have declared all of those variables, but you haven't given them any values. You set those variables to be the results of your calculations

lbs = readData();

And you need to change that method to take no parameter. Parameters are for giving data to a method. You have declared it like you expect the method to fill in the value for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Huh? That is exactly what you are doing here

envStack.push(envA);

Perhaps you need to restate the question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sure there is. Either capture that function value in a variable and then pass that to your calculate method

lbs = readData();

("pounds" isn't a parameter to that method, it's the value you want to return)
Alternately you can use the method call itself directly in the second call

Convert( readData(pound), oz, totalOz);

(though "totalounces" shouldn't be a parameter - it's the return value)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Recaptcha is good, free, and easy to implement - plus you're helping to digitize books at the same time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

First, make sure all code you post is in [code]

[/code] tags (there is a button to apply them to highlighted code in the post editor).

Second, you can't use primitives "by reference". Your function needs to return the result of the calculation. Objects passed as parameters can be modified by methods, but primitive datatypes cannot.

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

Manuz can't count

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well of course it does. You set the text to that number. If you want that label to remain the same then use a separate label for the converted value.

stephen84s commented: Oh dear never could have imagined that was his problem +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It works just fine for me as well. The only "disappearing" I could see is that the label will move depending on the length of the value displayed in the "result". That is because you used FlowLayout.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"Objects are the same" is the entire purpose of the equals() method.
http://www.ibm.com/developerworks/java/library/j-jtp05273.html