comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* Can someone use invokeLater() to call a public method from a JPanel? - 5 
messages, 3 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70ac1bf0cc54a090
* Hardcode keystore into java program - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6da2c5f243c47da8
* National letters in strings from ResourceBundle - 3 messages, 3 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/338fb94256f5c5fb
* How to create a JAR file - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ea455ce0dfc0c521
* GUI - GUI value passing - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/427d1d7372619486
* Release version 30 times slower than debug version - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2fb8ed01a0672310
* emacs Vs Eclipse? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/58b6f53b3e1b91e1
* How do I make my JDialog's buttons respond to enter key? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/42d85a46a4a0b455
* get the Object with "main" - 4 messages, 4 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65ec91a62fe2883b
* Newbee Question about random numbers - 6 messages, 4 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d5332da2a87b1a4a
* Convert UTF-8 encoded data from file into unicode escape - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/518625c508ec82f8
* Map that takes a pair of keys? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b8bfed67959eb893
* Experienced programmer: where to start with Java? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/92371952fdc705d2
* Can i use multiple bluetooth dongles on one computer?! - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bc883f14d78e1f6f
  
==========================================================================
TOPIC: Can someone use invokeLater() to call a public method from a JPanel?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70ac1bf0cc54a090
==========================================================================

== 1 of 5 ==
Date:   Sun,   Oct 24 2004 2:49 am
From: Alex Hunsley <[EMAIL PROTECTED]> 

***C.Steamer*** wrote:
> Yeah thanks for nothing dude, If you don't have anything useful to add don't 
> say anything.

Don't top post. It makes threads hard to follow.

Thanks for nothing? How about "thanks for the advice in your post about 
how to maybe fix my code"? Did you somehow completely miss the parts of 
my post where I gave advice?

Hmm, let's go over my post and examine each bit and see if there is 
anything useful there.

I wrote:
 >For a start, post complete, compilable, working code that demonstrates 
 >the problem. Snippets aren't much use.

This is very useful advice - how to enable to help you more easily. So 
you obviously missed this part of my post.

 >Secondly - you are calling something from the constructor of JPanel, 
 >you say? How do you mean? Have you edited/recompiled the JPanel 
source; >or overridden JPanel, or what?

Asking you for more information about something unclear in your original 
post, so that we can understand more and help you more easily. Something 
else which is useful, to us and to you. So you obviously missed this 
part of my post.

 >Anyway, sounds like you're suffering Constructoritis, the disease of 
 >doing far too much in constructors. Constructors should do very little 
 >- store passed in values, usually; constructors should *not* call 
 >non-final or non-private methods, and constructors shouldn't be doing 
 >GUI related things. Factor out that stuff into other method(s) that 
you >call after the Constructor has done its stuff. Doing this may solve 
 >your problems.

And again, more useful info: a suggestion about what may be the problem, 
along with hints about how to avoid that problem. So you obviously 
missed this part of my post.

So, from your very strange claims of me being no help, it would appear 
you missed all of my post. Did you actually read my post, or someone 
elses? Perhaps you're having problems with your newsreader software?

Ok, let's turn this on its head, just to see exactly what is your beef: 
show me a *single sentence* from my reply that *didn't* contain some 
useful advice or information about how we could help you more. (Hint: 
you can't.)

One last question: in which way is it smart to alienate the people who 
are trying to help you?

alex






== 2 of 5 ==
Date:   Sun,   Oct 24 2004 9:32 am
From: "Thomas G. Marshall" <[EMAIL PROTECTED]> 

Alex Hunsley coughed up:

...[rip]...

>> Overly strict.  I cannot /count/ the number of times I've seen
>> horribly convoluted code set out to avoid putting nearly /anything/
>> into a constructor.
>
> "Constructors should *not* call non-final or
> non-private methods" is not overly strict

STOP RIGHT THERE.

You meant: should *not* call non-final or non-private methods of that same
object?  Sorry, I misunderstood your intent.

Then I totally agree.

Here's something else I see *all the time*:  (pseudo-java, ignore scoping
rules):

    class A
    {
        A() { helper(); }

        helper() {....};
    }

    class B extends A
    {
        helper() {....};         // dangerous: overridden
    }


...[rip]...

-- 
Framsticks.  3D Artificial Life evolution.  You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/





== 3 of 5 ==
Date:   Sun,   Oct 24 2004 9:39 am
From: "Thomas G. Marshall" <[EMAIL PROTECTED]> 

Alex Hunsley coughed up:

