masijade 1,351 Industrious Poster Team Colleague Featured Poster

Just see the standard networking tutorial. Regardless of whether it is twisted pair, token ring, usb, whatever, whatever, you can and most definately should set up an IP network on it, then you can use the normal network classes.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I am quite sure someone has done this homework project before, but that doesn't mean anyone here is going to give it to you. For one, it violates the Terms and Conditions of use for this site (which you, and everyone else here, agreed to when signing up here). For another, and even more important point, it does not help you for someone else to do your homework for you. You don't learn anything, and it simply makes the rest of your course that much harder. And I definately would not want to work with you once you finish your schooling, as I definately would not want to continue having to do your work for you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

You need to add a save and a search button, which means, also, additional actionListener options.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

By starting your own thread in the JavaScript forum, maybe?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Take a close look at my previous post.

The first code block is your code, the second code block is modifications to that code.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Where would I place this? while (!phrase.equals("quit")) { If I do it before

length = phrase.length();

it won't run because I haven't initialized "phrase".

Well, think about that a bit.

...
        String phrase; // a string of characters
        ...
        // Read in a string and find its length
        System.out.print ("Enter a sentence or phrase: ");
        ...
        System.out.println ();
    }
...
        String phrase = ""; // a string of characters
        ...
        while (!phrase.equals("quit")) {
            // Read in a string and find its length
            System.out.print ("Enter a sentence or phrase: ");
            ...
            System.out.println ();
        }
    }
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Wrap the thing from that point on in a while (!phrase.equals("quit")) { loop.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
BestJewSinceJC commented: Yeah, it's not your fault though. +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Of course you will be using an import (excpet for those classes in the same package of course.

Either include the directory which contains the "root" of those classes packages on the classpath or create a jar and include that jar on the classpath.

http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, where is your attempt at it?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I don't know how it wouldn't.

Currently you read the input every time so that is 1 line of code for every input. Add the if statement as well as it's action and that is three lines of code for every input.

The method complete is 5 lines (with the closing brace), so, as of the third input read, instead of 9 lines of code it is 8 lines of code and th code is reduced by two lines for every additional read. Anf those calculations are assuming that you only have a single line inside of the if statement. If there are more than it pays off even quicker.

Plus you are not repeating the same code over and over and over again, which is just begging for problems. If what you do in that if block changes, you then have to change every if block (and hopefully you don't forget one), whereas with the method you change one. And what about if you then, later, also need to check for, say "start over" as well as quit? No the space saved has doubled.

But, hey, go ahead and do it your way. It's your choice.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have no idea what you mean.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You are calling the ethod without any arguments, but the method is designed to take an int and a double, so give it an int and a double.

pwk064 commented: Great help - Thanks! +0
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Write a method that reads the user input (I am assuming your getting input at various stages) and checks whether it is "quit" or not and otherwise returns the input as a String. Then, every place where you are currently reading input call this method instead.

tux4life commented: Good suggestion :) +6
javaAddict commented: Clever suggestion +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, no one here is going to do it for you.

Take it one small step at a time.

Take a piece of paper and draw out the way you wish it to look. Break that into parts (such as the view window, the scientific buttons, and the normal calculator buttons, and the memory keys), then create a panel for each of these things and create those, then place those panels on a frame, then start adding the actions behind the buttons, one button at a time.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That information seems to encapsulate a session, so Google around a bit and find out how to maintain a session using HttpURLConnection.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry, brainfart.

Starting after initComponents (if done within the SwingUtilities) is bad as you are kicking it off from the Swing Event Thread, and you should, really, avoid that, if possible. Try it this way. Remove the "detectUSB" constructor and then change the main as follows:

public static void main(String args[]) {
        detectUSB dusb = new detectUSB();
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    dusb.initComponents().setVisible(true);
                }
            });
        new usbThread(dusb.lbl_status).start();
    }

And, in any case, change the usbThread constructor as follows:

usbThread(JLabel label) {
        this.label = label;
        setDaemon(true);
    }

To ensure that the thread dies properly.

Edit: And, not intending to nitpick, it is standard Java programming convention to capitalise Classes so those class names should be DetectUSB and USBThread.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The browser is not "resolving" anything. The site is "redirecting".

So, are you using URLConnection or HttpURLConnection? HttpURLConnection will "follow" redirects, by default, URLConnection, won't.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Change this

usbThread thread = new usbThread();

    public detectUSB() {
        initComponents();

        thread.start();
        

        final JLabel label = lbl_status;
        final String text = thread.getThreadStatus();

        SwingUtilities.invokeLater(
                new Runnable() {
                    public void run() {
                        label.setText(text);
                        label.validate();
                        label.repaint();
                    }
                }
            );
    }

