JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are using a seriously out-of-date source for your info.
The whole Class.forName thing was replaced as of Java 1.4 or 1.5 (Yes, that's more than 10 years ago).
Forget the obsolete info you have been given and start again with current Java. Here's the up-to-date tutorial:
http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have a spurious . between String and id on line 3

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My advice is never do anything you wouldn't want your friends and family (or clients) to know about. Sooner or later they will find out, and in the meantime you are just living a lie.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"Without using code" means "in Netbeans GUI designer"? If so I can't help. In my opinion the GUI designer is far more trouble than it's worth for any real life application where you're worried about cross-platform differences and handling window re-sizing. I just write the code; it's not that hard, and you know exactly what you're doing.

People often add a JLabel with an ImageIcon and stack that behind their actual content

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You want a number of panels each occupying exactly the same space and you want just one of them to be visible at any time and you don't want tabs?
If that's the case then CardLayout is the one to use. Here's two tutorials (read both, in this order)...
https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
http://stackoverflow.com/questions/21898425/how-to-use-cardlayout-with-netbeans-gui-builder

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK.
If you don't want the tabs then you can place a whole lot of JPanels at the same place and make all except one invisible setVisible(false) When you want to change panels make the current one invisible and the next one visible.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thank you for posting your assignment - I'm assume your teacher gave you permission to post their intellectual property on a public web site? You don't seem to know whqat language it shoud be written in. You obviously didn't read the DaniWeb rules that you signed up to - including "Do provide evidence of having done some work yourself if posting questions from school or work assignments". You didn't even bother to ask a question. Maybe you think someone will just do your homework for you?

I suggest you start again. Ask a proper question, and show what you have already done to try to answer it youreself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you read the link I gave you for JTabbedPane? That's what it does.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Q1 - don't understand the question. It is in the scope, and lines 52-56 have nothing to do with it
Q2 - updateGui takes an instance of ActionEvent as a parameter. Where it is called there is a suitable instance in the variable e (it was passed in as a parameter to the actionPerformed method).

ps: I;m going out now, so no more answers until tomorrow.
J

pps: Back now.
When you post code you can omit all the standard stuff that Netbeans generates (initComponents and main) - just leave the method header and the closing bracket.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You seem to have tried to incorporate the SimplestTimer code and got that wrong.
Line 142 will create a new instance of the SimplestTimer class, but that has no relevance to this application. You have a method called SimplestTimer, but you don't call it.

Forget/delete SImplestTimer now - it was just a teaching aid.
Take the code that starts the timer and adds the button listeners, and put that in your constructor after the call to initComponents.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sounds like you are having layout manger problems, for example, the default LM for a JFrame is a BorderLayout, in which if you just add a component without saying where to add it it goes in the center position, replacing whatever was there before.

This tutorial will teach you how to chose and use a Layout Manager
https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html

Apart from that I can't say anything sensible about code I have never seen!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Its your graphics hardware, not the CPUs. A 2.4 i5 will be perfectly adequate with a decent graphics card. One of my machines has HD3000 graphics. Its fine for ordinary "business" use, but hopeless for real-time 3d games.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Starting at the top...
You create a Timer by giving it a time interval (1000 mSec in this case) and an ActionListener (the same as an ActionListener for a JButton etc). The Timer then calls the ActionListener every 1000 mSec. The code above uses a Java 8 lambda, which maybe you haven't covered yet, so here's the long verersion that you would have used before Java 8...

timer = new Timer(1000, new ActionListener(){ 
     public void actionPerformed(ActionEvent e ){
         updateGUI(e);
     }
 });

so via that the updateGUI method gets called every 1000 mSec. It's void because it doesn't return anything. It just adds one to the timeCounter, converts that to a String and uses it to set the JLabel's text.

Once you have created a Timer you can start and stop it by calling its start() and stop() methods (cunning, eh?). Eg if you have a startTimer JButton you would use

startTimer.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent e ){
        timer.start();
    }
});
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its a mistake to try to learn basic principles from a sample as complicated as that.
Because the weather here is horrible and I have nothing better to de I'll take a moment to show you a very very simple program that updates a JLabel with a one-second counter.

This will only be useful if you take the time to understand every single line, using the API reference documentation for anything unfamiliar. Once you understand it all you will know how to write your own program.

import javax.swing.*;

public class SimplestTimer {

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

    JFrame frame = new JFrame("Timer");
    JLabel timeLabel = new JLabel("Time shown here");
    int timeCounter = 0;