...[rip]...


> One last question: in which way is it smart to alienate the people who
> are trying to help you?

You were helpful.

However, to the side of your reply, I am sensing a growing sense of rudeness
in the replies in programming ng's.  It sometimes takes the following form:

    OP: humble question, please, I'm humble
    RP: this is a horrible idea, and do your research better
    OP: that is rude!

I think it may have something to do with the relatively recent rush of
students to the ng's asking for their homework to be completed for them, and
that /that/ is tiring for the frequent contributors to deal with over and
over.  But there seems to be something more here, and I haven't yet put my
finger on it.

Again, this is to the side of your post.  It's just an observation in
general that I've made.

{shrug} YMMV.

-- 
Framsticks.  3D Artificial Life evolution.  You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/





== 4 of 5 ==
Date:   Sun,   Oct 24 2004 10:11 am
From: Mark Thornton <[EMAIL PROTECTED]> 

Alex Hunsley wrote:
> ***C.Steamer*** wrote:
> 
> overridden JPanel, or what? Anyway, sounds like you're suffering 
> Constructoritis, the disease of doing far too much in constructors. 
> Constructors should do very little - store passed in values, usually; 
> constructors should *not* call non-final or non-private methods, and 
> constructors shouldn't be doing GUI related things. Factor out that 
> stuff into other method(s) that you call after the Constructor has done 
> its stuff.
> 

I agree with Thomas Marshall that your prescription is overly strict. 
The style of doing almost nothing in constructors is necessary in C++ 
where the consequences of throwing an exception during a constructor are 
poorly defined. By contrast in Java, this represents no problem, and the 
order in in which construction takes place is also well defined. Yes it 
is true that some people have been surprised by the fact that if a 
constructor uses a method which has been overridden in a child class, 
then unlike in C++ it is the child's version which is used.

For me the sign of constructor problems is where you end up with a large 
number of constructors with different combinations of arguments. In this 
case it is usually better to have a simple constructor followed by 
subsequent calls to set all the properties as required (unless of course 
you want an immutable object).

Mark Thornton



== 5 of 5 ==
Date:   Sun,   Oct 24 2004 11:44 am
From: "Thomas G. Marshall" <[EMAIL PROTECTED]> 

Mark Thornton coughed up:
> Alex Hunsley wrote:
>> ***C.Steamer*** wrote:
>>
>> overridden JPanel, or what? Anyway, sounds like you're suffering
>> Constructoritis, the disease of doing far too much in constructors.
>> Constructors should do very little - store passed in values, usually;
>> constructors should *not* call non-final or non-private methods, and
>> constructors shouldn't be doing GUI related things. Factor out that
>> stuff into other method(s) that you call after the Constructor has
>> done its stuff.
>>
>
> I agree with Thomas Marshall that your prescription is overly strict.
> The style of doing almost nothing in constructors is necessary in C++
> where the consequences of throwing an exception during a constructor
> are poorly defined. By contrast in Java, this represents no problem,
> and the order in in which construction takes place is also well
> defined. Yes it is true that some people have been surprised by the
> fact that if a constructor uses a method which has been overridden in
> a child class, then unlike in C++ it is the child's version which is
> used.

...which is a disaster waiting to happen, because it can allow a superclass
to access something that has not yet been initialized in the subclass.

I personally do not like the fact that java allows a constructor helper
method to be overridden in the first place---I believe that to be a mistake.


> For me the sign of constructor problems is where you end up with a
> large number of constructors with different combinations of
> arguments. In this case it is usually better to have a simple
> constructor followed by subsequent calls to set all the properties as
> required (unless of course you want an immutable object).
>
> Mark Thornton

Thank you for the agreement.  Again, I'm still not sure what he meant by it.
In the case of wanting to avoid public methods of itself, I am up for
veering away from it if you can.  But the notion of not allowing a
constructor to call /any/ public methods /anywhere/ is just over the top in
my opinion.

-- 
"Well, ain't this place a geographical oddity!
Two weeks from everywhere!"






==========================================================================
TOPIC: Hardcode keystore into java program
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6da2c5f243c47da8
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 2:52 am
From: [EMAIL PROTECTED] (Fritz Bayer) 

Hi,

I generated a keystore file with the java keytool. Now I would like to
import the data via copy and paste into my java source code and store
the data as a String.

To achieve this I did the following steps:

1. native2ascii -encoding utf-8 keystorefile iso8859_keystore_data.txt
2. Replace " in the iso8859_keystore_data.txt with \"
3. Replace newlines in the iso8859_keystore_data.txt with \n
4. Copy and paste the data into my program.

