Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It is most likely a focus issue. Read the tutorial on writing key listeners: http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

If you need to respond to specific keys being typed, it's usually easier to use a key binding instead of a key listener.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That error message should contain a little more information at the end. They are appending the string description on that line.

If you want more info than that, add an "e2.printStackTrace()" in the catch block. The app might need the images in the jar file. Open up the original jar and see what all is in there.

Edit: Yep, I just downloaded the app and checked. The images are in there as well. Try rebuilding your jar with

jar [B]u[/B]vf TunerApplet.jar TunerApplet.class

to update the existing jar (you may want to make a copy of it first :) )

samarudge commented: Very good information, helpful and quick response +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Happygeek already pointed out our acceptable use policy in your other thread.

Deletion of forum content is not merely a matter of request. Once you posted the information in publicly available forum, it became non-private by your own choice.

Edit: Cross-post with jbennet. Sorry for any confusion.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because a version of the xerces parser ships with the JDK and is used as the default DocumentBuilderFactory if you haven't registered a different one.

It's not using the libraries that you downloaded, but that may not matter to you at all if you just want a DOM to work with :)

If you have the xercesImpl.jar visible in the Libraries node of your Projects explorer, then you should be able to instantiate that parser directly without the compiler complaining.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you not have a "xerces.jar" file as well? From the online docs it looks like you should, but perhaps "xercesImpl.jar" has replaced that.

Edit: I just pulled down the latest binaries and xerces.jar is not in there, so that's out as a possibility. I still wonder about your project setup, because the error message points to a class path issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to add the jar files for those libraries to your project properties. In the Project Propteries window, select Libraries and add those jars in the Compile section.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Netbeans does allow you to work in GridBagLayout (or several others) from the designer if you set it yourself. It defaults to GroupLayout though, which is hideous to read.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks masijade.Still,not clear about this.
Say,test is a class which doesn't hav any parents.In such a case,why should i go specifically for runnable implementation instead Thread inherit.Pls,let me explain,the advantage of using runnable.

If there isn't any behavior of Thread that you need to alter by subclassing, why would you extend Thread? That's what they are saying here. If you can't point to an advantage in your code to extend Thread then you most likely have no reason to.

Keep in mind though, Runnable cannot return a value nor throw exceptions. If you need that functionality, use Callable.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here you have declared the type and size of the array

MovingPlatform[] platforms;
platforms = new MovingPlatform[1];

but you must still create an instance of each element

platforms[0] = new MovingPlatform();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The computer makers themselves are pushing the consumer market towards the 64 bit environment faster as they compete with one another. Having more ram is a selling point and we're marching right past 4GB fairly quickly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can go up to nearly 4GB with the 32-bit, so you still have room to nearly double your current ram before you would need 64-bit addressing.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's a small example that may be of some help. I've commented the relevant sections

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class WorkThreadExample extends JFrame{

    JButton btnGo;
    JLabel output;

    public WorkThreadExample(){
        btnGo = new JButton("GO");
        btnGo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                go();
            }
        });
        add(btnGo, BorderLayout.NORTH);

        output = new JLabel();
        add(output, BorderLayout.CENTER);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(200,200);
        setVisible(true);
    }

    /** called from button listener */
    private void go(){
        // start up a thread for our task and let the event queue get back to business
        Thread counter = new Thread(new CounterTask());
        counter.start();
        btnGo.setEnabled(false);
    }

    /** Small work task that we want to start from a UI event */
    class CounterTask implements Runnable{
        public void run() {
            try {
                for (int i = 0; i < 10; i++) {
                    final String countValue = String.valueOf(i);
                    // use this to put UI update tasks in the event queue
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            output.setText(countValue);
                        }
                    });
                    Thread.sleep(1000);
                }
                
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        output.setText("Done");
                        btnGo.setEnabled(true);
                    }
                });
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
        }
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                WorkThreadExample ex = new WorkThreadExample();
            }
        });
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is that all of that code is executing on (and holding up) the event queue, which is also responsible for repainting. You need to split that code off into a separate thread that calls for repaint() on the event queue when needed with EventQueue.invokeLater(Runnable) .

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The code fragment that you posted would only result in a single instance of the panel and should behave exactly as you want it to. The part I don't follow is that you say the panel is a class member of the frame, but you are making a frame.add() call. I thought this code was executing in the frame object, so what is frame ? If you can post the code it would clarify a bit.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, since it's difficult to see over your shoulder, perhaps you should post the current version of the code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you change the =="n" to equals("n") as Sciwizeh mentioned?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok congratulations, you've demonstrated that you can paste your homework. Do you have any specific questions? Anything at all to show that you have given this the least bit of thought?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't need a class name to call static methods within the same class - and that class name doesn't match anyway.

