Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, you don't have a no-argument constructor defined in the class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

They are in different packages, so you need to import those classes or put them in the same package as the inventory class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are better off using a regular expression pattern for things like that. Here's a tutorial link: http://java.sun.com/docs/books/tutorial/essential/regex/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That is part of the "Commons-lang" jar, you can probably figure out where it's residing by looking in your library references in Eclipse.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is another good source for small code snippets demonstrating all kinds of things in Java:
http://www.exampledepot.com/index.html

It only covers Java 1.4, so newer language features in 1.5 and 1.6 will be missing, but most of it is still very relevant.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Sun tutorial should cover it pretty nicely: http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html

Keep that Swing tutorial trail bookmarked because there is a wealth of info and demo code on using the various components.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's in the list in the second link that you posted above, but it's the last one. I haven't tried any of the others (I have enough to do without playing with different install builders and IzPack worked :) )

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

We use IzPack here and it works fine for our purposes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

While not really being "infinite", while(true) { } loops are seen fairly often in concurrent processes for things like polling for tasks in a work queue. They execute in a try-catch block for InterruptedException and that provides the mechanism for shutting them down gracefully.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to take a look at the free online book Thinking In Java, 3rd Edition. It is a bit dated since it doesn't cover any of the Java 1.5 or 1.6 changes, but the language basics are still solid and you'd probably find it a good reference for questions like this.
If you prefer an offline copy, you can download it as a PDF here: http://mindview.net/Books/TIJ/DownloadSites

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

...I am using the java.awt.Graphics.drawString and drawImage methods to draw each part of my object. If I have set my graphics component's font to have a size of 12 say, does this mean that each character takes up 12 x 12 pixels?

No, it's a little more complicated than that, but still easily available. You'll need to call Graphics.getFontMetrics() to obtain the font metrics for the current font. FontMetrics provides methods for obtaining dimensions of a particular string for that font and graphics context, such as getHeight() and stringWidth(java.lang.String). That should be all you need to center up any given string on your image.

Edit: You can find more detailed info on FontMetrics and handling text in the graphics context if you need it in the 2D graphics tutorial: http://java.sun.com/docs/books/tutorial/2d/text/measuringtext.html

darkagn commented: Thanks for the tips :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The only way that you would be able to set the system time is through JNI calls to the OS.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are some, but I would say they are fairly trivial. Both are good open-source IDEs and really the choice will come down to your personal preference. Try them both and use the one you like better.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Between the built-in help, the Start Page (Help > Start Page), and this tutorial http://www.netbeans.org/kb/60/java/quickstart.html (which is actually the one that the Start Page takes you to), you should have plenty of documentation available.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, Calculator actually uses Fraction, so really Fraction should be an inner class of Calculator if you have to combine them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, this statement

update.updateScore();

is not updating the panel that is in your frame. It's being called against the local "update" variable that you created. You need to change the constructor to initialize a class level "player" instance variable instead of the local one that it is creating now (see my previous post) and call the updateScore() on that instance variable. Currently you don't have a reference to that instance to work from. (Whereas you do with the "correction" call that is currently working for you in that handler)

If you want to keep the panels as separate classes, I would recommend moving the JLabels that go in those panel into those classes and not have them in your top-level JFrame class. Let those panels handle their own components. There is no reason that updateScore should have to set text on a label that is defined at the JFrame level. Having them each extend JPanel is fine, but keep their functionality encapsulated as well, otherwise you are not gaining anything by separating them. Also note that you don't have to put those objects into other JPanels just to add them to the frame - they are JPanels themselves - just add them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you don't say what labels you are having trouble updating, but some things really stand out as a problem. In your constructor

JPanel playerpan = new JPanel();

You're defining this as a local variable - not initializing your class level "playerpan" variable. Same with the other panels. This means that you essentially have no reference to those panels outside the constructor. Aside from that, why does player extend JPanel but refer to components in the enclosing class? The only variables in "player" are two strings. This is a rather odd tangle of component classes.

As for the label update, this is most likely due to this line in your button handler

player update = new player();

You are creating a new separate "player" instance and calling the update method on it - not the one that you actually added to your JFrame.

toomuchfreetime commented: Great help thanks a lot!! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You want to add that action listener to jMenuItem1 instead of jMenu1. Also, you aren't showing the dialog. I would recommend using the static JOptionPane method to show the dialog

JOptionPane.showMessageDialog(NewJFrame.this, "You pressed New.");

.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you can do it with reflection like this

