I'm trying to write a mothod in C# that will find the value of a point by bicubic interpolation.
basically I have an array of 16 (4x4) float values that are either 1.0f or 0.0f and i am trying to get the float value of a single point by interpolating from the 16 points.

I am writing a program that does one thing, it finds out the current link speed of the wifi connection and reports it to the user in real time. the problem I am having is that it does not seem to be able to find out the current link speed, only the max link speed of the device (300 Mbps). the reason I am writing this is that I have a problem where, periodically the link speed will drop drastically (down to 1-2 Mbps) and I want to be able to see when that happens. with this code it will simply give me the maximum speed that the adapter supports, not the current link speed of the connection.

private void update(object state)
{

    System.Net.NetworkInformation.NetworkInterface[] nics = null;
    nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
    long speed = 0;
    string adapter = "";
    foreach (System.Net.NetworkInformation.NetworkInterface net in nics)
    {
        if (net.Name.Contains("Wireless") || net.Name.Contains("WiFi") || net.Name.Contains("802.11") || net.Name.Contains("Wi-Fi"))
        {
            speed = net.Speed;
            adapter = net.Name;
            break;
        }
    }
    string temp;
    if (speed == 0)
    {
        temp = "There is currently no Wi-Fi connection";
    }
    else
    {
        temp = "Current Wi-Fi Speed: " + (speed / 1000000) + "Mbps on " + adapter + ". " + System.DateTime.Now;
    }
    if (label1.InvokeRequired)
    {
        SetTextCallback d = new SetTextCallback(update);
        label1.Invoke(d, new object[] { temp });
    }
    else
    {
        label1.Text = temp;
    }
}

this method is called periodically by this code

System.Timers.Timer timer = new System.Timers.Timer(200);
timer.Elapsed += new System.Timers.ElapsedEventHandler(update);
timer.Enabled = true;

right now the problem is that ...

the problem has been solved, it turnes out that there was a loop that it was getting stuck in when it was not running in netbeans because the loop was hogging cpu time and not letting other threads continue. added a delay inside loop, works fine now.
thank for all the help

i have done some more testing and it only works in the netbeans ide, it does not work in jGrasp

C:\Users\al>java -jar "C:\Users\al\Documents\NetBeansProjects\LANMessagingProgram\dist\LANMessagingProgram.jar"

this is the command I use to run the program. no further output is generated by the command prompt

the jar file contains eveything it is supposed to in the right places and the manifest is forrect

i have been running through command promt using java -jar "jar file path"

I checked the jar contents and all the necicary classes were there as well

this code sets up the GUIs:

setupGUI = new SetupGUI (true); // create the setupGUI
setupGUI.waitForDataFromSettupGUI (); // waitUntil the setupGUI is done
handle = setupGUI.getUser(); // get setup info
chatChannel = setupGUI.getChatChannel();
password = setupGUI.getPassword();
gui = new GUI(chatChannel, handle); // create the main GUI

this code sets up the main GUI

public GUI (String chatChannel, String handle) {
    super ("Chatbox - channel: " + chatChannel + " as user: " + handle);
    initComponents(); // initializes all the GUI elements - created by netbeans
    setVisible(true);
}

the problem i have is that this all runs flawlessly in netbeans.
and when I run it outside of netbeans it does not generate any errors
however, the second GUI still does not appear.

you will probably want to have each sound in a Sound object (you will have to write it)
and include a method of running it in a seperate thread.

import java.applet.AudioClip;

class SoundPlayer extends Thread
{
    AudioClip sound;
    public SoundPlayer (AudioClip sound)
    {
        this.sound = sound;
    }

    run ()
    {
        sound.play();
        stop();
    }
}

instatiate your audio as a SoundPlayer

SoundPlayer gunSound = new SoundPlayer (gunshotAudioClip);

when you want to play the sound

gunSound.start(); // this will play your sound in a new thread.

that is basically the code I use when i need to use sound effects in a game or other program

see this tutorial on how to get the words in from the file
http://docs.oracle.com/javase/tutorial/essential/io/charstreams.html

once you have all the words sorted into an array, select one at random using the random number method of your choice (Math.random () or java.util.Random)

now break your word down into a char array

char [] charWord = word.toCharArray();

creat a new char array of the same length as your word

char [] guessed = new char [charWord.length];

now populate it with stars

for (int i = 0; i < guessed.length; i++)
{
    guessed [i] = '\*';
}

check if the person guessed a correct letter using
if they did guess correctly then replace the star with a letter

int instancesFound = 0;
for (int i = 0; i < charWord.length; i++)
{
    if (charWord[i] == letter)
    {
        instancesFound ++;
        guessed[i] = letter;
    }
}

if they did not guess correctly then instancesFound will still be 0

you need a way of keeping track of how many wrong guesses and what they were

String guessedLetters = "";
if (!guessedLetters.contains (letter))
{
    guessedLetters+=letter;
}
if (guessedLetters.length () > MAX_GUESSES)
{
    game over
}

