Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if that action listener is attached to a button, then the source will be that button and has nothing to do with the component that you want to act upon. So I don't think you really want to call paste on that anyway. I was merely addressing the casting problem.

You may want to take a look through some of the tutorial on implementing copy and paste: http://java.sun.com/docs/books/tutorial/uiswing/dnd/textpaste.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

From what I can tell, JCreator has build capabilities that should allow you to create the jar within the IDE. After you have learned to create it from the command line (which you definitely should learn to do), you should also learn how to do it with the IDE build capabilities.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to cast e.getSource() to an appropriate type that implements the paste() method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As an argument to the constructor or within the default constructor? Hopefully not as args to the constructor, because that is pretty arbitrary and useless. If you want to pass some initial entries in the constructor, you are much better off accepting a String array as the parameter and copying those to your internal array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, you still aren't making much sense, but perhaps these two links will be useful:
Sound API: http://java.sun.com/docs/books/tutorial/sound/index.html
JMF: http://java.sun.com/javase/technologies/desktop/media/jmf/reference/docs/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Swing is a single-threaded event model. If you are executing the code that updates the table in a button action listener then you are essentially "holding-up" processing other UI events like repaints, table updates, etc.

If you want the table to update over the course of a long running process you will need to perform that processing in a separate thread and push UI updates onto the event dispatch thread.

This tutorial may help: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Alternately, you could have just used the add(Object) signature without specifying the index, since you're entering them in order anyway.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Read the API doc for ArrayList.add(int,E) It states that will be thrown if index < 0 or index > size(). Your error message gives that information to you as well. How can you insert an element at index position 1 when size is 0? The indexes are zero-based, so you must insert the first element... (your answer here)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i have a quick question.

how do i add two advices to the array within the constructor and update index accordingly?

Just like you add any "advices" to the array - you call the method that you wrote. That is what it's there for.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This loop works just fine when I run it

while(add.equals("y")) {
    // Booth 1.
    System.out.println("BOOTH 1");
    // ... stuff
    System.out.println("Would you like to add more votes (y/n)?");
    add = scan.nextLine();
}

Converting this to use a boolean instead