private static int getSomeNumber(Class<? extends Object> c)
{
    if (c == Mystery.class)
    {
        try {
            Class<Mystery> thing = (Class<Mystery>)c;
            Method m = thing.getDeclaredMethod("getNumber", (Class[])null);
            return (Integer)m.invoke(null, (Object[])null); 
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    return 0;
}

But whether you should is another thing altogether. What is the fear of using objects there? Reflection isn't exactly the fastest thing in the world either, so if you're worried about creation time of objects then you may find using reflection no better. Are the objects very expensive to create? If so, can you use lazy initialization to defer some of that expense and keep the contructor light?

I'd say there are more design issues raised by this than answered.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you certain of the SMTP address and are you certain that Yahoo will accept STMP connections for this account? It appears that is limited to paid Yahoo! Mail Plus accounts - not the free ones.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Invalid SMTP address? Wrong port? Invalid user name? Invalid password? Check those things.

Beyond that you will probably have to post some code, since it's hard to see over your shoulder from here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, yes, static methods can be called directly on the class by ClassName.methodName(). Is that all you needed to know or is there something more specific to your question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

StringTokenizer is considered a legacy class now and it is recommended to use String.split(java.lang.String) or the java.util.regex classes for this now.

With split() you could first split on the math operator, giving you the two operand strings, and then spilt those into the whole and fractional strings, and then split the fractional into it's numerator and denominator. The one issue you may face doing that is your fraction separator "/" is the same as the division operator "/". If you can be certain that the operator will have blank spaces on both sides, it becomes much easier.

Give that a try and see how it goes. Even if you must use StringTokenizer due to some professor insisting you use legacy classes (does he know it's a legacy class?), still it may help if you consider that you don't have to parse the string in one shot from left to right. You can parse it into separate pieces and then parse those pieces into other pieces and so on, which can make the problem much cleaner to approach.

darkagn commented: good tip +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
String result = "Is not included.";
for(int i = 0; i < 7; i ++) 
 {
  if(team.group.toys[i].getName().equalsIgnoreCase(name )
      {
        team.insert(team.group.toys[i].getDescrip());
        result = "OK";
        break;  // no reason to keep looking here
       }
}
System.out.println(result);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just to clarify the question, the printing of "Ok" part works fine if the match is found, but you don't want it to also print "not included"?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, use "\\\\" then.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
String newString = oldString.replace("\\","\n");
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See comments in the code

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;

public class HeartLandHomeFinance2 extends JFrame {

    JPanel Panel;
    JLabel lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10, lb11, lb12, lb13, lb14,
      lb15, lb16, lb17, lb18, lb19, lb20, lb21, lb22, lb23, heading, lb24;
    JTextField jt1, jt2, jt3, jt4, jt5, jt6, jt7, jt8, jt9, jt10, jt11, jt12, jt13, jt14, jt15, jt16, jt18, jt17;
    JButton bt1, bt2;
    GridBagLayout gb;
    JScrollPane jscrollpane;
    GridBagConstraints gbc;
    JComboBox combo1, combo2, combo3, combo4, combo5, combo6;
    Connection con;
    PreparedStatement stat;
    Statement stmt;
    ResultSet rs;
    Font f;

    // this constructor was not valid - constructors don't have a return type
    // explicitlly stated, because they always return an instance of the class
    public HeartLandHomeFinance2() {
        // you don't need a new Frame here
        // your class is a JFrame
        // I moved the frame calls into createAndShowGUI() as well
        createAndShowGUI();
    }

    public void createAndShowGUI() {
        setTitle("Heart Land Home Finance");
        setDefaultLookAndFeelDecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        Container contentPane = getContentPane();
        // you have to initialize gb before you make the setLayout call
        // you were using a null layout because gb was null
        gb = new GridBagLayout();

        Panel = new JPanel();
        Panel.setLayout(gb);
        Panel.setBackground(Color.RED);

        gbc = new GridBagConstraints();

        f = new Font("Monospaced", Font.BOLD, 24);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridwidth = 3;

        heading = new JLabel("Heart Land Home Finance");
        heading.setForeground(Color.black);
        heading.setFont(f);
        Panel.add(heading, gbc);

        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 5;

        lb1 = new JLabel("Please Fill All The Fields in CAPITAL LETTERS"); …
tactfulsaint commented: your gud +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Making those variables "protected" would also allow subclasses to access them.

(Of course, that may lead to some design traps by locking your base class into a particular implementation, but I doubt you really have to worry about that in this case :) )

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's somewhat dependent upon what "com.toedter.calendar.JDateChooser" returns when you call getDate() if nothing has been chosen. Does it return a null? A default date? If you were just checking for a valid date from a string you'd just catch the exception thrown by SimpleDateFormat.parse(). Since you're using some custom component to return the date though, you'll have to figure out what it's returning for no selection.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post your code then, because the code you posted above does not have a single line that attempts to set the image and we can't read over your shoulder here.

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

Yes, for your purposes a simple array of String would be all that was needed.

import java.io.*; 
public class Problem2
{


  private static BufferedReader stdin =  new BufferedReader( new InputStreamReader( System.in ) );

  public static void main(String[] arguments) throws IOException
  {
    System.out.println("Welcome. How many names do you wish to enter?");
    String input = stdin.readLine();
    int nameCount = Integer.parseInt(input);
[B]    String[] names = new String[nameCount];[/B]
    for(int i = 0; i < nameCount; i++)
      {
	System.out.print("Enter name: ");

	//NEED HELP HERE
        [B]names[i] = stdin.readLine();[/B]
      }
  
  }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your best bet is to construct a GeneralPath with the points from the mouse listener and use the Graphics2D.draw(Shape) method to render it. You can append to the GeneralPath as new points are added, so you don't have to even maintain a point collection at all.

Examples of this can be found here: http://java.sun.com/docs/books/tutorial/2d/geometry/arbitrary.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Checking for the comma first could affect more than just where to split the string. For example "Joe Smith" indicates first name and then last name, whereas with the comma the last name appears first "Smith, Joe". So you have two different parsing operations to perform.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look at the api doc for indexOf(). It returns -1 when the string is not found in the target string. You are searching for a comma in a name that does not contain a comma in your driver class. The test name in your class does have the comma so it works fine for that one.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That is a lot more code than is needed. The conversion only needs the evaluation of intVal!=0, so the function reduces to

boolean intToBool(int value){
  return (value != 0);
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could add the file names to a HashSet as you download them. The add() method will return false if the set already contains the item, at which point you could alter the filename, add it to the set and then write it to the zip stream.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

(i != 0)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I have a good idea what I am supposed to put but I can't seem to get it right. I have two different files, Server.java and Client.java. I want Client.java to call a method in Server.java. This is what I have figured out so far.

public class Client{
public static void main(String[] args) {
Server otherInstance = new Server();
otherInstance.instanceMethod();
Server.staticMethod();
}
}

I am a complete novice but I think I have to replace the word "other" with the method I am trying to use from the file, Server.java? Any help would be greatly appreciated.

No, you replace "instanceMethod" with the name of the method, unless it is declared to be a static method in Server, in which case you replace "staticMethod".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, it took about 2 seconds to find with Google:
http://en.wikipedia.org/wiki/Pi#Calculating_.CF.80

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In short, you can't clear the console without system specific calls. You can write a bunch of blank lines to scroll everything to a point it looks clear, but that's about all without "workaround hacks".

If you want full control of the screen that you are running in, you should make the application a GUI application.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think the null pointer exception is occurring from the printStream.println() call, rather than the exec() call. You haven't initialized "printStream", so when the error from that exec() command is thrown (which is that "cls" is not a program, by the way), the catch statement is throwing the exception out to main().

To execute a command, you have to use "cmd /c <command>". However, if you are expecting that command to clear the command window in which you are running your program, it will not. Runtime.getRuntime().exec() creates a new separate process.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't see any reason why you would need "threadMain". The monitoring threads can run just as well in a single main application/controller context. You certainly don't want those threads to be statics. They should be private members of whatever class is acting as the controller context of the application.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, it is not possible. Main() is the only method that can be run with the "java myClass" call from the OS.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You actually do not need classes for the input at all, as they are just making a single call to show your input dialog. A class isn't needed to wrap a single function call. You can put a small helper method in your Calculate class which handles the input part

public static int getInput(){
  int inputValue=0;
  try {
    String input = JOptionPane.showInputDialog("Please enter an integer");
    inputValue = Integer.parseInt(input);
  } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null, "Entry is not a valid integer.");
  }
  return inputValue;
}

and simply call that method to get your inputs in the main() method. (The method has to be declared static to be used from main() )

int input1 = getInput();
int input2 = getInput();

The class to evaluate the numbers, let's call it Evaluator, should have a separate method for each function that you want it to perform. Each should take the number to evaluate as a parameter and return true or false for the evaluation.

public boolean isGreaterThan100(int value){
  // your code here
  // return true or false if value is greater than 100
}

public boolean isNegative(int value){
  // return true or false if value is negative
}

This separates the functionality of the evaluator to it's individual parts and clearly indicates what it is supposed to do for you. Furthermore, if you wanted the isGreaterThan100() method to be more widely useful, you could let it take two integer inputs : the input value and the value you want to compare …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not in his case, if the change is 0.38, he would want dimes to equal 3, not 4.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why do you need to run the OS command instead of using File.delete()?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Can someone please suggest...

Yes, and I did.