Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to narrow that down a bit or highlight the additions that caused the problem and explain what you are trying to do, because I doubt many people are going to wade through that much GridBagLayout code based on what little you described.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The default layout manager is FlowLayout, which is what your JPanel is currently using since you have not changed it. You can change the positions of those text fields all day but FlowLayout won't respect them. It wasn't designed for that.

I would recommend using a BoxLayout or GridLayout if you just need to stack them, but you may need to examine the capabilities of other layout managers and play around with them to get things working like you desire. Take a look through this tutorial on laying out components:
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Sun tutorial on Reflection is a pretty good place to start:
http://java.sun.com/docs/books/tutorial/reflect/index.html

Keep in mind that using reflection to manipulate classes and methods is much slower than normal compile-time usage patterns (and the code is pretty long and unwieldy to boot) and should only be done when you need to work with classes or methods that are not present at compile time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

telekinesis has been demostrated many times througout time go and see for your self there are many famous psychic out there.view all the articles in mytelekinesis.com

Ok enough plugs for that ridiculous site.

i am not asking you to believe me.

That's good. At least you are being realistic on one point.

decide for yourself

Done. You're delusional.

Salem commented: That works for me :) +17
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, you definitely do not want to be adding components in paint().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to use a GeneralPath or Path2D.Float or Graphics.drawPolyline(int[],int[],int) for this. All of those provide methods to draw a series of points connected by lines.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

After you create the "mainPane", you need to set it's layout to GridBagLayout like so

mainPane.setLayout(new GridBagLayout());
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you tried

sid = input.nextInt();
if (isUnique(sid)){
  a[counter] = sid;
 ...

The problem is just that you are putting the id in the array and then searching that array to see if that id is already there. Search first, then add it if it's not found.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are putting the id into the array before you check if it's unique, so of course the id will be found in the array

a[ counter ] = input.nextInt();
           	sid=a[counter];
           	if (isUnique(sid))
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What is the "length" variable? You should be looping to "a.length" over that array. If "length" is not the same as the array length, you are missing parts of your array in the loop.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It will draw the lines from whichever (x,y) to (x', y') that you specify, so you have to vary those four parameters each iteration as needed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are only using the 'row' variable in drawLine() and I suspect you want to also use 'col', otherwise you are drawing over the same area several times.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I did change it as you said but now I got....
"variables col and row might not have been initialized"....Why?
I thought they were initialized at the top...

You declared them - you did not initialize them, meaning set them to a specific value. Declare them like this instead

for ([B]int col=0[/B]; col<7; col++) {
            for([B]int row=0[/B]; row<3; row++) {
               page.drawLine( 0, 100, (int) status(0,0), 100);
            }
         }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Sorry for not mentioning it before but, I do want to print 21 lines...

Yes, that was understood. Your code, as written, would have executed the setColor() statement 21 times and drawLine() only once, because the drawLine() call was not in the for() {} block. My point is that you should always include the braces on a for() block

for( ... ) {
    doSomething();
}

even though the compiler allows an implicit block of a single statement after the for()

// DON'T USE THIS FORM
for ( ... )
    doSomething();

Without the braces, the for() only applies to that single statement directly following it.

The implicit block form is completely acceptable, but it is less clear and prone to insidious problems when later another line of code is added to what should be a block but is not.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

For the exact reason that I have been telling you to use braces to delimit your for() blocks. That for statement is only applying to the line directly after it and the variable "row" that you declared is only in scope for that single statement. You need to use blocks with the for() statements if you wish to execute more than a single line

public void paintComponent (Graphics page)
      {
         super.paintComponent (page);

         // setColor() only needs to be called once - not each iteration	
         page.setColor(Color.red);
         
         for (int col; col<7; col++) {
            for(int row; row<3; row++) {
               page.drawLine( 0, 100, (int) status(0,0), 100);
            }
         }
      }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, ok, you are trying to cast it to an int. You need to place parens around the cast like so

page.drawLine( 0, 100, (int)status(0,0), 100);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This line

page.drawLine( 0, 100, int status(0,0), 100);

is not a valid method call because you have placed the type definition ('int') in it. Drop the 'int' part.

And get braces around those for() blocks unless you expect to set the color to red 21 times and only draw a single line.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Surely that is not all of the code? Post the rest and please place it within [code] [/code] tags.

Also, always use braces around for() blocks. Even though a single statement without braces is allowed after for() and if() statements, you are likely at some point to add additional code and then wind up trying to figure out why it isn't working right because what you thought of as a block really isn't. Just get in the habit of using braces even for single statements.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are just hitting a resource location problem. Your relative file path is not being found and because of the specifics of getImage() and drawImage(), the only visible symptom is no image being drawn. The MediaTracker that load the image is actually creating an image with no dimensions because it can't find the file resource.

I'd recommend loading the image as an ImageIcon through the class loader like this:

Image ZERO = new ImageIcon(getClass().getResource("images/0.gif")).getImage();

If you plan on building the game in a jar file, you would need to include the "images" directory as a package in the jar. You can read a bit more about this here if you like: http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource

To make it easier on yourself, I would also suggest putting the gifs in an array of Image[] so you can access 0-9 by index instead of having to translate digits to each named variable like ZERO.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, focus issues can be a pain with key listeners. The InputMap and ActionMap make it easier to handle this. Try using this instead of the KeyListener.

private void launch() {
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
      KeyStroke.getKeyStroke("R"), "reset");
    
    getRootPane().getActionMap().put("reset", new AbstractAction() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            System.out.println("reset");
        }
    });

    setBounds(100, 100, 300, 300);

    add(new JButton("hi")); //here is the perp

    setVisible(true);
}
TheWhite commented: great post! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you just need to get the text of the selected item from the combo box you can use getSelectedObject().

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