When I load the keystore using " trustStore.load(new
ByteArrayInputStream(copyAndPastedString.getBytes("utf-8")),
password);" I get an exception saying that the Format is invalid. So
somewhere along the conversion the data get altered.

For all the IO pros out there I have some questions, which I think
will help me get closer to the solution of the problem.

1. Are the keystore files created with the java keytool actually
encoded in utf-8? Which encoding is used - I assumed its utf-8...

2. Generally speaking should I use the string "utf-8" or "utf8" in my
java program, when for example using String.getBytes(String encoding)
?

3. Do you know a program, which reads a utf-8 encoded file and writes
the data to a new file thereby producing only unicode escapes ? (This
would save step 2 and 3, which are error prone)

Fritz




==========================================================================
TOPIC: National letters in strings from ResourceBundle
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/338fb94256f5c5fb
==========================================================================

== 1 of 3 ==
Date:   Sun,   Oct 24 2004 3:55 am
From: Brzezi <[EMAIL PROTECTED]> 

Hi.

I`m writing program, in it I`m using strings received from .properties file
by ResourceBoundle, end if I put this strings into components like JLabel,
JButton,  instead of national letters (in this case Polish letters) I see
'?'

I use NetBeans4.0 IDE, if I hardcode strings into source, everything is
good, without i'?', .properties files I edit in NetBeans too,

Do you have any idea how to solve it?


Pozdrawiam
        Brzezi
-- 
[    E-mail: [EMAIL PROTECTED] ][  GEEK CODE [Version: 3.12]: GCM dpu s+:-  ]
[       Ekg: #3781111            ][  a--- C+++ UL++ P+ L+++ E--- W+++ N+++    ]
[ LinuxUser: #249916             ][  o-- K- w--- O-- M- V- PS PE Y PGP--- t+  ]
                                  [  5- X++ R* tv+ b- DI- D+ G+ e- h! r y--   ]



== 2 of 3 ==
Date:   Sun,   Oct 24 2004 8:27 am
From: Tor Iver Wilhelmsen <[EMAIL PROTECTED]> 

Brzezi <[EMAIL PROTECTED]> writes:

> I use NetBeans4.0 IDE, if I hardcode strings into source, everything is
> good, without i'?', .properties files I edit in NetBeans too,

Properties.load() want non-Latin-1 characters as \uxxxx escape codes.

See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding



== 3 of 3 ==
Date:   Sun,   Oct 24 2004 9:00 am
From: Oscar kind <[EMAIL PROTECTED]> 

Brzezi <[EMAIL PROTECTED]> wrote:
> I`m writing program, in it I`m using strings received from .properties file
> by ResourceBoundle, end if I put this strings into components like JLabel,
> JButton,  instead of national letters (in this case Polish letters) I see
> '?'

This looks like character encoding problem.

ResourceBundle is an abstract class, with two known subclasses. For a
resource bundle read from a .properties file, PropertiesResourceBunble is
used. The API for this class refers to ResourceBundle and Properties. It
also makes a special note of mentioning charcater encodings at:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#encoding

A quote from that page:
"This format uses the ISO 8859-1 character encoding. Characters that cannot
 be directly represented in this encoding can be written using Unicode
 escapes; only a single 'u' character is allowed in an escape sequence.
 The native2ascii tool can be used to convert property files to and from
 other character encodings."

For more information on unicode escapes, see:
http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#100850


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2




==========================================================================
TOPIC: How to create a JAR file
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ea455ce0dfc0c521
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 5:16 am
From: [EMAIL PROTECTED] (Samar Hossam) 

Dear everyone,
I need to write a method that takes a source directory and jars its
content. I wrote the following:
public static void jar(String sourceDir,JarOutputStream out,String
parent){
try {
// get a list of files from the current directory 
File f = new File(sourceDir);
String files[] = f.list();
// update the parent
if (parent != ""){
parent = parent + File.separatorChar;
}
File tempFile;
BufferedInputStream origin = null;
byte data[] = new byte[2048];
for (int i=0; i<files.length; i++) {
System.out.println("Adding: " + files[i]);
tempFile = new File(sourceDir +File.separatorChar + files[i]);
if(tempFile.isFile()){
FileInputStream fi = new FileInputStream(sourceDir +
File.separatorChar + files[i]);
origin = new BufferedInputStream(fi, 2048);
JarEntry entry = new JarEntry(parent + files[i]);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0, 2048)) != -1) {
out.write(data, 0, count);
}
origin.close(); 
}
else{
JarEntry entry = new JarEntry(parent + files[i] + File.separatorChar);
out.putNextEntry(entry);
jar(sourceDir + File.separatorChar + files[i],out, parent + files[i]);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}

The problem with the code is the following:

1. Each subdirectory contains an extra empty file
2. If you try to extract a jar file created by this method. The entry
of a subdirectory is considered as a file not a directory.
3. I don't know how to create the META-INF folder 

I would appreciate your help sooooo much. Regards, Samar




==========================================================================
TOPIC: GUI - GUI value passing
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/427d1d7372619486
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 5:56 am
From: "paul.foreman" <[EMAIL PROTECTED]> 


"Jacob" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> paul.foreman wrote:
>
>> From a window created by extending Frame, I have created a new child 
>> window also based on extending Frame.
>
> If the two are *conceptually* independent, use an event mechanism as
> suggested by Michael R.
>
I have tried to set up an event mechanism, with no luck so far.
//code to add an action listener and create an ActionEvent.
    button2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        button2_actionPerformed(e) ;
      }
    });

