JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like that, but with arrays. There's no point doing that with ArrayLists.

Stuugie commented: Thanks for helping with my helping confusion +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can't. An array size is fixed when it is created, and cannot be changed.
All you can do is to create a second array of the right size, copy all the entries into that one, point any reference variables to the new array, then allow the original array to be garbage collected.
Or use an ArrayList.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You haven't given much background to help anyone pick the rigt answer, but, in general, if the columns are of various types, then you would be pretty safe with creating a class to represent one row (instance variables for each column) then having an ArrayList of those instances to represent all the records.
Of course it's highly possible that something you didn't mention in your post could completely change that answer...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why Java is platform independent?

Because it's sometimes a very good thing to be able to write and run the same software on Windows/Linux/Mac.

And how to set path in Java?

That depends on which platform you are using (which demonstrates the practical limitations to complete platform independence!)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

See the Java Language Spec 14.14 - it makes this very clear...
http://docs.oracle.com/javase/specs/jls/se5.0/html/statements.html#14.14

Stuugie commented: That's a great link! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your paintComponent you need to paint all the lines and all the rectangles etc. That's one loop thru the lines array, folowed by one thru the recs array (etc). The code you posted just paints lines, and there's a variable ShapeType that makes no sense

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's a little demo I wrote a while ago that runs on Java 7 and has a transparent/shaped/undecorated window (JFrame window2). Maybe you can find what you need to know in this code? I remember that the order of the setUndecorated/setBackground/setOpacity/setVisible is critical. J.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.lang.reflect.Method;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;


public class DemoWindows implements ActionListener {

   public static void main(String[] args) {
      // create a new demo, and update it every 50 mSec
      new Timer(30, new DemoWindows()).start();
   }

   int phase = 0; // demo runs a number of consecutive phases
   int count = 0; // each of which takes a number of timesteps

   JFrame window1 = new JFrame("Java windows demo");
   JLabel text1 = new JLabel("<HTML><H1>Hello" + "<BR>Everyone");
//         "<HTML><H1>This is a demo of some of the effects"
//         + "<BR>that can be achieved with the new Java"
//         + "<BR>transparent window methods</H1>"
//         + "<BR>(requires latest version of Java)");
   JFrame window2 = new JFrame("Java windows demo");
   JLabel text2 = new JLabel("<HTML><center>Java<BR>rocks");

   int w, h, r, x, y; // parameters of iris circle

