Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The constructor difference, while it is an error, has nothing to do with the "Cannot find symbol" error. You need to make sure EmployeeInfo is in the same package as "PayRoll3" or add an import statement for that class. The compiler cannot find the class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The error also tells you which symbol (name) cannot be found and the line on which it occurs. Please post the exact error text if you cannot locate it based on the compiler information.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, thinking on it a bit, it seems the deck should just contain a method deal() that returns a single card. The Game class should be responsible for seeing that each Player gets a card dealt until they have the required number.
In pseudocode:

for (numberPerHand) {
  for (numberOfPlayers) {
    player.take( deck.deal() )
  }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would think your game class would have a variable for number of cards in a hand. The deck class could contain a method deal(numberOfCards, numberOfHands) that returns a Set of Hand instances. This would keep your deck independent of the game and not tied to the specifics of your game. Since you have shuffled already, dealing to the Hand instances can be just like a real game, one card per hand until all have the required number of cards.

A Hand class would really just be a List of Cards with a few methods like add() and discard(). The game class would be responsible for evaluating a Hand, since that is specific to the Game and not the Hand.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Glad you got it working the way you want.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would imagine that you are either resetting total or newtotal is not being captured like you think it is, because there is nothing wrong with that operation (except that you could use total += newtotal; instead).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Um, you can 0 to a value all day and it won't change...

total = 5;
newtotal = 0.0;
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If that is supposed to be a method, then it is not a valid declaration at all. There is no type information for the parameters and method declarations do not end in a semi-colon (unless it's an interface or abstract method).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What exactly are you trying to do on that line of code? It doesn't appear to be a valid statement at all.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, most threads never get marked Solved in the Java forum either. Some never even get a "thanks, that worked" response to give any indication that the issue was resolved.

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

Issues that I see:
1) Logic is hard-coded to 3x3 board. Array positions, bounds checks, adjacency checks are using literals in many places.
2) Heavy repetition of if() blocks that are nearly identical, especially in the blocking() method. These could probably be replaced with a parameterized method or by adding a second array dimension loop and converting the checks to use relative indexes instead of the hard-coded positions.

The code is certainly not awful, just a little bit raw and literal. These are just things you might want to think on if you want to handle the logic a little more abstractly. Take a step back from a fixed 3x3 board and consider the nature of the operations you need to perform in terms of relative positions within a square grid. Also moving some operations into clearly named methods, which can help with clarity and organization in addition to limiting repetition.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hi! i am gettin the same error messge when i declare an object of a class. though i have initialised it to null while declarin. pls have n look at the code n reply if u find ne of my silly mistakes or is java just wierd..
<snip>

Do not tack questions on the end of old threads. Start a new thread if you have a question and lose the "text speak". If you are too lazy to write actual words, then I can't see why anyone should take the time to help with your problem.

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

I don't believe you can make the component not fill the cell, but you can add a border to the button in the custom renderer

class ButtonCellRenderer extends JButton implements TableCellRenderer {
    private Border MATTE_BORDER = BorderFactory.createMatteBorder(2, 3, 2, 3, 
      UIManager.getColor("Table.background"));

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {

        setBorder(MATTE_BORDER);

        // ...

        return this;
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sure, let me write them all up in Word with step-by-step explanations and I'll post them in a few days. Just keep checking back here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is I am not very educated in Qbasic and my teacher has given me a project of making a hangman game.

Yes, that is a problem. The best way to get educated in it is to actually do the assignments you are given.

If you help me I will always be thankful to you.

No, you'll be a cheater that expects to receive credit for work you did not complete.

The death line is the day after tomorrow I know its too late but still u people are my only hope..

I guess you will just have to face that "death line" then. Good luck.

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

trim() is a method of the String class that returns a copy of the String with leading and trailing spaces removed.

String original = "  blah  ";
String trimmed = original.trim();
System.out.println(trimmed);
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

Middle-clicking the image view overlay (or whatever that is that pops over the screen) in Firefox will just open the underlying thread in a new tab. Right-clicking and choosing View Image does show an uncluttered version of the image though.

The garbling of the image seems to be related to whatever that overlay component is that shows the image attachment.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Image text mostly unreadable here. 1280x1024 on Firefox 2.0.014.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i think i have to use a stringbuffer but i don't know where to use it

In the translate method - and use StringBuilder instead of StringBuffer.

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

It was a conspiracy by the folks who make plastic tamper-proof seals :P

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

That is exactly what can be found in the "Read Me" post which is stickied at the top of this forum: http://www.daniweb.com/forums/thread99132.html

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

For starters, this is not a valid method body

public void init()

This is

public void init() {
    // stuff
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Nope, this isn't a homework service. You need to make an effort on your own first. If you have problems, post your code and the errors or specific questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You really don't even need to have a 2D array. The single 1D array is fine for a uniform rectangular grid, with rows being nothing more than an offset into the array.

I hesitate to say any more though since it's a homework situation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, tech is an ever changing subject - seems only right that it wouldn't stay in the same place long :P

majestic0110 commented: hehe +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Change your print methods to return the Strings you want, rather than actually sending output to System.out. Your GUI class can then put those strings wherever it wants to. If fact you could just override toString() to return the string representation of each of those objects and do away with print() methods altogether.

An alternative is to pass a reference to a text component to each print method and let each of the objects "print" to that instead of the console, but it does limit your flexibility a bit (i.e. you can only print to a JTextComponent or whatever you decide to pass as a parameter). Overriding toString() lets you get a custom string representation for any of the objects and use it as you please.

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're on the right track generating the list of numbers 1 to N*N into an array and then shuffling them. You just need to consider how to pick a random place in the array to place each number.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are only reading a single word here

message = sc.next();

Use nextLine() to read the entire input line

message = sc.nextLine();
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

Just drop the call to set hours to be less than twelve

hours.setValue(hours.getValue() - 12);

and leave it in 24-hour time. You can display it in 12-hour format without altering the underlying value.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In the mousePressed() method, use the following

int bothMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK;
    if ((evt.getModifiersEx() & bothMask) == bothMask){
        // do your thing
        System.out.println("Both down");
    }
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.