There is no paintComponent() method on JFrame, which is why it is not being called from repaint(). There is a paintComponents() method that paints all of the child components in the container by calling paintComponent() on each of them.

Because JFrame is a top-level container, you have to override paint() instead of paintComponent(). Be sure that you call super.paint(g) before your custom code so that everything else get's rendered properly. Your code will work with the following method

public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2 = (Graphics2D)g;
        clock = new Clock(minuteY, hourY, hourX, minuteX);
        clock.draw(g2);
    }
VernonDozier commented: Good post. +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to post the error message along with the updated code. No one here can see over your shoulder :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"txtMask" was simply the name of the JFormattedTextField that I was using in a small test file. In your case that would be "lastName". You need to call setFocusLostBehavior(JFormattedTextField.COMMIT) on it so it does not discard the field input when the string is shorter than your mask. You will also need to call trim() on the result of getText(), because it will contain placeholder spaces padded to the length of the mask.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you know that the code won't compile and it "has more to it", what exactly is your question? You said "for some reason this part of the code is'nt excuted"(sic). The obvious answer is that it won't execute because it won't compile.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

None of that code is executed - it doesn't compile. You have missing concatenation operators, illegal calls to non-static members from a static context, etc. You need to fix those first.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try adding the MaskFormatter like so

try {
    MaskFormatter formatter = new MaskFormatter("?????");
    txtMask.setFormatterFactory(new DefaultFormatterFactory(formatter));
    txtMask.setFocusLostBehavior(JFormattedTextField.COMMIT);
} catch(ParseException ex) {
    ex.printStackTrace();
}

That mask only allows up to 5 letters, so you'll have to add the others up to 25.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The masked field allows you to specify what is allowed to be entered in the field. Anything not allowed by the mask does not show up, so terminating after three invalid attempts doesn't really apply there.

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

getComponent() will provide the component that initiated the mouse event. If the info you need is just the text on the button then this will get it

public void mouseExited(java.awt.event.MouseEvent evt) {
        JButton button = (JButton)evt.getComponent();
        System.out.println(button.getText());
    }

If you need some other info, you can extend JButton to keep a reference to your Card object (or whatever object the button represents) and cast to that object instead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can do whatever you want when the mouse enters or leaves the button

jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseEntered(java.awt.event.MouseEvent evt) {
        jButton1.setBackground(Color.GREEN);
    }
    public void mouseExited(java.awt.event.MouseEvent evt) {
        jButton1.setBackground(UIManager.getColor("control"));
    }
});

or to just underline

jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    Font originalFont = null;

    public void mouseEntered(java.awt.event.MouseEvent evt) {
        originalFont = jButton1.getFont();
        Map attributes = originalFont.getAttributes();
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        jButton1.setFont(originalFont.deriveFont(attributes));
    }

    public void mouseExited(java.awt.event.MouseEvent evt) {
        jButton1.setFont(originalFont);
    }
});
jasimp commented: Is there anything you don't know? +7
sukhpalsingh31 commented: it is nice way to change text attributes +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If your database supports the "TOP" clause, you can use that. If not, then this is usually done by calling setMaxRows() on the Statement object in JDBC. Since you are using beans binding, I have no idea what to tell you because I don't have any api docs for that model and I've never touched it.

Edit: If you're using the Persistence API Query object, there is a setMaxResults() method available.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, the code in your action listener will execute in it's entirety without pause for input. If you don't want to use modal dialogs to prompt for input, then you need to separate the action listener code into section to respond to each input action (which will occur when the user presses enter in the input box). Here is a partial example to demonstrate what I mean