   DemoWindows() {

      // build and diplay the windows
      window1.add(text1);
      window1.pack();
      window1.setLocationRelativeTo(null);
      window1.setVisible(true);

      window2.setUndecorated(true);
      window2.setBackground(new Color(0, 0, 0, 0)); // alpha <1 = transparent
      window2.setOpacity(0.0f);

      text2.setFont(new Font("Arial", 1, 60));
      text2.setForeground(Color.red);

      window2.add(text2);
      window2.pack();
      window2.setLocationRelativeTo(null);
      window2.setVisible(true);

      // parameters of the smallest circle that encloses window2
      // this is the starting pouint for the "iris out" effect
      w = window2.getWidth();
      h …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you add lines etc in your mouse handler there's no way for Java to know that this will affect the way the panel is painted, so the paintComponent won't get called. After updating the Lines etc, call the repaint(); method for your drawing panel, so Java will schedule an update of the panel and call your paintComponent.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I think we'v exhausted this one now. No more posts that aren't directly relevant to the original topic please.
Thanks
J.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello the_yuo

You keep saying what you want. You are not prepared to try the excellent advice you have been given, so you do not understand how your existing code works. let alone understand how to change it.
Unless you are prepared to show some effort in trying to help yourself I'm going to close this thread.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check the JOptionPane documentation. There's a method that allows you to give a prompt (eg "Enter file name") and get the answer back in a String

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Start with one simple validation, get it working, then repeat that pattern.
Here's a typical pattern for inputting one value and validating it, with an initial prompt, and a different re-prompt after errors:

display normal request for input
while (true) {
   get user input
   if (user cancelled) exit program // give user a way out if they can't get input right
   validate user input
   if (input is valid) break;
   display error message/re-prompt for input
}

the "validate user input" may involve catching an exception, but you can handle that right there and generate an error message, so the structure remains simple.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

NEVER NEVER NEVER ignore an exception when writing or debugging code!
Java has created an instance of SQLException packed full of debugging info for you, and you have chosen to ignore it. Bad move.
Repeat after me: e.printStackTrace() e.printStackTrace() e.printStackTrace() ...

:)
J

somjit{} commented: that was fun to read! :D and it worked :D +3
riahc3 commented: Step 0 should be this +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's always a good idea to protect your program from bad user input. The alternative is just to let it all crash, which will upset the user and reflect badly on your programming skills!
It's not hard - a simple loop that keeps prompting the user and validating the input until the input is valid. You are going to have to do this in almost every program you write, so it's a bit of an effort to get it right the first time, but then you'll know how to do it and the rest will be easy.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no problem using an s format for enums - print will actually use the enum's .toString() anyway, so you can use a fixed-width string format like
printf("| %6s | %6s | %6s |", board[0][0], board[0][1], board[0][2])
Where it all falls down is if you want to center the shorter strings in their width - there's no format for that so you have to do tacky stuff with calculating how many blanks to add (AFAIK)

ps
boolean squareStatus = false;// needs comment because you have no idea what true or false would mean much better just to give it a good name, egboolean squareIsFull = false; // obvious what that means!`

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can tell for yourself if it's right or not by testing it

Why do you hope it's not right?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I thought that was quite funny.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Calls to instance methods are resolved at run time, so when you call addAll or add from an instance of InstrumentedHashSet the JVM looks for versions defined in InstrumentedHashSet, and only looks for them in HashSet if they are not overridden in InstrumentedHashSet (unless you explictly use the super keywod which makes the JVM start looking for the method in the current objects superclass).

Don't worry too much about the addAll doc - addAll is defined in java.util.AbstractCollection, which does not have a proper implementation of add, it just throws the unsupported exception. When you subclass java.util.AbstractCollection with a non-abstract class you will have a real add method, so everything is OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

bguild's solution is certainly the simplest, and is probably all you need, but for future reference here's the general way to add any amount of into to an Execption:
Create your own Exception by extending Exception, add the extra info to the constructor, have accessors for that info (or just make it public final), eg

class BadJokeException extends Exception {
    public final String theJoke, theComdian;
    public BadJokeException(String message, String theJoke, String theComdian) {
       super(message);
       this.theJoke = theJoke;
       this.theComdian = theComdian;
    }
}

... then you can create, throw, catch and query a BadJokeException just like any other Exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need a loop that processes one search at at time. A do-while loop is ideal,eg (pseudo-code)

do {
   // search for book, show price etc
   prompt for continue 1/0
} while (answer is 1);

within that, in place of the "prompt for continue 1/0", you may have another loop to reject answers that are not 1 or 0, eg

