masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, setImage needs to actually assign the image given to an instance variable, of course. Otherwise, bi, essentially, doesn't exist anymore once the setImage method is finished, of course.

And don't override paint, and definately do call this setImage from within paint or paintComponent.

Here, in pseudo code

class PhotoPanel extends JPanel {
  BufImage bi;

  void setImage(BufImage localBi) {
    // do whatever with localBi
    bi = localBi
  }

  void paintComponent(Graphics g) {
    super.paintComponent(g);
    G2D g2d = (G2D) g;
    g2d.drawImage(...)
  }
}

class main {
  void main() {
    photopanel p = new photopanel();
    displayGui
    askForImageURL
    BufImage bi = loadImageFromURL
    p.setImage(bi);
    p.validate();
    p.repaint();
  }
}

That's all there is to it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Drop lines 27 & 28. That is exactly what I told you not to do.

Also, the setImage method should take an image as an argument, not open any GUI and ask for one. IOW, you should ask for and load the image elsewhere and pass the loaded image to the PhotoPanel.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And, are you able to "connect" to the device? If you can't do that there is no need to go any further. Then, once you can, simply open the stream, read a fair amount of the bytes (simply use the read(array) method) and write those to disk somewhere, than start to study the data (probably with a hex editor first). Once you know what is sent on the signal, and how it is sent, you can start to manipulate it. All of that (except for the specific read method mentioned) is also language independent. You might try Google to see if anyone else has already done some part (or all of the above) already and posted their findings. That way you can cut out some of your own time. Otherwise, you are in for some long nights.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Add a single JPanel to the JScrollPane. Use FlowLayout with vertical (or horizontal, depending on which way you want to "scroll") alignment in that JPanel, and add the JPanels that are to be added "dynamically" to that JPanel. Then, don't forget to call validate() and/or repaint() on the JScrollPane.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Nothing to do with Java, to tell you the truth. The signal that the Wii uses, and what (and how, i.e. in what form) data is transmitted/received over that signal is what's at issue, and that is completely language independent.

Try to find the signal, then read the bytes from it, and study those. If it's bluetooth, its bluetooth, so get yourself a bluetooth adapter for your pc, and see if you can "hack" into the signal.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That is not a portability issue. You do not simply grab a components graphics and paint to it, as that "painting" will be "removed" the next time the component refreshes. You need to rewrite this "PhotoPanel" class and give it a "setImage(image)" method and then, in that class, override paintComponent to draw the Image. Then you call setImage(image) followed by validate() and/or repaint().

masijade 1,351 Industrious Poster Team Colleague Featured Poster

replace all single slants with double slants before (or while) calling "aregex".

str.replace("\\", "\\\\")

note: replace, not replaceFirst or replaceAll.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You can't.

I am not going to take forever to describe this so think about it a bit. Rather than applying the "toLowerCase" and "nextToken" immediately, set a boolean variable to true, then, on the next iteration, when that variable is true, do the "toLowerCase" and set the variable to false.

But, it's not as though you're doing much with the stuff, so I see no reason why you can't simply perform the actions you're performing then and there.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

this

st.nextToken().toLowerCase();

produces a new String object. what are you doing with it? It also, of course, consumes the next token in the String.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A String is immutable. You can "change" the String, but that really creates a new String. It is impossible to change a Strings value, so you need to read the Tokens and save them into a new String.

tokenizer = new tokenizer(line);
StringBuilder newLine = new StringBuilder();
while(hasmore) {
  if (matches) {
    newLine.append(token.toLowerCase);
  } else {
    newLine.append(token);
  }
}
line = newLine.toString();

Edit: Again as quasi pseudocode.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
if (token.matches(regex)) {
  nextToken.toLowerCase()
}

as pseudo code.

try it. If it doesn't work post your attempt and we will help you correct it.

Once again, see the API docs for String.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As long as you're not doing any Runtime.exec type stuff you shouldn't have any problems. You will want to test it, first, though.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

matches and toLowerCase ?

See the API docs for String

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The line

JLabel label[] = new JLabel[ numLabels ];

creates an array of "numLabels" length containing references of the Type JLabel, but with value null. You still have to initiate the individual elements. I.E.