//code in the same class to close the window.
  void button2_actionPerformed(ActionEvent e) {
  dispose();
  }
 where sP is the reference to the instance of the class (window) which is 
generating the button event.

//I have tried the following code in the other window, where sP is the 
reference to the instance of the class (window) which is generating the 
button event., but it does not compile

  void sP.button2_actionPerformed(ActionEvent e) {
  cPid = sP.cPids;
  }

Any assistance welcome in trying to get the event mechanism working across 
different class instances.

Regards

Paul 






==========================================================================
TOPIC: Release version 30 times slower than debug version
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2fb8ed01a0672310
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 7:47 am
From: croeltgen <[EMAIL PROTECTED]> 

I have a developped an applet in Visual J++ 6.0 and I encounter the
situation that the when it runs in debug mode everything is fine, but
when I run in release mode, the execution is 30 (thirty!) times
slower. I didnt encounter this problem before and I use J++ since 2
years already. Apart from a corrupted J++ I cannot image what the
reason could be.
Any hints?
Thank you,
Claude




==========================================================================
TOPIC: emacs Vs Eclipse?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/58b6f53b3e1b91e1
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 7:46 am
From: Kai Grossjohann <[EMAIL PROTECTED]> 

Oliver Scholz <[EMAIL PROTECTED]> writes:

> I am not exactly a newbie with Emacs and in fact I touch the rodent
> rarely. But even /I/ would sometimes wish to have the option to switch
> temporarily to a more graphical user interface: whenever I use Elisp
> packages that I use rarely. ediff and artist-mode would be examples
> for this in my case, because I use each of them about once a year.
> Rather than invoking `C-h m' or `C-h a' and studying the output until
> I find that damn comand that I used half a year ago to draw a
> rectangly, I'd prefer to interact with a GUI.  A CLI or a TUI shows
> its strength only there were you use it very often.  Other than that
> it is cumbersome.

For ediff, just hit ?.  That will show you a little cheat sheet of
things to do.

What is artist-mode?

Kai




==========================================================================
TOPIC: How do I make my JDialog's buttons respond to enter key?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/42d85a46a4a0b455
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 8:40 am
From: "Bryan Cooper" <[EMAIL PROTECTED]> 

I've put together a sample TestDialog and TestPanel class that use the
DefaultKeyHandler class that I posted.  I think this test case matches the
behavior you're looking for.  I don't think there is a one-line (or just a
couple of lines of code) solution to this one because of how focus works in
Java.

Code is attached.  Hope this helps you.

Best Regards,
Bryan Cooper

file [TestDialog.java]:
package testdialog;

import java.awt.HeadlessException;

import javax.swing.JDialog;
import javax.swing.WindowConstants;

/**
 * @author Bryan
 *
 */
public class TestDialog extends JDialog {
 /**
  * @throws java.awt.HeadlessException
  */
 public TestDialog()
   throws HeadlessException {
  super();
  initGUI();
 }

 /**
  * Initialize the dialog and show it.
  */
 private void initGUI() {
  setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  getContentPane().add(new TestPanel());
  setTitle("Test Dialog");
  setModal(true);
  setSize(800, 600);
  setVisible(true);
 }

 public static void main(String[] args) {
  new TestDialog();
 }
}

file [TestPanel.java]:
package testdialog;

import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * The test panel with some buttons.
 */