   do  {
      prompt for continue 1/0
   } while (answer is not 1 or 0);

I'll leave the Java syntax up to you

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can write Java programs to perform math calculations, solve equations, plot graphs etc, but that requires you to understand what you are trying to do. If you don't undertand the math, writing a Java program isn't going to help, in fact it will just add a whole load of confusion.
Have a look on the web, there are many sites that will teach you any math topic you want. Once you understand the concepts and equations you can start to use Java to perform the calculations.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not familiar with dtexec, but isn't /f part of the arguments, not part of the command itself? And isn't the final .dtsx part of the first argument?
I would have guessed
{"dtexex","/f C:\\EconAnalysisConferenceBoard\\EconAnalysisConferenceBoard\\EconAnalysisConferenceBoard\\ConferenceBoardETL.dtsx"};
(note space between /f and c:), or maybe
{"dtexex","/f", "C:\\EconAnalysisConferenceBoard\\EconAnalysisConferenceBoard\\EconAnalysisConferenceBoard\\ConferenceBoardETL.dtsx"};

Stuugie commented: Thank you for trying to see me through this, I really appreciate it! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Something like this...

String[] runParameters = {"command", "arg 1", "arg 2"};
// array of strings, first is command, following are the args required for that command
Runtime.getRuntime().exec(runParameters);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ProcessBuilder is nowdays recommended over Runtime.exec, but in this case there's probably no real advantage. The main thing is to pass the dtexec and its parameters in separate elements of a String array, not just as one String.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A lot depends on how robust you want he to be. A simple public static getInstance with a private constructor that's called from a static initialiser block is good enough for some situations, but there are all kinds of problems in a multi-threaded situation, or if you have multiple class loaders or if you use serialisation.
This discussion covers the options pretty well, but in short, since java 1.5, the preferred solution is to have an enum with a single value

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The version of exec that takes a single String as its argument is full of problems if you have a command with arguments, or spaces or quotes anywhere in it. It tries to parse the command/arguments itself and often gets it wrong.
There is a version of exec that takes a String array as its parameter. Put the command (executable) in the first element, and the argument(s) in the following element(s). No need to put quotes round any of them. This avoids all those problems.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hang on a momemnt...
I compiles, but it won't exactly do what you need.
When you call original_image.getSubimage(x,y,w,h); that creates a new BufferedImage containing just the sub-image. The original BufferedImage is unchanged. So you are returning the original image, not the subimage.
You need to use the sub image that the getSubimage() methods gives you. Your original code (lines 15,16) got that part right, it just had the wrong syntax after the = for calling the method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks 99% right!
getSubimage (note capitals - Java is case-sensitive) is a method in the BufferedImage class, so you need an instance of BufferedImage to call it, eg
myImage.getSubimage(0, 0, 100, 100) returns the top left 100x100 pixels of myImage as a new BufferedImage

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Step one is to disentagle your current GUI from the code about pizzas that you will need in the GUI version. eg at lines 23-35 you could create new method eg choseSize(int size) and move the code from lines 24-35 into it, so the code now reads:

choice = inScan.nextInt();
choseSize(choice);

After you have done that for all th existing code it will be straight forward to call those same methods from a JButton or whatever GUI design you chose.

This is an example of separation of "model" and "view", which is a key architectural pattern seen throught Java

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Around line 8 you know how many bullets there are in enemyBulletStore, so maybe you could use that to pick a counter value for the next bullet.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just read the API documentation for the String class - it's all explained there
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#String%28byte[],%20int,%20int%29

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1 arr is an array of ints, setText needs a String, so you need to convert your value
2 SetText replaces any existing text, so setting it in a loop will just show the last value; you need to append att the text together.

One way is to start with an empty String before the loop, then append all the values to that String inside the loop (you can append ints etc to a String, Java will convert automatically), then use it to setText after the loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That code looks like every Boss fires a new bullet on every pass through the game loop - that's a lot of bullets. Or is there some other code that determines how often a new bullet is fired?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's nothing to do with Parent/Child. It's because you have an executable statement (avg = st_marks/2;) that's not inside a method or other executable block.
You could do that as an initialisation expression as part of the declaration of avg...

dlgmu537 commented: Thanks +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You seeem to be confused about the Date class.
A Date object represents an instant in time, and has methods to access it. It does NOT have a format. When you convert a Date to or from a String that's when a format is applied.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, Java isn't limited to any one drive. If the path is valid Java will work with it.
Sorry, I still don't understand what you are asking about the \ characters. If you want a \ in a Java String you have to code it as \ in your Java source code. Ifthe user is inputting it in a dialog box then a \ is a \, no problems.

ps: If you are asking the user to pick a file did you look at using a JFileChooser? It's much easier for the user, and avoids problems with mis-typed paths etc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Given that you are relying on user input here, it would be a good idea to do some basic validation before trying the exec. eg
new File(location).exists()
will return false if the user has input an incorrect path, so you can re-prompt for correct input immediately

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is a real Lulu! The hardest I've seen for some time (but here's the solution)