boolean add = true;
while(add) {
    // Booth 1.
    System.out.println("BOOTH 1");

    System.out.println("Would you like to add more votes (y/n)?");
    String response = scan.nextLine();
    add = ("y".equalsIgnoreCase(response));
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The "green bracket" does not include the question to continue in the while loop at all, and since you set add='y' to begin with it will always be true. You need to use the "red bracket" and determine why "add" is not equal to "y" when you want to continue.

I would recommend you use a boolean value for "add" instead of the string comparison. Set that boolean based on the value of the input from your question.

Also, always indent blocks such as your while() loop block. Proper code formatting isn't just for "prettiness" - it helps you visually keep track of the logical structure of your code more easily.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Typically, yes, you place a while loop around that section that checks a boolean variable like "continue" or "moreEntries" (or whatever). That variable is set based upon the response to your question, in your case the value of "add".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not if you don't post the code. We really can't speculate what you have written.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In unix is device is represented as a file , open it read , write it.

What? This is even less coherent than the poster's question.

rainny, you need to restate the question and provide a little more info on what you are trying to do. As written, it is not clear.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you want step-by-step guidance then you need to hire a private instructor or seek out books and tutorials laid out in such a manner. peter_budo gave you the first step. It's up to you to follow it. We're here if you have questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please find the below code which might solve your problem:

Giving the answer to the exam question does nothing to promote active thought on the problem. Hints and suggestions, rather than canned solutions, are more appropriate.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No and no. Hydrogen is not currently a feasible replacement solution.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the Map.keySet() method. It will return a Set of the keys in the map. A for-each on that Set will allow you to compare the key value easily and Map.put(key, value) will replace the value if key already exists in the map. You should be able to implement your method pretty easily with that info.

Also, on "iii", you may want to look at the enclosures you used around the method parameters. Do those look right for a method call?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look at this loop and walk through each iteration in your head or write down the values for one or two iterations and I think you will see the problem

for(i = 0;i <=(i-1);i++)
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

round() returns a long if you pass it a double, which your calc is doing. You can just cast that to an int.

Array1[size]= (int)Math.round (Math.random()*100);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, 2 main problems with the method that creates your array - see comments in the code belowe

int[] Array1= new int[size];
        // you are changing 'size' in this loop
        // use a new variable in the loop
	[B]for(size = 0;size <=(size-1);size++)[/B]
	{
	    // casting Math.random() to an int will always yield zero
           [B]Array1[size]=(int)Math.random();[/B]
	}

If you need a random number between 0 and X, use Math.round(Math.random()*X).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, what problems are you having? What errors if any? Posting several lines of abbreviated variables and equations and saying "it's not right" is a bit vague.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It should work just fine for those components provided those character sets are available on your machine. This shows a bow-tie for me with no other setup

JOptionPane.showMessageDialog(null,"\u22c8");
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The location of the component within the cell(s) is affected by the anchor. Depending upon the .fill setting, it will also affect the direction in which components expand to fill available space in conjunction with the weightx and weighty properties.

GridBag does take some experimentation to get comfortable with how all of those properties work together. As you have already discovered, grouping related components into their own panels and them placing those panels into other containers makes managing those layouts much easier. Also, sometimes placing a "spacer" blank label into the grid to absorb "dead" space can be helpful if you just can't get certain areas to stay put while others expand.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try giving the comment text area a grid width of 4, fill both, and weightx/y of 1.0. Place the button panel in the fifth column. Here's an example of that layout that might help

public class GridBagFrame extends javax.swing.JFrame {

    public GridBagFrame() {
        initComponents();
    }

    private void initComponents() {
        java.awt.GridBagConstraints gbc;

        panDetail = new javax.swing.JPanel();
        panTime = new javax.swing.JPanel();
        panTemp = new javax.swing.JPanel();
        panTank = new javax.swing.JPanel();
        panTimePoint = new javax.swing.JPanel();
        scrollComment = new javax.swing.JScrollPane();
        txaComment = new javax.swing.JTextArea();
        lblComment = new javax.swing.JLabel();
        btnQuit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        panDetail.setBorder(javax.swing.BorderFactory.createTitledBorder("Detail"));
        panDetail.setMinimumSize(new java.awt.Dimension(120, 60));
        panDetail.setPreferredSize(new java.awt.Dimension(120, 60));
        gbc = new java.awt.GridBagConstraints();
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(panDetail, gbc);

        panTime.setBorder(javax.swing.BorderFactory.createTitledBorder("Time"));
        panTime.setMinimumSize(new java.awt.Dimension(120, 60));
        panTime.setPreferredSize(new java.awt.Dimension(120, 60));
        gbc = new java.awt.GridBagConstraints();
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(panTime, gbc);

        panTemp.setBorder(javax.swing.BorderFactory.createTitledBorder("Temp"));
        panTemp.setMinimumSize(new java.awt.Dimension(120, 60));
        panTemp.setPreferredSize(new java.awt.Dimension(120, 60));
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(panTemp, gbc);

        panTank.setBorder(javax.swing.BorderFactory.createTitledBorder("Tank"));
        panTank.setMinimumSize(new java.awt.Dimension(120, 60));
        panTank.setPreferredSize(new java.awt.Dimension(120, 60));
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(panTank, gbc);

        panTimePoint.setBorder(javax.swing.BorderFactory.createTitledBorder("Time Point"));
        panTimePoint.setMinimumSize(new java.awt.Dimension(120, 60));
        panTimePoint.setPreferredSize(new java.awt.Dimension(120, 60));
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(panTimePoint, gbc);

        txaComment.setColumns(20);
        txaComment.setRows(5);
        scrollComment.setViewportView(txaComment);

        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 4;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        getContentPane().add(scrollComment, gbc);

        lblComment.setText("Comments:");
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 4;
        gbc.fill …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Alex is correct. Generics became available with 1.5. And 1.2 is way too old to be using for anything these days.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i am so confused were am i? i was only trying to find a site where you can chat to yer mates like msn... can u help me?

Oh, you want the site just down the street for that. It's the blue one on the left.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think Nader's potential to be a spoiler has dwindled to insignificance this time around.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, that and the fact that there are a lot of people around we just don't want to think about seeing naked! :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Wander outside for a smoke or a walk around the building. As mentioned, the nude thing just wouldn't work in the office - and I don't touch code when I'm at home with the exception of a very rare occurrence of having to remote in or work from home.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't need to declare char arrays for every value in the word list. You have a single word chosen randomly from that list and you only need to worry about the characters in that word

char[] characters = randomString.toCharArray();

or you can dispense with the array and check any character with

randomString.charAt(0)

for any position 0 to length-1.

majestic0110 commented: A relentless helper!! +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start by adding a string array to that class. Re-read your class notes on arrays if you have difficulty declaring it. You were given the size to make it.

Then work on the addAdvice() method to add a string to that array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The instructions are very clear. You have to add an array to that class to store each "advice". The add method should add that string to the array and the get method should return a random entry from that array. Short of telling you exactly how to do it, I don't see what more needs to be said.

If you have a specific question then ask it, but the instructions are simple enough that you should know how to start.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use regex to parse out the links and push them onto a stack, pop the stack, get that page and gather the text or whatever, continue through the stack.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Place the mouse listener code in your custom tab component and add the listener to that component.

class ButtonTabComponent extends JPanel implements MouseListener {

    private final JTabbedPane pane;
    private final JButton button;

    public ButtonTabComponent(final JTabbedPane pane) {
    ...
    addMouseListener(this);
    ...
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to narrow that down a bit or highlight the additions that caused the problem and explain what you are trying to do, because I doubt many people are going to wade through that much GridBagLayout code based on what little you described.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"this" already refers to that inner class instance. You only need to qualify it if you want to refer to the enclosing class instance, like "Testing.this".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"this" refers to the enclosing instance, which in your case above is an anonymous inner class that implements ActionListener. It's not a JFrame. If you drop the "this", or qualify is with "Test.this" it would work fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just call

whateverFrame.dispose();

in the action listener.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And please include the code in post with [code] [/code] tags. Many people, myself included, do not want to mess with attachments to glance at your code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

shobshank, read the other 500 threads for "need project suggestion" or "final project help". Also, drop the "text-speak". Write properly or don't bother.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's a unique way of structuring it, but if all of the listeners are performing essentially the same action with differing parameters then that is still too much redundant code. There is no reason to repeat that much boilerplate code unless each operation is distinct to a degree that cannot easily be represented as a shared class.

In the case of the poster's color buttons, a simple action class is all that is needed to encapsulate the action for each case and minimize the repetitive code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The default layout manager is FlowLayout, which is what your JPanel is currently using since you have not changed it. You can change the positions of those text fields all day but FlowLayout won't respect them. It wasn't designed for that.

I would recommend using a BoxLayout or GridLayout if you just need to stack them, but you may need to examine the capabilities of other layout managers and play around with them to get things working like you desire. Take a look through this tutorial on laying out components:
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Sun tutorial on Reflection is a pretty good place to start:
http://java.sun.com/docs/books/tutorial/reflect/index.html

Keep in mind that using reflection to manipulate classes and methods is much slower than normal compile-time usage patterns (and the code is pretty long and unwieldy to boot) and should only be done when you need to work with classes or methods that are not present at compile time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The code that Alex Edwards posted will work for that scenario, but the action listener code can become quite long, verbose, and repetitive for your button array. A cleaner way to handle that would be to create a small action class for those buttons, like

class ColorButtonAction extends AbstractAction{
    Color buttonColor;
    
    public ColorButtonAction(Color buttonColor){
        this.buttonColor = buttonColor;
    }
    public void actionPerformed(ActionEvent e) {
        // your code to set the color here
        setColor(buttonColor);
    }
}

and when you create the buttons for the array just create the appropriate action instance

new JButton(new ColorButtonAction(Color.BLUE) )
// or you can set the action on an existing button 
button[0].setAction(new ColorButtonAction(Color.BLUE));
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot seriously think it's a good idea to take code written by others and submit it as your own for an interview. If you cannot complete the project then you should not get the job.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Futbol10, you already have a thread for this question. Please don't posts requests for help into other posters' threads (especially not old posts).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You simply reply to it. If you have changed the code, repost it in the reply.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might have better luck posting this (after searching a bit) over in the Sun Java forums that apply to installation issues:
http://forum.java.sun.com/forum.jspa?forumID=32
http://forum.java.sun.com/forum.jspa?forumID=14