JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you asking for help with the second listener? If so, you need to show me the code!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hold on a minute here - tong1 - are you sure you are answering the original requirement here?
Wootens: go back to the version in your post that starts "Cheers, it compiles now", that's almost perfect, its just that you increment count OUTSIDE the loop when, obviously, it should be incremented INSIDE the loop (see lines 38/39), and you need to print the number in a final else clause if it's not beep or beepbeep

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, so theres a
ArrayList<String> getPackageList(String appSet)
method just like the
ArrayList<String> getAppList(String appSet)
method that gives you the packages in a specified appSet, so, as I said, the new listener is exactly like the one you already have except that is goes from appSet to package, not from app to appSet

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, but it should be exactly the same structure except for the details of the CBRCPMDailyT20AppManager query, which I have no info for.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please give me an idea for how to implement an actionlistener for appComboBox inorder
to get the data for package at runtime

This is very confusing. You already have an action listener for appComboBox, which contains code that apparently gets the data for package at runtime

ArrayList<String> anAppList = CBRCPMDailyT20AppManager.instance()
				.getAppList(appSet);//replace by appSet
		for (int i = 0; i < anAppList.size(); i++) {
			this.appComboBox.addItem(anAppList.get(i));
		}

I thought your problem was that when you cleared the old data from the list you got an NPE, and you haven't responded to my questions or suggestions about that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, forum rules say I can help you by suggesting good directions to go in, and helping to fix specific problems, but I can't write your homework code for you.
Just slow down, step back a bit, look at your overall code, then dive into particular parts.
If you're using Eclipse the use the code folding feature to hide all the implementations of your methods so all you see are the signatures, then think about exactly what should be done in each one, and what data each one needs to do that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Create the combo boxes at initialisation time (ie by calling the get method, just once only), but don't put any data in them. Then in the action handler just check if the existing combo box is empty and, if not, removeAllItems(), then load the new data into it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One last time before I move on to something else...
why are using getAppComboBox() instead of just referring to appComboBox like you do on the next line? It can't be what you told me earlier - "give the list of items for the app combo box" - because the very next thing you do is to remove all the contents anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The syntax you just quoted isn't right right, so its not very helpful.
Exactly which line of code does the error refer to - it has the line number but I don't have a current listing to match that up with.
Are you saying that you create a new JComboBox just so you can use it to return some values?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

getAppComboBox() will give the list of items for the app combo box

So why is it declared as returning a JComboBox?

Exactly what error are yo getting now?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What does getAppComboBox() return? Why not use appSetComboBox?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, Sun isn't being difficult. Because of shift keys (etc) typing one character may involve multiple keys being pressed, thus mutliple keyCodes for one keyChar.
This is from the API doc:

For example, pressing the Shift key will cause a KEY_PRESSED event with a VK_SHIFT keyCode, while pressing the 'a' key will result in a VK_A keyCode. After the 'a' key is released, a KEY_RELEASED event will be fired with VK_A. Separately, a KEY_TYPED event with a keyChar value of 'A' is generated.

In more detail:

Key typed" events are higher-level and generally do not depend on the platform or keyboard layout. They are generated when a Unicode character is entered, and are the preferred way to find out about character input. In the simplest case, a key typed event is produced by a single key press (e.g., 'a'). Often, however, characters are produced by series of key presses (e.g., 'shift' + 'a'), and the mapping from key pressed events to key typed events may be many-to-one or many-to-many. Key releases are not usually necessary to generate a key typed event, but there are some cases where the key typed event is not generated until a key is released (e.g., entering ASCII sequences via the Alt-Numpad method in Windows). No key typed events are generated for keys that don't generate Unicode characters (e.g., action keys, modifier keys, etc.). The getKeyChar method always returns a valid Unicode character or CHAR_UNDEFINED. For key pressed and key released events, the getKeyCode method …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For keyTyped events use getKeyChar(), not getKeyCode()
(For KEY_TYPED events, the keyCode is VK_UNDEFINED.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is the OP ready for it yet?

drogba123: sorry to talk about you in the third person like this, please don't be offended - it's intended to help!

Norm: I'm an OOP fanatic, so I believe in starting with the OO style from day 1 (although others may disagree!). Judging by the code posted so far I think the OP has plenty of capability with the essential programming constructs and the Java API way of doing things; the problem here is one of design. However, it's important to maintain the continuity of dialog that you already have. Having made my suggestion I'm going to lurk in the background, just let me know if I can help.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its up to the person who designed the bean to decide which attributes are single values and which are lists, and implement the accessors accordingly. Unless you can change or subclass the bean you'll probably just have to work around that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Norm. I don't mean to butt in here, but do you think maybe its time to stop and think about States and a state transition diagram? I suspect that ad-hoc booleans and timers could lead to something confusing and very hard to debug completely.
If this were my code I'd be thinking of an enum of States (stooped, going up, going down, loading) and some methods like stop(), wait(int seconds) etc to handle the state transitions.
Just ignore this if you think it's not helpful.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The normal convention is that a set... method sets a single value, so when you call it repeatedly in your loop you are overwriting the the value you just set. There is only one value to get..., which will be the last one you set.
If a bean has an attribute that takes multiple values you usually see an add... method, not a set..., and the get... method takes a parameter to identify which value you are getting.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"The Java EE platform is built on top of the Java SE platform. The Java EE platform provides an API and runtime environment for developing and running large-scale, multi-tiered, scalable, reliable, and secure network applications."

EE is used for developing large corporate-type apps in environments with big web servers and databases. Is that what you are thinking of doing? - if not SE is fine.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

James please do not ask people to repost their code again, rather advise on using code tags for future posting. As you know multi-posting is against forum rules

Sorry.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I understood what you said, so there was no need to say it again. I'm not stupid. But if you don't want to give me the additional info I asked for, that's OK. Good luck. I'm outta here. Bye bye. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please re-post code in code tags so we can read it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly which line is giving the NPE? Is it in getAppComboBox() - where's that code?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at the language ref 8.3.2.3 - the bit I quoted is followed by loads of examples illustrating each of those points.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The current Language Reference has this to say:

8.3.2.3 Restrictions on the use of Fields during Initialization
The declaration of a member needs to appear textually before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:

The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C.
The usage is not on the left hand side of an assignment.
The usage is via a simple name.
C is the innermost class or interface enclosing the usage.

A compile-time error occurs if any of the four requirements above are not met.

What's interesting is that the third condition (via a simple name), which is the one that answers this question, was not present in earlier versions (eg JDK 1.4.2) of the same documentation. Did they change the language, or did they just notice this behaviour?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The usual form of that expression is
Sum(n) = n(n+1)/2
but that's not a loop.

How about recursion:

int sum(int n) {
   return (n==1)?1:n+sum(n-1);
}

Does that count as a loop?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Come on guys! This is a really good question! I certainly want to know the answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where is Labels defined?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That was a Java bug, but whatever.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using someone else's code for your homework is called "cheating". Nobody here is going to help you cheat.
Write your own code and you will get help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

nevermind

NewOrder commented: thanks James +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where is userdata[][] defined and initialised?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ppps: I don't know DrJava, but I can very strongly recommend Eclipse. NewBeans also seems to be a popular choice. Eclipse and NetBeans seem to be the only Java IDEs in really wide use for full-scale commercial development.
(Unlike Norm I would never think of trying to work with source code without a good IDE to do most of the donkey work for me.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

pps: I notice your code has a convolution filter, so if you also want to do blurring or whatever, "proper" transparency also works beautifully with an overridden paint(...) method - the alpha values are used just like you'd hope.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I used to use that approach, but JDK 1.6u10 (or thereabouts) has REAL transparent windows. It's buries in awtutilities for now, will be fully exposed in Java 1.7
Here's a demo I wrote:

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(50, 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>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();
      centerOnScreen(window1);
      window1.setVisible(true);

      window2.setUndecorated(true);
      setTransparent(window2);
      setAlpha(window2, 0.0f);

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

      window2.add(text2);
      window2.pack();
      centerOnScreen(window2);
      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 = window2.getHeight();
      r = (int) Math.sqrt(w * w + h * h) / 2; // radius
      x = w / 2 - r; // top …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

SimpleDateFormat. (It's in the API reference)
Create a format to match your data, then use the parse(...)method to convert to a Date

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, or:

sessions = new collection of Dates
for each vote
  if sessions does not contain this vote's session date 
      add session to sessions

This kind of in-memory processing should be safe and v v fast for thousands of votes, but maybe not millions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Once you've read this in its easy to loop thru all the entries & build an arraylist of unique session dates - which you can then display in an list box for user selection.
What kind of data volumes are you expecting?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
for (a = 0; a <9; a++) {
   for (b = 0; b < 9; b++){

Am I the only one who plays chess on an 8x8 board?

tux4life commented: Of course not, there's still me :P +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I suggested the date/time when the session starts as the unique session identifier. This is easier & safer than trying to create your own unique int.
The Date/time of the actual vote may, or may not, be useful.
ps There's no need to covert Dates to Strings - you can just store the raw Date in your results if you want. There's no reason to convert Date to String via StringBuilder in this case, SB is used when you want to concatenate a whole load os String values into one. Converting the Date to YYYYMMDD loses the time, so two sessions on the same day an't be distinguished - is this what you intended?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, include a session identifier (eg new Date() when session starts) as part of the data for each vote.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unless there are privacy issues, maybe its a good idea to keep all the data instead of a summary, ie for each vote cast add a record to the list showing who voted/when voted/what voted for. That way each record is unique and never updated. Then derive the summary statistics on the fly or (if that turns out to be slow) build them when you read the data at startup and increment it as you go, but don't save it.
If multiple clients can increment a set of shared counters then you also have to get very serious about Thread issues.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can call methods from inside other methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe time to mark this as solved and start a new thread for connection issues if required?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 1 you create a new list and add the latest to it, and write that, so yes, that's all you get.
You need to add the new Result to the existing list of previous results

String fileName = "votingResults.txt"
inputStream = new ObjectInputStream(new FileInputStream(fileName );
results = (LinkedList<Result>) inputStream.readObject();
inputStream.close();
// create new result here ....
results.add(result);
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(fileName ));
stream.writeObject(results);
stream.close();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, previous 2 posts taken together are ambiguous, and the toString is redundant in a print(...) because print(...) does that anyway.
This what I meant:

LinkedList<Result> results = (LinkedList<Result>) inputStream.readObject();
for (Result r : results) {
   System.out.println(r);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ps: Use the enhanced for loop - much easier

for (Result r : results) {
   System.out.println(r);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Norm's right. You write a single (complex) Object - a linked list. You read a single Object - a linked list, but you need to cast the Object you read to linked list.
There's no reason to read in a while loop, there's only one Object

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did a bit more scratching a round, and found what seems to be the answer. Object I/O writes a header to the stream, so it's OK then to write multiple objects, but if you close & re-open the stream in append mode the next write writes a new header at the append point where input is not expecting it - so it won't work.
The ArrayList approach should be OK tho.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't see where you add those fields to anything.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can definitely read multiple Objects from the same stream. Maybe worth checking that the output stream is properly flushed & closed after each session? I did see somewhere that there can be block-size padding issues in append mode, where some padding is left after the first write and the input stream gets confused, but I'm not sure what/when that was.
If that still doesn't work then put all you objects into some kind of Collection (eg ArrayList) and write the whole list (as a single Object) to a (non append) file. Then in each session you can read the while collection, add any new ones, write it all out again. A but tacky, yes, but depending on the volume may be plenty good enough.