If you use the method exec(String s) it assumes you may have a command and some arguments in s, and it attempts to split them up using blank as a delimiter - hence the problem you see.
If you use exec(String[] s) then it assumes s[0] is the command (executable) and any arguments are already parsed into s[1] etc. In that case the executable and erguments are not parsed.

So the solution is simply to pass your executable as a one-element array, not a simple string...

     String[] dummy = {Location};
     p=r.exec(dummy);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What did you do with the String that the format method returns? I KNOW you are a better Java programmmer than this.

riahc3 commented: Java is completely crap. Thank you. +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm worried. This thread has become very unheathy - just look at the number and kind of questions that are being asked. I know you have the Java skills to answer many of them yourself, and I don't think I'm providing the right kind of help any more.

So this may br my last post in the thread (maybe)...
Yes. Answered. What makes you think that that code will do anything other than print result (a double) in a system default format?
If you don't know how to use a NumberFormat then read the API doc, read the examples, Google if necessary. Don't just guess. The mistake in your code is a very elementary one.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The idea of pseudo-code is to capture/plan ypur logic without getting buried in the details of Java syntax or API method signatures. If you were writing this code for a non-programmer end user you may even be able to go through bits of the pseudo-code with him/her to confirm that you have understood the requirement properly. From your viewpoint it should be at a level of detail where you are confident that you can convert it to real code without having to re-think the overall logic.
So in some places the pseudo-code could represent a lot of simple java code:
prompt the user and get/validate name, birthday, employer, salary
but if it's some very convoluted data structure algorithm the pseudo-code may look very much like Java loops & snytax.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Commenting standards do vary, and for a school assignment you do do what the teacher wants! I don't think your comments were "bad", and some were excellent. I would not deduct any points for that.

Just ask yourself - would a Java programmer understand that line or block of code? If so then it doesn't need a comment, if not then either improve the names you use, or add a comment.

Personally I think your code is pretty good. Well done.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every time you call getDays you increment the elements of dayCounts - I can't see any code where its values are reset. Eg the loop counter on line 36 calls getDays each time the loop is iterated, each call incrementing dayCounts.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java SE JRE 7 update 21 is now available, with fixes for dozens of security-related issues. Immediate installation is highly recommended. Head on over to Oracle's Java download page and grab it now. There is also a version for Java 6 users, if any such animals still exist.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Re: comnments
Your commenting varies widely, some is excellent and some of it is redundant.
You should write your code with meaningful names so that someone who knows Java can read it easily. Comments like line 37 or 85 just clutter the code to no benefit.
On the other hand, you have some very good commenting, eg lines 312-315. Comments like that explain the overall content and strategy of what will follow, and any Java programmer will be able to read what follows and understand it perfectly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... ou dont need to write how a set of code conventions state ...

Possibly the worst advice of 2013 so far in this forum. Even if you never write a single program for real, even your teacher will read and mark your code. Coding standards and conventions are there to help everybody, and the sooner you engrain all the right habits the better.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Before you get carried away with more advanced apps, there's a lot more you can learn from this one. eg

  • use a proper layout manager (eg GridLayout) rather than the un-portable null layout
  • replace all those repeated variables and repeated blocks of code with an array of JButtons and a loop
  • use Actions to define and handle the responses to the buttons and the keyboard (via Key Bindings) consistently
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are going to need 26 of some kind of 2-dimensional array that shows where to print the As in in large block of As, the B's in a large block of Bs etc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Liuqahs suggested an enum, which is generally a good idea, but if you haven't learned those yet you could use a simple boolean, eg
boolean playOnce = (true or false depending on the type of Sprite)
then if it's true you stop the animation after the last frame, but if its false you go back to the first frame