to this

public detectUSB() {
        initComponents();
    }

and change this

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new detectUSB().setVisible(true);
            }
        });
    }

to this

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new detectUSB().setVisible(true);
            }
        });
        new usbThread(lbl_status).start();
    }

and change this

public class usbThread extends Thread{
    public String status=".....";
    usbThread()
    {
      
    }

    String getThreadStatus()
    { 
      return this.status;
    }

    @Override
    public void run() {
        ....
        this.status="FindDrive: waiting for devices...";
            ....
                this.status="Drive "+letters[i]+" has been plugged in";
            else
                this.status="Drive "+letters[i]+" has been unplugged";
                ....
            }
            try { Thread.sleep(100); }
            catch (InterruptedException e) { /* do nothing */ }
        }
    }

to this

public class usbThread extends Thread{
    private String status = ".....";
    private JLabel label;
    usbThread(JLabel label) {
        this.label = label;
    }

    private void postStatus() {
        SwingUtilities.invokeLater(
                new Runnable() {
                    public void run() {
                        label.setText(status);
                        label.validate();
                        label.repaint();
                    }
                }
            );
    }

    @Override
    public void run() {
        ....
        this.status="FindDrive: waiting for devices...";
        postStatus();
            ....
                this.status="Drive "+letters[i]+" has been plugged in";
            else
                this.status="Drive "+letters[i]+" has been unplugged";
                ....
            }
            postStatus();
            try { Thread.sleep(100); }
            catch (InterruptedException e) { /* do nothing */ }
        }
    }
majestic0110 commented: Patience of a Saint! +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

E.G.

class Checker extends java.util.TimerTask {
  private JLabel label;
  Checker(JLabel label) {
    this.label = label;
  }
  public void run() {
    //check the drives
    final String text = <status>;
    // call invokeLater
  }
}