public class TestPanel extends JPanel {
 /** Handles key mappings */
 private final DefaultKeyHandler keyHandler = new DefaultKeyHandler();

 private JButton[] buttons = new JButton[5];
 private Action[] actions = new Action[5];

 public TestPanel() {
  for (int i = 0; i < buttons.length; i++) {
   /** Create five buttons and assign them actions */
   final String actionName = "Button " + i;
   actions[i] = new AbstractAction() {
    {
     putValue(Action.NAME, actionName);
    }

    public void actionPerformed(ActionEvent e) {
     System.out.println("I am action: " + actionName);
    }
   };
   buttons[i] = new JButton(actions[i]);
   buttons[i].addFocusListener(new FocusListener() {
    public void focusGained(FocusEvent e) {
     System.out.println("Focus gained on " + e.getSource());
     /**
      * This will switch your Enter key mapping
      * whenever focus has been gained on a button.
      */
     keyHandler.mapEnterKeyAction(((JButton)e.getSource()).getAction());
    }
    public void focusLost(FocusEvent e) {
     System.out.println("Focus lost on " + e.getSource());
    }
   });
   add(buttons[i]);
  }
  /** Register the panel with the keyHandler */
  keyHandler.registerComponent(this);
 }
}

file [DefaultKeyHandler.java]:
package testdialog;

import java.awt.Component;
import java.awt.Container;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.KeyEventDispatcher;
import java.awt.KeyEventPostProcessor;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.HashMap;
import java.util.Set;

import javax.swing.Action;

/**
 * This class handles the default key strokes the users type
 * in a panel or component by executing the registered actions.
 * If no actions are registered, then nothing will happen.  Any key
 * stroke can be mapped to an action, however, the two main
 * key strokes mapped in this object are the \<enter\> and
 * \<escape\> keys.  The key is a KeyEvent.VK_<key> static
 * value and the action is what will be executed if
 * the keystroke is typed by the user.
 * @author B. Cooper
 * @since v1.0.0
 */
public class DefaultKeyHandler
    extends DefaultKeyboardFocusManager
    implements KeyListener, KeyEventDispatcher, KeyEventPostProcessor {
    /** The table that will hold the actions to execute */
    private HashMap actionMap = new HashMap();

    /**
     * Default Constructor
     */
    public DefaultKeyHandler() {
        super();
    }

    /**
     * @see 
java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent)
     */
    public boolean dispatchKeyEvent(KeyEvent e) {
        /** Add custom code here if you need to... */
        return false;
    }

    /**
     * If a KeyEvent matches the key in the actionMap object,
     * the associated action will be fired.
     * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
     */
    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();
        Set keys = actionMap.keySet();
        Integer findKey = new Integer(keyCode);
        if (keys.contains(findKey)) {

            final Action a = (Action)actionMap.get(findKey);
            try {
                a.actionPerformed(
                    new ActionEvent(
                        this,
                        1,
                        (String)a.getValue(Action.ACTION_COMMAND_KEY)));
            } catch (Exception ex) {
                ex.printStackTrace(System.err);
            }
        }
    }

    /**
     * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
     */
    public void keyReleased(KeyEvent e) {
    }

    /**
     * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
     */
    public void keyTyped(KeyEvent e) {
    }

    /**
     * This method will map an action to the enter key event
     * @param action
     */
    public void mapEnterKeyAction(Action action) {
        actionMap.put(new Integer(KeyEvent.VK_ENTER), action);
    }

    /**
     * This method will map an action to the escape key event
     * @param action
     */
    public void mapEscapeKeyAction(Action action) {
        actionMap.put(new Integer(KeyEvent.VK_ESCAPE), action);
    }

    /**
     * This method will map an action to the escape key event
     * @param keyEventId
     * @param action
     */
    public void mapKeyAction(int keyEventId, Action action) {
        actionMap.put(new Integer(keyEventId), action);
    }

    /**
     * @see 
java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent)
     */
    public boolean postProcessKeyEvent(KeyEvent e) {
        /** Add custom code here if you need to... */
        return false;
    }

    /**
     * @see 
java.awt.KeyEventPostProcessor#postProcessKeyEvent(java.awt.event.KeyEvent)
     */
    public void processKeyEvent(Component component, KeyEvent e) {
        /** Add custom code here if you need to... */
    }

    /**
     * This method registers a component for the mapped actions.
     * @param component
     */
    public void registerComponent(Component component) {
     component.addKeyListener(this);
     if (component instanceof Container) {
      Component[] comps = ((Container)component).getComponents();
      for (int i = 0; i < comps.length; i++) {
       registerComponent((comps[i]));
      }
     }
    }
}