label[i] = new JLabel();
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Use an HTML parser of some sort. Google for one. Adding it to the JNLP list or the archive tag will make it available to an applet from the server.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhm, is this a webapp? If so, simply save the bean to the session. If it is not a webapp, save the bean elsewhere (Preferences. maybe). Assuming this is simply a "user profile" bean and not actual "data", as that is more view related than data related.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

This

ps.setString(1, newUser);<--------------------

is not your problem. This

ResultSet rs = ps.executeQuery();
        System.out.println("ResultSet rs= : "+rs.toString());
        String password = rs.getString(1);

is your problem. You have not called next() (or first()/last()/etc. for scrollable resultsets) before calling getString() so the current "cursor position" is before the first row, i.e. not yet on any row, hence the failure.

What was it you saw that made you think the PreparedStatement's setString was were the exception rather than the ResultSet's getString method?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because Strings are immutable. You cannot change it's content, you can only create a new String containing modified content, so

str.replace('x', 'k');

should, of course, be

str = str.replace('x', 'k');
masijade 1,351 Industrious Poster Team Colleague Featured Poster

To do the addBatch simply do addBatch rather than execute and then include an if statement inside the for loop so that you can for, say, every 500 statements do executeBatch (i.e. if ((i % 500) == 0)). Also, as to why you only see one result, it is because you are only checking for one row. You are doing if(rs.next()) when you should be doing while(rs.next())

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry about that. That was a MySQL Connection URL property "allowMultiQueries".

From what I saw of your thread, you would be better off using Stement and the addBatch(String) method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I don't know how that won't just make things worse.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Something in there is null. Add a printstacktrace to that catch block so you can at least identify which line it's happening on.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Show the code for this part. Are you trying to execute multiple statements with a single sql string? If so, have you activated the "allow multiple statements" property?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Your problem (if the queries really look like what you've presented there) is the single quotes (') around the table names. Remove those. If you're worried that the tablename might be "generally" invalid, thereby needing to be quoted, then use double quotes (") not single quotes.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well the api docs say

Executes the given SQL statement, which returns a single ResultSet object.

for executeQuery and

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

for executeUpdate

masijade 1,351 Industrious Poster Team Colleague Featured Poster

then try adding ";create=true" to the end of the dburl. See the documentation (as I believe I've already said). Its not "entering that method" as you say because the connection is failing (possibly becuase the db doesn't exist, which I assume is the case since you're wanting to create tables), and you would be able to "see" that if you didn't simply ignore the exceptions like you are. Never do that. At the very least print the stack traces to STDERR.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhm, create=true as part of the DB url, maybe? Can't say if that's case since you haven't shown us what you used, nor told us in what state the DB was in before you started.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, post what you have so far, we are not simply going to do it for you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sounds like a question for the producers of your IDE, as that is not a Java error.

However, do you want an Applet or a Stand-alone app?

You've extended Applet, but written a Stand-Alone, so which is it?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Make an arraylist with all the individual items.

Generate a random number (not larger than the current size of the arraylist) and get then remove that index from the arraylist. Repeat.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, I have stated multiple times, that the components will take the minimum (or preferredSize amount of space) space needed to display itself. It might help if you actually showed some more of your code as this works just fine

import java.awt.Color;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class GridBagTest extends JFrame {

	public static final long serialVersionUID = 0L;

	JPanel redPanel, bluePanel, greenPanel;

	GridBagConstraints gbc;
	Container container;

	public static void main (String args[]) {
		GridBagTest gbe = new GridBagTest();
		try { Thread.sleep(2000); } catch (InterruptedException ie) {}
		gbe.setVisible(false);
		gbe.dispose();
	}

	public GridBagTest() {
		setSize (400, 400);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		container = getContentPane();

		redPanel = new JPanel ();
		greenPanel = new JPanel ();
		bluePanel = new JPanel ();
		redPanel.setBackground(Color.RED);
		greenPanel.setBackground(Color.GREEN);
		bluePanel.setBackground(Color.BLUE);

		GridBagLayout gbl = new GridBagLayout();
		container.setLayout(gbl);
		gbc = new GridBagConstraints ();

		AddPanel (redPanel, 0, 1);
		AddPanel (greenPanel, 1, 8);
		AddPanel (bluePanel, 9, 1);

		gbl.columnWeights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };
		setVisible (true);
	}

	public void AddPanel (JPanel panel, int gridx, int gridwidth) {
		gbc.gridx = gridx;
		gbc.gridy = 0;
		gbc.gridwidth = gridwidth;
		gbc.gridheight = 1;
		gbc.weightx = 0.0;
		gbc.weighty = 1.0;
		gbc.fill = GridBagConstraints.BOTH;
		add(panel, gbc);
	}
}

And seems to do exactly what you're asking.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, have you tried the columnWeights suggestion? Does that "fit the bill" for you?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And you have given three columns (0, 1, and 10, and where has column 9 gone, as that is your 10th column since the first column is 0, 10 is the eleventh column) a percentage of 100%, and the remaining became 0% (since you didn't assign one to them), so, obviously, all of the space will be (at best) evenly split between those three columns. So, even that you "know" that the weights are percentages, you seemingly don't know what that means (so I doubt that assertion to begin with). It has nothing to do with the gridwidth. If you want 10 columns all with a width of 0.1 and use gridwidth to "control" component size, then use the columnwieghts property of the layout itself.

gbl.columnWeights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };

(gbl is the GridBagLayout variable, I don't know what you used as you didn't show it.)

And set c1.wieghtx to 0.0. Also, you can reuse the same GridBagConstraints object. A copy of that object will be made when you use add (at least when using gbl.setConstraints(comp, const) and then add(comp), I'm not sure about add(comp, const) as I don't use that one). There is no reason to create a new GridBagConstraints object every time.

If a component "needs" more space than the "columnWeight" would normally provide, it will still take it, though.

There is no "forceGridSize" as that would make it GridLayout, so use that.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Every place where you write to the file, and the place where you open the file. I would also say to add a windowClosing method (which means using your own WindowListener) or a shutdown hook to close the file, but that is probably too much at the moment, and shouldn't be necessary, as it should automatically close, normally, when the program exits (but call flush after every write, to be sure).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, we are not here to do your work for you. The API docs and the tutorials work wonders.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? So, as a simple soultion, open a PrintStream to a file and set that to System.out. As a slightly better solution, open a FileWriter and set that as an instance variable and have the actionlisteners write to that rather than system. out, as a thid solution, but one which the instructor probably doesn't want to see, simply redirect standard out on the command line. There are much more elegant solutions, but any of these will work. At least try.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then use JApplet and simply do setMenuBar(menubar), JApplets own setMenuBar, not yours.

Edit: You don't want to mix AWT and Swing, anyway, and Applet is awt, JApplet is Swing, and since the rest is swing ....

masijade 1,351 Industrious Poster Team Colleague Featured Poster

add the JMenubar to the JApplet, not to "screens".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The weightx and weighty values are doubles, because they are percentages. A weight of 1 means 100%. If you want 10% it should be 0.1

Edit: Remember, though, that if the component needs more space than that in order to be completely displayed it will take that space, so don't, necessarily, expect that those percentages are "set in stone".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When you open an ObjectInputStream it attempts to first read the "header" (which will automatically be created upon creating an ObjectOutputStream on the other end), which the API docs clearly state. And, since your groovy script is not creating an ObjectOutputStream for your java program to read your ObjectInputStream fails. Why are you even attempting to open any kind of InputStream on the Java side if your Groovy script is not sending anything? And your using a BufferedReader on the Groovy side will not work with an ObjectOutputStream from the Java side. It would only receive a lot of nonsensical garbage.

Edit: Okay, I see you are writing from the groovy side (although it is sometimes w and sometimes writer and neither, as far as I can see, is ever defined). But, it seems to be a Character stream. So again, why the Object Streams Java side and the character reader/writer on the groovy side. That is destined to fail.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Study this, and I really mean study this, as I hate doing this sort of thing, I don't think it usually helps, but I can see I will be talking for hours trying to nudge you in the right direction.

public class MatrixTest {
	private static int[][] matrix = {
			{ 1, 2, 3, 4, 5 },
			{ 2, 3, 4, 5, 6 },
			{ 3, 4, 5, 6, 7 },
			{ 4, 5, 6, 7, 8 },
			{ 5, 6, 7, 8, 9 }
		};

	private static int[][] pattern1 = {
			{ 2, 3 },
			{ 3, 4 }
		};

	private static int[][] pattern2 = {
			{ 4, 5, 6 },
			{ 5, 6, 7 }
		};

	private static int[][] pattern3 = {
			{ 2, 2 },
			{ 3, 3 }
		};

