Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Switch statement validation JTextArea / JFilechooser?

I was wondering if anybody could help me validating a text file from a JFileChooser I want it to select only certain 'cases' i've attempted to do this with the switch statement but i'm lost, then placing the validated text into the Jtextarea at the bottom, then from there draw it in on the canvas (dark grey area). I've tried repeatedly and I'm truly lost if anybody could adjust my code accordingly or point me in the right direct. Will pay if required just pm me your skype name (y)

InstructionsPanel.java
pastebin.com/ufz6cdQ3

DrawingAssignment.java
pastebin.com/r84vFnVT

GraphicsPanel.java
pastebin.com/SrddUBHp

Load text file.txt
Code
LINE 100 100 // Corresponds to draw LINE at X and Y
MOVE 30 40 // Corresponds to move pen to X and Y
COLOR 255 100 10 // corrosponds to setting the color of pen to correct RGB colors
Do you want to validate the contents of the text file or the file name?
Hey I have a signature.
(Jan 4, 2017 08:45 AM)Sogomn Wrote:  Do you want to validate the contents of the text file or the file name?

The contents of the file.
Well then just read the file, iterate through all its lines and check if they are valid:

Code
final Path file = fileChooserFile.toPath();
final List<String> lines = Files.readAllLines(file);

for (final String line : lines) {

    /*
    * You might want to use only the first word of the line or whatever
    * Just use calls like "line.substring(0, end)" then, for example
    */

    final boolean valid = validate(line);

    if (valid) {
        //Do your magic
    }
}

The "validate" method could look like this:

Code
boolean validate(final String line) {
    switch (line) {
    case "Bla":
    case "Whatever":
    case "Valid stuff":
        return true;
    default:
        return false;
    }
}

A better way would be to have a list which contains all valid items. Then you just need to check if the string contains the item.
Hey I have a signature.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by joshuagress12345Mar 12, 2024 08:15 AM 4 323 Mar 12, 2024 08:15 AM
Last Post: Hackers
[Java] by OBAMASELFApr 23, 2019 12:42 AM 4 245 Apr 23, 2019 12:42 AM
Last Post: Joseph Stalin
[Java] by friiz1337Apr 3, 2018 09:46 AM 7 285 Apr 3, 2018 09:46 AM
Last Post: Conejo