"Paul Tomblin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In a previous article, "Bryan Cooper" <[EMAIL PROTECTED]> said:
>>Did you try out this solution?
>
> Not yet.  I was hoping there was an easier solution first.  I mean,
> JOptionPane guis do it, native guis do it, and the "setDefaultButton"
> thing does it, so why would it be so complicated in JDialogs?
>
> The source code for JOptionPane is pretty simple, but it looks like all
> the complicated stuff is in plaf/basic, and it seems to do something
> almost as complicated as yours.
>
> -- 
> Paul Tomblin <[EMAIL PROTECTED]> http://xcski.com/blogs/pt/
> Documentation: Cryptic, lacking, erroneous.  Pick any three.
>              -- Arvid 






==========================================================================
TOPIC: get the Object with "main"
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65ec91a62fe2883b
==========================================================================

== 1 of 4 ==
Date:   Sun,   Oct 24 2004 9:06 am
From: "<- Chameleon ->" <[EMAIL PROTECTED]> 

class MainClass {
   static public int main(String[] args) {
     MainClass a = new MainClass();             // <-- here!
     OtherClass b = new OtherClass();
   }
   ..................
}


class OtherClass {
   private void aMethod() {
     MainClass f = getMainObject();             // <-- and here!
   }
}
-----------------------------------------

Can you implement "getMainObject()" to return the "a"?
(a instanceof MainClass)


thanks



== 2 of 4 ==
Date:   Sun,   Oct 24 2004 10:50 am
From: Tor Iver Wilhelmsen <[EMAIL PROTECTED]> 

"<- Chameleon ->" <[EMAIL PROTECTED]> writes:

>      MainClass a = new MainClass();           // <-- here!

This is a method-local variable.

>      OtherClass b = new OtherClass();

> class OtherClass {
>    private void aMethod() {
>      MainClass f = getMainObject();           // <-- and here!
>    }

> Can you implement "getMainObject()" to return the "a"?
> (a instanceof MainClass)

You really should not copy assignemt text verbatim, it becomes too
obvious it's homework.

Hint: You need to pass a to b somehow.



== 3 of 4 ==
Date:   Sun,   Oct 24 2004 10:54 am
From: "Matt Humphrey" <[EMAIL PROTECTED]> 


"<- Chameleon ->" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> class MainClass {
>    static public int main(String[] args) {
>      MainClass a = new MainClass(); // <-- here!
>      OtherClass b = new OtherClass();
>    }
>    ..................
> }
>
>
> class OtherClass {
>    private void aMethod() {
>      MainClass f = getMainObject(); // <-- and here!
>    }
> }
> -----------------------------------------
>
> Can you implement "getMainObject()" to return the "a"?
> (a instanceof MainClass)

No.  There is no information in OtherClass that ever contains the reference
to the same object referred to by "a". Somewhere, you must make the
reference what is referred to by "a" available to the OtherClass.  Some
options are:

1) Pass MainClass reference in to the OtherClass constructor.

2) Make a static variable in MainClass that is accessible to OtherClass,

3) Create a singleton class that is shared between MainClass and OtherClass
to hold the shared value.

The only way to know which of these (if any) or others is best is to know
exactly what problem you're trying to solve.

Cheers,
Matt Humphrey   [EMAIL PROTECTED]  http://www.iviz.com/





== 4 of 4 ==
Date:   Sun,   Oct 24 2004 10:41 am
From: Oscar kind <[EMAIL PROTECTED]> 

"<- Chameleon ->" <[EMAIL PROTECTED]> wrote:
> class MainClass {
>   static public int main(String[] args) {
>     MainClass a = new MainClass();             // <-- here!
>     OtherClass b = new OtherClass();
>   }
>   ..................
> }
> 
> 
> class OtherClass {
>   private void aMethod() {
>     MainClass f = getMainObject();             // <-- and here!
>   }
> }
> -----------------------------------------
> 
> Can you implement "getMainObject()" to return the "a"?
> (a instanceof MainClass)

No. But this is not necessary: it is always MainClass. Static methods are
always associated with the class in which they are defined, and not with a
subclass.

Just as non-static methods are always associated with the instance of the
class they are defined in, regardless of the (sub)class of the instance.


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2




==========================================================================
TOPIC: Newbee Question about random numbers
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d5332da2a87b1a4a
==========================================================================