to get input from the user use Scanner class

import java.util.Scanner;

Scanner scanner = new Scanner (System.in);
String input = scanner.nextLine();

or

char inputchar = scanner.nextLine().charAt(0);

to output to the user use System.out.println()

System.out.println (output);
System.out.print(output);

use a while loop to continuously go back to the start.

while (true)
{
    // insert code here
}

I know i've done quite a bit of ...

JamesCherrill commented: Very clear, very helpful +14

basically my program runs like this

  1. open up configure GUI
  2. get congiguration
  3. close configure GUI
  4. open up main GUI

now when I am testing in netbeans, this works perfectly however, as soon as I compile and try to run the jar file outside of netbeans the 4th step fails. I am at a loss as to why this is happening so if anyone can shed some light on it it would be a great help

I'm just starting out in C++ and want to use TextOut to print a character that is generated at runtime based on keyboard input but am having trouble converting TCHAR to LPCWSTR so that it can be used in the TextOut method.
my code is
[CODE]
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
int kbrdId, kbrdEvent;
TCHAR chCharCode;
int lKeyData;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    EndPaint(hWnd, &ps);
    break;
case WM_CHAR:
    {
        chCharCode = (TCHAR) wParam;
        lKeyData = lParam;
        kbrdId    = LOWORD(wParam);
        kbrdEvent = HIWORD(wParam);
        TCHAR s (32);
        HDC hdc = GetDC(hWnd);
        TextOut (hdc, 40,40, chCharCode, 1);
    }
    break;
default:
    return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;

}
[/CODE]

I want to print any character that is pressed on the keyboard on the screen.
please don't suggest printf because it this is a GUI not a console app.
thanks

unfortunately no, I have a similar problem my self, I was simply offering another way to approach the problem

you need to directly access the systems event queue, opposite to what the Robot class does.
for this to work, your keylogger must scan each event before the default system event handling gets to it.

often when you try to mod a negative number, the results can be unexpected.

try this
[CODE]
// to encrypt
int numberOfCharacters = 256;//the number of chars in your alphabet
int key; //the number of chars you want to shift by
String clearText = "hello";
String encrypedText = "";
key = key % numberOfCharacters;
for (int i = 0;i<clearText.length();i++){
encryptedText = encrypedText+(char)((int)clearText.charAt(i)+key %
numberOfCharacters);
}
// to decrypt
clearText = "";
for (int i = 0;i<encryptedText.length();i++){
clearText = clearText+(char)((int)encryptedText.charAt(i)-key+numberOfCharacters %
numberOfCharacters);
}

[/CODE]

try having the action listener call a method that resizes the frame instead of resizing the frame directly

Ezzaral commented: You resurrected a four-year-old thread just to post this? -3

I am writing a program that needs to be able to respond to keyboard actions regardless of what application has the focus at the time but after hours of searching the internet I have found no way to do this. for example, the program needs to be able to respond to keystrokes being entered into MS word without disrupting MS words reaction.
to clarify, I need to retrieve all events directly from the operating systems event queue.

that code is useless but I can replace all the print stuff and make it useful

I just need to know how to use this
[CODE]class NewThread implements Runnable
{
Thread t;
NewThread ()
{
// Create a new, second thread
t = new Thread (this, "Demo Thread");
System.out.println ("Child thread: " + t);
t.start (); // Start the thread
}
public static void main (String [] args)
{

}

// This is the entry point for the second thread.
public void run ()
{
    try
    {
        for (int i = 5 ; i > 0 ; i--)
        {
            System.out.println ("Child Thread: " + i);
            // Let the thread sleep for a while.
            Thread.sleep (500);
        }
    }
    catch (InterruptedException e)
    {
        System.out.println ("Child interrupted.");
    }
    System.out.println ("Exiting child thread.");
}

}

class ThreadDemo
{
public static void main (String args[])
{
new NewThread (); // create a new thread
try
{
for (int i = 5 ; i > 0 ; i--)
{
System.out.println ("Main Thread: " + i);
Thread.sleep (1000);
}
}
catch (InterruptedException e)
{
System.out.println ("Main thread interrupted.");
}
System.out.println ("Main thread exiting.");
}
}[/CODE]

could you tell me how to use mouseListener, I havent been able to get it to work eather, the help library i have is horible.

I don't have an object so mouseListener isn't what I need. This is my code for finding the location, is there a method that is similar for finding the status of the mouse bottons.
public static int return_x ()
[CODE] {
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
return (x);
}
public static int return_y ()
{
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int y = (int) b.getY();
return (y);
}
}[/CODE]

I don't know how to check if a mouse button has been pressed

i'm writing a program that can tell me where my curser is and whether the bottons are being pressed

I want to create a new thread in a program that i'm working on but i cant get my new threads to start
does anyone have some code that would allow me to create and start new threads