    SimplestTimer() {
        frame.add(timeLabel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        new Timer(1000, this::updateGUI).start();
    }

    void updateGUI(java.awt.event.ActionEvent e) {
        timeLabel.setText("" + (++timeCounter));
    }
}

If you get stuck you can ask questions here, but only after trying yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forget thread and sleep - it doesn't work well in a GUI
You need a Swing Timer that will update your GUI at regular intervals.
Here's a couple of tutorials:
https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
http://www.javacoderanch.com/how-to-use-swing-timer-class.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The only way to paint is by overriding paintComponent etc
You have no direct control over how often or when paintComponent will be called - it may be triggered by window activity, it may coalesce paints if it's busy etc

For smooth movement it's essential that the underlying model updates at regular intervals, regardless of screen updates.

So you update the model in its own thread at regular intervals at least as fast as your desired fastest frame rate.
After each model update you request a screen update, and Swing will do its best. If it can't keep up it will coalesce consecutive points, but the movement will still look steady. Given two or more CPUs you will be running at fastest rate your hardware can achieve.

The code to manage that is trivial, just a few lines. I've posted versions of it here a few times, but I can't access them from here.

J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You definitely should use a timer

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

https://www.daniweb.com/programming/software-development/threads/424529/need-help-regarding-how-to-draw-smoothly-in-java-p

Except use Java.util.timer not Javax.swing.timer so model updates are not on the swing thread

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Doing a getGraphics and drawing to that will never work. You have to cooperate with Swing's double buffering. The ONLY way to draw in Swing is to override paintComponent.
I would post you an example, but I'm away from my usual machine right now. There's an article on Oracle's site about painting in AWT and swing that explains the right way to do it.
http://www.oracle.com/technetwork/java/painting-140037.html#swing

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I googled for de.vorb.leptonica+jar+download and it was the first hit

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's a bit more to the Ariane story.
The software was originally written for the Ariane 4 rocket, where it worked perfectly. Then they built the 5 which is bigger heavier faster, reused the 4 software, and that's when the overflow happened.
There's another good moral here: requirements and specs are never final, and once working software lives on far longer than anyone originally intended. "It works now" isn't good enough.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess you know the story of the ArIane 5 rocket? Cost a gazillion Euros and blew up soon after launch.
The guidance software had an assignment of a 64 bit number to a 16 bit target. Of course the compiler objected, but management reviewed the problem and decided the value would always be within a 16 bit range, so don't bother to fix it. Wrong.
I use that story a lot.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you google "Java OCR " (optical character recognition) you will find a good number of libraries, some of which are open source.
On the other hand, if you are trying to automate CAPTCHA recognition then Daniweb TOS prohibits such discussions here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK! I never really doubted that Java's indexOf method works correctly, so it had to be something else. Your latest code looks good to me.
Don't forget to mark this "solved" when you have finished testing.

JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It does work - there's another bug in your code somewhere.
Just to prove it here's an example that works (I'm not suggesting you copy this, your teacher will realise it's not your code, but proves the idea is OK)