== 1 of 6 ==
Date:   Sun,   Oct 24 2004 10:06 am
From: [EMAIL PROTECTED] (Bob) 

I'm new to programming. This is a school project that I'm working on.
At one part of this project, I need to scramble a String array to get
the words in array mixed up. I know how to use Math.random() to get
random numbers between 0 and the length of the array, but it will give
me repeated random numbers. How can I get unique random numbers? Also
I have those words displayed as buttons in an applet, any hint how can
I swap 2 words when 2 buttons are clicked? Any help would be greatly
appreciated.



== 2 of 6 ==
Date:   Sun,   Oct 24 2004 10:56 am
From: Tor Iver Wilhelmsen <[EMAIL PROTECTED]> 

[EMAIL PROTECTED] (Bob) writes:

> I need to scramble a String array to get the words in array mixed
> up.

Don't reinvent the wheel: Use
Collection.shuffle(Arrays.asList(theStringArray)).



== 3 of 6 ==
Date:   Sun,   Oct 24 2004 10:50 am
From: Oscar kind <[EMAIL PROTECTED]> 

Bob <[EMAIL PROTECTED]> wrote:
> I'm new to programming. This is a school project that I'm working on.
> At one part of this project, I need to scramble a String array to get
> the words in array mixed up. I know how to use Math.random() to get
> random numbers between 0 and the length of the array, but it will give
> me repeated random numbers. How can I get unique random numbers? Also
> I have those words displayed as buttons in an applet, any hint how can
> I swap 2 words when 2 buttons are clicked? Any help would be greatly
> appreciated.

You cannot create unique random numbers: they wouldn't ne random. But if
you swap the elements at each index (at the time of the swap) of the
array with another random element, the array is randomized anyway.

To swap 2 words in the buttons, use the JButton#setText(String) method.
For other answers to this kind of question, please read the API
documentation: http://java.sun.com/j2se/1.5.0/docs/api/


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2



== 4 of 6 ==
Date:   Sun,   Oct 24 2004 11:29 am
From: marcus <[EMAIL PROTECTED]> 

Bob, you are almost there.  Tor gave you the shortcut answer, but you 
need to learn to think things through.

you jumped from "scramble" to "unique random numbers", but never quite 
completed the thought.  This is essential in programming, and problem 
solving in general.

Shuffling is not picking random numbers out of a hat -- you got that. 
But you stopped at what shuffling is.  Shuffling is rearranging a list 
in random order with a one-to-one correspondence.  So the question is, 
how to take a list and randomize the *order* of the elements, which is 
not, as you pointed out, as simple as generating random numbers.

You would do well to avoid Collection.shuffle() IMHO, and figure out how 
to do your homework -- you might learn something along the way.

Bob wrote:
> I'm new to programming. This is a school project that I'm working on.
> At one part of this project, I need to scramble a String array to get
> the words in array mixed up. I know how to use Math.random() to get
> random numbers between 0 and the length of the array, but it will give
> me repeated random numbers. How can I get unique random numbers? Also
> I have those words displayed as buttons in an applet, any hint how can
> I swap 2 words when 2 buttons are clicked? Any help would be greatly
> appreciated.




== 5 of 6 ==
Date:   Sun,   Oct 24 2004 11:30 am
From: marcus <[EMAIL PROTECTED]> 

tor-- it is a kind of thing in this ng to not give homework answers, buddy

Tor Iver Wilhelmsen wrote:
> [EMAIL PROTECTED] (Bob) writes:
> 
> 
>>I need to scramble a String array to get the words in array mixed
>>up.
> 
> 
> Don't reinvent the wheel: Use
> Collection.shuffle(Arrays.asList(theStringArray)).




== 6 of 6 ==
Date:   Sun,   Oct 24 2004 11:22 am
From: Oscar kind <[EMAIL PROTECTED]> 

Tor Iver Wilhelmsen <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] (Bob) writes:
> 
>> I need to scramble a String array to get the words in array mixed
>> up.
> 
> Don't reinvent the wheel: Use
> Collection.shuffle(Arrays.asList(theStringArray)).

Ooh, I need to read the API docs more often. Thanks Tor!


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2




==========================================================================
TOPIC: Convert UTF-8 encoded data from file into unicode escape
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/518625c508ec82f8
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 10:04 am
From: Alex Kizub <[EMAIL PROTECTED]> 

My appology. Of course it should be hex numbers.
It's hard to think in the middele of the night.
But it's obvious and you can do hex numbers by yourself.