private void inputActionPerformed(java.awt.event.ActionEvent evt) {
    char inputChar = input.getText().toLowerCase().charAt(0);
    if(Character.isLetter(inputChar)) {
        switch(inputChar) {
            case 'y':
                displayScreen.setText("M)anual or A)uto mode?");
                input.setText("");
                input.requestFocus();
                break;

            case 'm':
                displayScreen.setText("How many discs would you like to use?");
                input.setText("");
                input.requestFocus();
                useManual = true;
                break;
        }
    } else {
        if(useManual) {
            int numberDiscs = 0;
            try {
                numberDiscs = Integer.parseInt(input.getText());
            } catch(NumberFormatException nfe) {
                nfe.printStackTrace();
            }
            // ...
        }
    }
}

Because you lose the linear question/answer behavior of using dialogs like in your original code, you have to maintain the state of the question series yourself. The code above (with the 'useManual' flag) is not really a good way to maintain that state, but a more proper example at this point would probably just cause more confusion. To avoid having to set a bunch of flags to keep track of which question you are on, an array of question strings could be used in conjunction with an index value that you increment after each question. But that is only one of many possible ways to set it up.

The point is that you have to maintain the …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You declared 2 car objects at the class level, but you are declaring 2 new ones in the constructor

import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;


/**
 * Draws two car objects. * 
 * @author LevelSix 
 * @version May 12, 2008
 */
public class CarComponent extends JComponent
{
   /**
    *@param g the graphics context
    */
   public CarComponent()
   {
[B]       // You are declaring new objects here with the same name
       // instead of initializing the ones you already declared
       // They drop out of scope after the constructor is done[/B]
       Car car1 = new Car(HUNDRED, HUNDRED);
       Car car2 = new Car(200, 400);
      
    }
       
   public void paintComponent(Graphics g)
   {
        
      super.paintComponent(g);
       Graphics2D g2 = (Graphics2D) g;
[B]       // so these are still null[/B]
       car1.draw(g2);
       car2.draw(g2);
       
    }
     public void moveBy(int dx, int dy)
   {
    car1.translate(dx, dy);
    int backward = dx * (-1);
    repaint();
    car2.translate(backward, dy);
    repaint();
   } 
   [B]// These remain null because you don't initialize them[/B]
   public Car car1;
   public Car car2;
   public static final int HUNDRED = 100;
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The first point I mentioned is causing the error. The second point will become apparent after you fix the first.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You probably want to look at two things.
1) Consider that these are declaring new car objects, which immediately go out of scope.

public CarComponent()
   {
       Car car1 = new Car(HUNDRED, HUNDRED);
       Car car2 = new Car(200, 400);
   }

2) Consider the placements of the cars in relation to your specified frame size.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to elaborate a little on "can't get this to work". That's a bit vague.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you don't want to allow them to even type anything but numbers into field, you need to use the MaskFormatter: http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html#maskformatter
(Which you will see is covered in the first link I posted above on using JFormattedTextField)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Those things are covered by the tutorials that I linked above.

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

Thanks for posting generic information on a Collection for whoever might randomly need such, but it doesn't change the fact that the actually return type of that collection can only be ascertained by the api itself. Perhaps you need to reword your original question, because based upon this last post above it's not very clear what you are wanting to know.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is absolutely no way to tell the type of the collection from that line of code. The return type of that method will be documented by whatever API describes the class of "searchQuery1".

The question about "search" vs "Search" doesn't make any sense - it's your variable declaration, call it whatever you want.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Read the error message closely, they are pretty clear about the issues. You are calling things that do not exist in the parent class in that first file. The second file has structural problems such as a missing brace or semi-colon.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't delete objects - they get cleaned up when they go out of scope and have no more active references.

Perhaps this article will answer your questions: http://www.ibm.com/developerworks/java/library/j-jtp01274.html

(though next time, you don't need to put 15 questions marks on them - one will suffice)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

After you added your mouse listener, the mouseListeners collection contained 2 listeners: The original BasicButtonListener, and the one that you added. That code b.removeMouseListener(b.getMouseListeners()[0]); removed the BasicButtonListener because it was at index 0, leaving yours still in place.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your button already has a mouse listener installed before you add your own. The button starts with a BasicButtonListener by default. Your action listener is removing that listener, but leaving your own mouse listener in place.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

OMG.. I stated my intake on the subject..2012, the End of the World? And.. lmao.. everyone got their panties in a wod.. Pick me apart like buzzards. I don't care.. lol

You give yourself too much credit.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Very nice quotation indeed!

For the folks who believe that there is no God, please tolerate those of us that need God in our life. A simple request.

Conversely, please accept that some of us do not. Our simple request is that need be kept as a personal matter and out of our schools, laws, government, and international dealings. Simple enough from our point of view anyway, obviously not so for the majority.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Edit: nevermind... not even worth getting into...