    int firstDNAMatch(String shortDNA, String longDNA) {

        // some simple input validation...
        assert shortDNA.matches("[ATCG]*");
        assert longDNA.matches("[ATCG]*");

        // create the string we will be searching for by swapping T<>A, C<>G
        String matchingShortDNA = shortDNA.toLowerCase().
                replaceAll("t", "A").
                replaceAll("a", "T").
                replaceAll("c", "G").
                replaceAll("g", "C");

        // now it's a simple search...
        return longDNA.indexOf(matchingShortDNA);
    }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have done that translation then all you need to do the search is is
longDNA.indexOf(shortDNATranslated)

https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-java.lang.String-

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I find that code very hard to read, but looking at the matching around line 78 it looks like you are testing if the chars from the two DNA strings are the same, not T matches A etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simple example of formatting a float into a String:
String s = String.format("Pi = %7.4f", Math.PI);
formats the value of PI as 7 digits wide, 4 dec places (the % character signals a format specification), so s contains
Pi = 3.1416

Slightly more interesting example:
String s = String.format("Pi = %7.4f, e= %5.2f", Math.PI, Math.E);
gives
Pi = 3.1416, e= 2.72

You can do the same thing when printing by using printf instead of println
There's a complete description of all the formatting codes at
https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
(plus lots of examples and tutorials on the web)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The right time to round is when you are converting the floating point value to String - line 1 in the code you posted.Rather than using concatenation to force a default conversion, use String's format method to format (myDiameter - (myPitch * 0.649519)) to the right number of decimals

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It just avoids the problem of you having to get the right OS-dependent separator.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Right idea, wrong syntax for a method call. It goes like this:

String myDir = ..... (maybe from system properties)
String fileName = .....
File f = new File(myDir, fileName); // creates a File object with that file in that dir

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the program uses the value (and if it doesn't then why have it?) then the program must contain some encoded version of the value and some code to decode it for use. In other words there must be enough information in the program to retrieve the value. So a cracker with enough patience can always retrieve that information and thus get the original value.
The only way round that would be to ensure the program does not itself contain enough information - eg by interacting with a server that contains information inaccessible to the cracker.

Aeonix commented: Clear, direct and perfect answer. The only next thing I could wish for, was 5 billion bucks. +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't have linux here so I can't say.
But why not use the File constructor that goes
public File(String parent, String child)
Creates a new File instance from a parent pathname string and a child pathname string.... the parent pathname string is taken to denote a directory, and the child pathname string is taken to denote either a directory or a file.

that way you don't need to input a separator at all.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I didn't know that calls from outside methods were not allowed

You know that you can't put any kind of executeable code just lying around in a class. It has to be in a method or an initialiser. Method calls are no different than any other executable code in that respect.

Your separator is null because you never initialise it. Where you think you are initialising it you are actually initialising a local variable. Not the first time you have made this mistake (and probably not the last either :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You tried to call it from inside the inner class but outside any method!
Because its outside any method the compiler is confused and thinks you are trying to define a new method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An inner class has access to all the variables and methods in its containing class (that's why you make them inner classes!) so there's no problem calling the outer class's methods from the inner class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

.java is a source code file so you can't execute it. Yo have to compile it first
Compiled java programs that can be executed come in .class files or .jar files

If you have a .class file, eg myprog.class, then it's executed by javaw myprog
If you have a.jar file, eg myprog.jar, then it's javaw -jar myprog.jar
Full details are here: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

I don't speak php, so I can't go any further, but if you know how to invoke an executable; (javaw.exe) with a parameter (myprog) then that's what you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That would work ok, and help tp ensure that each batch of new output has been written to the files system.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You call closeFile in your main method (line 130) regardless of whether it has been used (initialised) or not.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

because the variable (stringInput) I apply the method to is of type String and not Scanner?

Yes

If you want to use Scanner methods on data that you have in a String, you can create a Scanner object that uses the String as its input. Hint: It's one of the standard constructors for Scanner.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, especially when writing new code always start off with printStackTrace() everywhere. You never know when the next bug is going reveal itself, and when it does you want all the info you can possibly get.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks good now!
But please put a printStackTrace() in your exception handlers (especially lines 53 2nd 64) otherwize all you will know is "general error" whereas the stacktrace will tell you exactly what caused the error so you will know how to fix it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes to both.

You can use the system property as you suggest. That's probably what newLine() does anyway. Personally I think newLine() is that little bit clearer when you read the code, and for me that's an important consideration.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Actually my previus description was a bit garbled, and I've now fixed it. Please re-read it. Thanks

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

nextLine reads lines from a file and returns them to you without their terminating \n chars.
That's got nothing to do with writing files.

The new line character or sequence depends on the machine where it's running. In reality that will be either or both of decimal 10 (line feed) and 13 (carriage return). (This dates back to typewriters and teletype printers where feeding the pape up one line and returning the print head to the start position were two quite separate things.) Windows preferrs CR and LF. Java's \n is a LF.

Different OSs and different editors vary in how tolerant they are of any variations from their preferred norm. In this case notepad++ is giving handling this file properly and notepad is doing its own thing. So your code is OK; just use notepad++ to check your file contents.

The best solution is to wrap your FileWriter in a BufferedWriter (you should do this anyway for efficiecy reasons) then use BufferedWriter's newLine() method to write a system-dependent new line char opr sequnce as apropriate.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not a mind reader. You have a problem in a version of your code that you hven't shown. And anyway, I'm not going to read any more of your code unless you indent it correctly - it's just too hard to follow all those nested whiles & ifs (eg lines 140-142... what's that all about?). It will be easier ro read if you indent according to the Sun/Oracle preferred system eg

if (blah) {
   stuff
} else {
   other stuff
}

rather than having all those lines with just a single curly open bracket on them that make for uneccessary vertical scrolling to see all the code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Around lines 144-146 you seem confused about what variables you are using.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like you are writing the new line chars correctly - maybe the poroblem is with whatever you are using to check the contents of the file?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like you create a new FileWriter for each line in the input (loop starting line 24), all competing to write to the same output and corrupting each other. That's a msitake, just create one filewriter at the beginning and use that for all the lines.

The file is going to the current working directory, which happens to be where the app is because that's how you're running it. Depending on how the app is run that will often NOT be the case, and you may get unpredictable crashes. See my previous post, and use the user's home or working dir. It's just one more line of code.