Here is one of solutions.
public class a{
   public static void main(String []a) throws Exception {

   java.io.FileReader fr=new java.io.FileReader("a.java");
   while (fr.ready()) {
     String hex=Integer.toHexString(fr.read());
     switch (hex.length()){
       case 1: System.out.print("\\u000"); break;
       case 2: System.out.print("\\u00"); break;
       case 3: System.out.print("\\u0"); break;
       case 4: System.out.print("\\u"); break;
       default: throw new RuntimeException( hex+" is tool long to be a Character");
     }
     System.out.println(hex);
   } fr.close();
 }
}

Alex Kizub.
Fritz Bayer wrote:

> Alex Kizub <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> > Fritz:
> > Convertion from utf-8 to unicode is Java loalization privilege.
> > So, let Java do what it supposed to do.
> >
> > public class a{
> >    public static void main(String []a) throws Exception {
> >    java.text.DecimalFormat f;
> >    f = new java.text.DecimalFormat();
> >    f.applyPattern("\\u0000");
> >
> >    java.io.FileReader fr=new java.io.FileReader("a.java");
> >    while (fr.ready()) {
> >      System.out.println(f.format(fr.read()));
> >    }
> >  fr.close();
> >  }
> > }
> >
> > Alex Kizub.
> >
> > Fritz Bayer wrote:
> >
> > > Hi,
> > >
> > > I'm looking for a little program, which reads utf-8 data from a file
> > > and writes it in the form of unicode escape into another text file.
> > >
> > > Why am I looking for something like this? Well, I have a file which
> > > contains utf-8 encoded data.
> > >
> > > That data I would like to build staticly into my program. So I would
> > > like to copy and paste it into a String constant (String
> > > ="\uxxxx\uxxxx...").
> > >
> > > However, since I can't just open up a viewer and copy and paste the
> > > contents (of course), I would have to convert it into unicode escape.
> > >
> > > Then I could copy and paste those escape code into my program. I
> > > thought that their must be some source code / program aroung which
> > > does that?
> > >
> > > Fritz
>
> Thank you Alex. I`m experience a small problem so. Some of the escapes
> look like:
>
> \u65533
>
> ie they are too long. I also noticed that none of the escapes contain
> hexadecimal, which seems to be wrong since unicode escapes contain
> them.





==========================================================================
TOPIC: Map that takes a pair of keys?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b8bfed67959eb893
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 11:43 am
From: marcus <[EMAIL PROTECTED]> 


> No, because it calls equals on a member variable; not on its own object.
> The method being called is not the same: it has the same name, but belongs
> to another object (unless key1 has the value this).

thanx -- man I must have some nasty assumptions running around in my 
brain about immutables (String, Integer) being just fancy primitives or 
something, and I am stuck on hash keys being primitives.  Ugh.

Anyhow I solved the problem, and learned a couple things -- so thanx all!





==========================================================================
TOPIC: Experienced programmer: where to start with Java?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/92371952fdc705d2
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 11:47 am
From: marcus <[EMAIL PROTECTED]> 

> I mean what aspects of Java should I be
> learning: applets, programs, wireless? 

my opinion, for what it's worth, is Java is largely used for web 
services, so learn servlets, beans, deployment.





==========================================================================
TOPIC: Can i use multiple bluetooth dongles on one computer?!
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bc883f14d78e1f6f
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 24 2004 11:50 am
From: marcus <[EMAIL PROTECTED]> 

man -- so many openings.
I want to write an application for my ford in java, so can someone tell 
me how many cars I can park in my garage?
I want to write an application for my cell phone in java, so can someone 
tell me how many phone numbers it can answer at once?
I want to write an application for my smart refridgerator in Java, so 
can someone tell me how many eggs it holds?

Ed -- learn to paint, buddy

Edward Klepping wrote:
> Paul Lutus <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
>  
> 
>>Tell us how this relates to Java, our topic.
> 
> 
> Because i plan to write the application for it all in Java and
> therefore wondered if any of you would know how you would do this in
> java - ie if you know how all the bluetooth java API worked and
> therefore suggest a way of tackling this problem java stylee, or tell
> me if its not possible.
> Cheers




=======================================================================

You received this message because you are subscribed to the
Google Groups "comp.lang.java.programmer".  

comp.lang.java.programmer
[EMAIL PROTECTED]

Change your subscription type & other preferences:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

Report abuse:
* send email explaining the problem to [EMAIL PROTECTED]

Unsubscribe:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe


=======================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to