	private static int[] findStart(int[][] pattern) {
		int[] result = { -1, -1 };
		START:
		for (int i = 0; i <= matrix.length - pattern.length; i++) {
			for (int j = 0; j <= matrix[0].length - pattern[0].length; j++) {
				if (matrix[i][j] == pattern[0][0]) {
					if (confirmMatch(i, j, pattern)) {
						result[0] = i;
						result[1] = j;
						break START;
					}
				}
			}
		}
		return result;
	}

	private static boolean confirmMatch(int row, int col, int[][] pattern) {
		for (int k = 0; k < pattern.length; k++) {
			for (int l = 0; l < pattern[0].length; l++) {
				if (pattern[k][l] != matrix[row + k][col + l]) {
					return false;
				}
			}
		}
		return true;
	}

	public static void main(String[] args) {
		int[] vals = findStart(pattern1);
		if (vals[0] != -1) {
			System.out.println("Pattern 1 found at Row:  " + vals[0] + "  Col:  " + vals[1]);
		} else {
			System.out.println("Pattern 1 not found.");
		}

		vals = findStart(pattern2);
		if (vals[0] != -1) {
			System.out.println("Pattern 2 found at Row:  " + vals[0] + "  Col:  " + vals[1]);
		} else {
			System.out.println("Pattern 2 not found.");
		}

		vals = findStart(pattern3);
		if (vals[0] != -1) {
			System.out.println("Pattern 3 found at Row:  " + vals[0] + "  Col:  " + vals[1]);
		} else {
			System.out.println("Pattern 3 not found.");
		}
	}
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster

"outer" length and "inner" length are the lengths of the arrays in the 2D array. I.E. double[][] a = new double[5][6]; the "inner" length is 6 (i.e. the length of the "sub" arrays) and the "outer" length is 5 (i.e. the length of the encompassing array). Both the matrix and the pattern have "outer" and "inner" lengths.

Usually the "outer" will refer to the row and the "inner" to the column, but this is arbitrary, so long as any calculations to be done with the matrix are done with the proper "alignment", and the same "alignment" is used throughout the program.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

First of all, get the lengths of the "inner" and "outer" array of the pattern. Then, when looping through the matrix, there is no reason to go beyond matrix.outer.length - pattern.outer.length, or matrix.inner.length - pattern.inner.length as the pattern wouldn't fit in those spaces. Then loop until you find the first value from the pattern in the matrix. Then loop through the inner matrix comparing it's values to the "offset" values from the matrix. i.e.

pattern[outerIndex][innerIndex] == matrix[firstFoundIndex + patternOuterIndex][firstFoundIndex + patternInnerIndex]

.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

define "not working".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because you wrongly overrode equals. Add the "@Override" annotation above every method that is suppossed to override something and you would notice that. The "equals" method needs to take "Object" as the parameter, not "WatchedPath".

Edit: And, obviously, you should then check that are actually getting a "WatchedPath, and not something else, and, regardless, you should also check that it is not null.

Edit Again: As well as checking that "dir" is not null, before calling equals and/or hashCode, and/or CompareTo on it, of course. And, for the compareTo to be used properly, don't forget to implement Comparable.

stephen84s commented: Ahh... Missed the equals() method signature +5
masijade 1,351 Industrious Poster Team Colleague Featured Poster

HashSet uses hashCode and equals as already stated. Also, as already stated, test the hashCode and equals outputs of Path, and ensure that you are getting what you expect, and ensure that the problem does not lie there.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As the first line of your "identify" method add if (!di.isDirectory()) return;

masijade 1,351 Industrious Poster Team Colleague Featured Poster

call pack on the frame in which the component resides

or

call doLayout (and/or validate) on the component to which the component was added and then repaint

Edit: Although, in the second scenario, the layout of the frame itself (if the size of "subcomponent" has changed) will also, still need to be updated, so maybe simply call pack on the Frame or doLayout on the contentPane of the frame.

Chaster commented: Short, very good answer, that solves the issue. +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

no, it is objQueue[0] that is null. When you initiate an Object[], each of the elements initially contain null. You still have to define the individual elements of the array.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you mean "start at one"? Do you mean that the first index should be 1 and not 0? Well, you can't. Java arrays (and the arrays of most other languages) index starting with 0. Make the array one longer and simply don't use the first index, or use indexes from 1 to array.length and simply subtract one when you actually index into the array.