public class myApp {
  public static JLabel createAndStartGui() {
    JLabel sLabel = new JLabel();
    // create the GUI, set it visible using the above reference
    return sLabel;
  }
  public static void main(String args) {
    JLabel l = createAndStartGui();
    java.util.Timer t = new java.util.Timer(true);  // start as Daemon
    TimerTask tt = new Checker(l);
    t.scheduleAtFixedRate(tt, 0, 100);  // do you really need to check 10 times per second
  }
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because I never said to put the entire thing into "invokeLater". InvokeLater should be used entirely as, and contain nothing more, than shown there. The rest of that should be running in another thread that is started alongside the rest of the application and simply given a reference to the label that it is to update so that it can invoke it in the call to SwingUtilities.

I assume you are starting a GUI out of your main method? If so, do that and keep a reference to this "status label", then start another thread with this stuff in it, passing this "status label" in the constructor, and at the spot where the label is to be updated, call invokeLater.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then normal swing standalone app.

A preparedstatement, its setString method, and the textfields getText method.

That should get you started.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A mistake that is completely self correctable

final JLabel label = <reference to the label>;
final String text = <text to change to>;
SwingUtilities.invokeLater(
        new Runnable() {
            public void run() {
                label.setText(text);
                label.validate();
                label.repaint();
            }
        }
    );
masijade 1,351 Industrious Poster Team Colleague Featured Poster

MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

Sorry, of course a complete redesign is not in order, but you do need to change DBs.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I think that you can write a server/client solution to get it to work. The client connects to the server which returns the content of the database. I did something like that when I needed my applet to read from a database, but I don't remember all the details.

An applet has no problems connecting to a DB, as long as the DB exists on the same server as the machine that served the page, and the DB is a client/server DB and not MS Access.

Of course you can build your own client/server protocol and connection to enable connection to MS Access, but why? Why pay the hefty license and software costs only to have to build your own (possibly buggy) access routines in order to be able to even use it when there are a plethora of free client/server DBs out there, and most of them are better than MS Access in the first place.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I need more details. I don't understand what you are actualy doing. The best method would be to make a JTable in which you can see your database table records. Then you can go further. I mean how can you modify something if you can't see what row u actualy modify? (I'm guessing)

Under normal circumstances, how is he to access an MS Access DB from an Applet? It is the pinnacle of arrogance to suggest that the clients should modify their security settings for your app.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have a background operation which runs infinitely. I want to set JLabel's text from that thread as it would be the status of the operations in that thread or the progress?

final JLabel label = <reference to the label>;
final String text = <text to change to>;
SwingUtilities.invokeLater(
        new Runnable() {
            label.setText(text);
            label.validate();
            label.repaint();
        }
    );

Did I miss something in the description?

Yes, you missed stating what you wanted to do. As I said "access a component" means, essentially, nothing. It is what you want to do with it that makes a difference.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What are you trying to do with the component. "Access a component" means literally nothing.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

With a compare(obj, obj) or compareTo(obj) method, a loop, a toString() method, and the println(string) method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Each package has it's own directory (in the normal state of affairs, there are other ways of doing it, but we won't get into those).

I.E. Hypothetical, your source code is under
/my/source
and your compiled code is under
/my/classes
then for the package
thisIs.myPackage
and the class
DontYouLikeIt
the java file should be located at
/my/source/thisIs/myPackage/DontYouLikeIt.java
and the class file should be located at
/my/classes/thisIs/myPackage/DontYouLikeIt.class

So, hopefully those "5 programs" all have the same package and not just "a pacakge".

Now, what exactly, is your problem?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I give up. You make a change, then later claim that you don't where the change is to be made, then you make another change, that is the counter-point to the first change, with expected results, and wonder why it goes wrong.

All I can say now is, look at your code and balance your braces. for every '{' there should be a '}'. And indent your code properly. As it is now it is very hard to be read clearly.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
cmd /c <command>

See http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

And read it completely and thoroughly, although I can't imagine why you would really want to do all this.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Redesign that "insertdetails" thing. You should not be cobbling together SQL statements like this. It is far too error-prone and an extreme security risk. You have no idea how easy it is to perform an SQL Injection attack like that.

Also, is "setVisible(false);" suppossed to be outside of the method? It is, in the code you posted, which would make this utterly uncompilable.

If, in the "real" code, it is inside the method, I would say that is causing your application to exit (especially if your default close operation is EXIT_ON_CLOSE), or simply hiding it otherwise, regardless of what else happens in that method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Also, closing a JOptionPane definately should not cause the entire application to close. What does the rest of the method where this statement resides look like?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And what about the rest of the post?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What exception, and your problem could possibly be solved by using the "short-circuit" or "||" instead of "|", because that way the second half of that if statement won't even be evaluated if the first half is false. Currently, they are both being evaluated regardless of whether the first is false or not. Also, does not "getText()" return a String? Normally that type of method will, so I don't understand the "toString()" call after that.

Also, what is the rest of the statement after the "|", as the forum seems to have let it run of the end of the window so I can't see it (after the toString call).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Break all those scriptlets out into a Bean or three. Do not use scriptlets in a JSP any more than absolutely necessary (which they never really are). They are nothing but a maintenance nightmare (as you are now experiencing).

masijade 1,351 Industrious Poster Team Colleague Featured Poster
Integer.toBinaryString((int) 'J')

See the API docs.

And don't forget to left pad it with zeroes, as it will only produce a String as long as it needs to be, rather than the full 8 bits. I.E. if the "full" bit string should be "0000101" this will only produce "101". Or, if the bit string should be "00110010" it will produce "110010".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That depends. What exceptions or compiler messages are you getting?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Around this

for (int i = 0; i < numbers.length; i++){
  sum += numbers[i];
  float average = sum / TOTAL_NUMBERS;
}

either move the '}' above the average calculation (which is better IMHO) or remove both the '{' and the '}'.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You forgot the '{' after the for statement on the block before this point.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
String pic = rs.getString("pincode");

not

String pic = rs.getString(pincode);

Also, use a preparedStatement, cobbling a statement together using String concatenation like you've done is just begging for trouble. Maybe only as innocent as a mistyped user input string that causes the SQL to fail with a syxntax error, or as damaging as an intentional SQL Injection attack.

Edit: And this

if(pic=="pincode")

is probably backwards, too.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What is this? Has this thread become the new "I'll just dump my trash here" thread?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, let's see what you have.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Have you tried using System.setProperty as the first couple of lines in your main method?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You defined your imageicon as ic and then try to use it as img.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

To gain some understanding of what? You essentially asked for a complete "user's guide" to your assignment. If this is your assignment, I can guarantee that other assignments before this have used the print/println statement, so the "question" about "display" is a moot point (unless you need to show it in a dialog, but then you should say that, if that is the case). Now, you might, and I stress, might, not have had anything to do with loops yet, but I doubt that, so I must ask how much sleep you are getting at night to need this much sleep during your classes?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Did you read the API docs for ArrayList, yet? I'll take that as a no.

KimJack commented: Very rude individual +0