Also, make sure your method call matches the signature you wrote. You can't call a method that requires a String parameter without supplying a parameter.

'city1' shouldn't really be a parameter to the method. That is the value you want to send back from the method

return city1;

Re-read your class material on using methods.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It has to be inside the class. Just declare it after main(). It should return a String.

public static String getCityName() {

after you get a value from the user, return that value;

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Don't put it in a separate class. It doesn't really have any context as a separate object.

Just make a method getCityName() that returns the String that the user entered.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"case" is not capitalized.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Move your switch down below the point you are getting the input. You want to set the speed based on what they input and you want to switch on the first char of that entry

switch(roadChoice.charAt(0)) {

If you don't want to deal with the whole char/switch thing, you can always just use if()-else statements with the string data.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A and B are not variables themselves. They are two possible values for a variable that you want the user to set. So use a String variable for roadChoice that you read the input into. Then you can use roadChoice.charAt(0) to check the first character as a char value.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just like you got the other input, but you will need to use something like charAt(0) to get the first character of the String as a char value for your switch.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No. Change the value of speed separately from your print output.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

For A and B you could use char values, but not string values in the switch. If you use a String, you would have to use if() statements.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just have the user enter a number for the road type. Then your switch can simply be

switch  (roadType) {
  case 1:
    speed = 50;
    break;
  case 2:
      // ... etc
}

You will have to remove the "final" from your SPEED declaration.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have to cast the Object to Integer if you want to assign it to the array.

keys_Array[i] = (Integer)unsorted.get(random.nextInt(100));

Using generics to type your collections would avoid that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
for(int i=0;i<100;i++){
        keys_Array[i] = unsorted.get( random.nextInt(100) );
    }

Note that get() is used if 'unsorted' is an arraylist and not an array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can also use Random.nextInt(int) for the random int.

Keep in mind that the suggestions tendered so far will allow the chance that an element is selected multiple times. If you don't want that to be possible then you'll need to put additional measures in place to prevent it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you mean is there any better design I could follow without appending then I'm am not exactly sure because basically I have 4 tickboxes in the gui and when one is ticked the variable in the if statements changes to true. The tricky part is that the result is a complete array and the tickboxes selects what parts of the array should exist in other words different tickbox combinations will result in different arrays. Are there any examples on how I can do this?

I see that you have solved this part already, but I thought I would add a couple of examples of different designs you can use for that.

This one uses a small listener class that takes the list you want to append as a parameter. To map the check box, you create and add one of these listeners with the list you want to associate with that box. See the comments for clarification

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CheckboxDemo {
    JCheckBox box1;
    JCheckBox box2;
    JCheckBox box3;
    JTextArea output;

    // the lists we will map to the check boxes
    List<String> list1 = new ArrayList<String>(Arrays.asList(new String[]{"a","b","c"}));
    List<String> list2 = new ArrayList<String>(Arrays.asList(new String[]{"1","2","3"}));
    List<String> list3 = new ArrayList<String>(Arrays.asList(new String[]{"x","y","z"}));

    // this will hold the "final" list that results from clicks
    List<String> resultList = new ArrayList<String>();

    public CheckboxDemo() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);

        JPanel top = new JPanel();
        box1 = …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you can but it's rather unwieldy

ArrayList playerinfo = new ArrayList(Arrays.asList(new Object[]{"blah","blah"}));

It would be much cleaner to just make a small static method to build and return the test data.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sounds like you just need to tweak your coordinate math a little. If you got a solid triangle you are on the right track.

Edit: Oops, cross posted with santiagozky. I would agree that you should add more than if you don't want solids.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just a note: it's preferable to override paintComponent() in most cases instead of paint(), since paint() is also responsible to painting children and the border.
http://java.sun.com/docs/books/tutorial/uiswing/painting/closer.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's because you moved the code into the anonymous listener. If you aren't going to define that method on your class then remove the "implements ActionListener" from your class declaration.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In your Netbeans installation directory, go to "etc/netbeans.conf". There you will find an entry for "netbeans_jdkhome".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, looking at that brace on line 64, your code to add the listener is not in a method at all. So you've left out some other code in your post or that piece above won't even compile.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The literal value of a float in your code would be "6.0f", but printed output does not show that "f" unless you put it there explicitly.

Your output is perfectly fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you expecting it to print the "f"? Doubles and floats don't look any different as output.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Maybe you want to reverse line 23?

shroomiin commented: always helpful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That isn't Java code. Perhaps you meant to post this in another forum?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

(Yes, the HTML page source is just marked up text)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Much appreciated response ezzaral, just one quick question when reading the text from the url, does that automatically read the source of the page?

Give it a quick try and you'd have a definitive answer. :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
KirkPatrick commented: you've always been helpful around here bud, the world needs more helpful people like you +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

My suggestion: learn how to type and communicate effectively. It will serve you well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think you are correct that the behavior did stem from some blocking, but this can still be simplified a great deal to work without a separate listening thread.

Here's a re-wired version of the same that behaves itself. It's worth noting that these two versions only differ in what kind of socket is created to make one the "server". They could be coalesced to a single class. (It's also a quickly slapped together modification that doesn't properly handle exceptions or shut down properly and close io streams :) )

package game;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;

import javax.swing.*;

public class Clientms2 extends JFrame implements MouseListener {

    private static final long serialVersionUID = 1L;
    JFrame container;
    InetAddress address;
    Socket s;
    String host = "localhost";
    PrintWriter out = null;
    BufferedReader in = null;
    int port = 5656;
    String message;
    int mouseX, mouseY;

    boolean myTurn = true;
    JTextArea status = new JTextArea();

    public Clientms2() {
        super("Client 1: Player 1");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        //this.setResizable(false);
        addMouseListener(this);
        status.addMouseListener(this);
        add(status);
        pack();
        setSize(400, 400);
    }

    public static void main(String args[]) {
        Clientms2 client = new Clientms2();
        client.setVisible(true);
        client.run();
    }

    public void run() {
        try {
            address = InetAddress.getByName(host);
            s = new Socket(address, port);

            // establish streams one time
            out = new PrintWriter(s.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(
                    s.getInputStream()));

            // start processing
            myTurn = true;
            String input = "";
            while ((input = in.readLine()) != null) {
                if (!myTurn) {
                    process(input);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void mouseClicked(MouseEvent …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is that all of your code, including the thread.sleep() calls, are executing on the AWT event queue thread, which is the same thread that handles the repaint calls to update the display. You have to separate the animation updates from the painting. One way to do that would be to wrap the code you currently have in the show() method into a small Runnable class

class LineAnimation implements Runnable{
        public void run() {
            Vector<Line> LINES = this.lines(POINTS);
            Vector<Line> PWLINES = new Vector<Line>();
            for (int i = 0; i < LINES.size(); i++) {
                PWLINES.add(LINES.get(i));
                this.G.transfer(POINTS, PWLINES);
                this.G.repaint();
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                }
            }
        }
    }

and start a new thread with that Runnable in your show method

Thread lineAnim = new Thread(new LineAnimation());
lineAnim.start();

As BestJewSinceJC mentioned, a Swing Timer can also be used for this.

kolibrizas commented: A very decent help to my problem! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It all comes down to the details of "changing the look". Some things are trivial, others are quite complicated. You asked a very general question.

If you just want to set the frame to be borderless, use setUndecorated(true);