Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you don't have an API that you can use for the target program then about the only thing you could try would be the Robot class. There's a tutorial that demonstrates how it can be used to interact with other programs here: http://www.developer.com/java/other/article.php/2212401

It would be a clunky solution at best, but if you have no API nor command line access, it's about the only thing left. Unless, of course, you can hack the underlying data store and write in the field values directly ;)

PoovenM commented: You're just bloody brilliant mate! Thanks for the reply :) +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It may simply be a matter of incorrectly specifying the pixel values, because when I use this code (from the example in the MemoryImageSource API)

for (int y = 0; y < height; y++) {
            int red = (y * 255) / (height - 1);
            for (int x = 0; x < width; x++) {
                int blue = (x * 255) / (width - 1);
                pixarray[i++] = (255 << 24) | (red << 16) | blue;
            }
        }

in place of your loop to fill 'pixarray' from the pixels param, it works just fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The compile error is due to the fact that BlockingQueue does not implement the List interface anywhere in it's hierarchy, which is what the SwingWorker requires in the process(List) method. You really only need to specify the type for the List parameter when you override it, because it is called internally by the mechanics of the publish() method.

Since you are publishing String objects, declare your process() method like this

@Override
protected void process(List<String> lines) {
    for (String i : lines) {
        Form.TraceBox.append(i+"\r\n");
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, didn't Pandora open that box? Some crazy scientists are about to do that and suck us all into this black hole instantaneously in the Big Whoosh (opposite of Big Bang)

You bet. All those "crazy scientists" just want to kill themselves and their families.

Thanks for highlighting your ignorance in bold red letters for all to see.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Those requirements are certainly not trivial. I'd recommend assessing currently available commercial solutions for this:
http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=home+inspection+reporting+software

If those don't meet your needs, then you could start getting some bids on a custom solution. Generally, if an existing product would meet 80% of your needs, you're better off taking a hard look at what that remaining 20% is worth to you and how flexible you can be on it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I can't really speak to the rest of your code. I was just looking at the timer operation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sorry, I suppose I could have explained that a bit. If you press a key the timer starts. If you keep pressing keys before the 2 second timer expires, nothing changes. If you don't press a key in 2 seconds, the label changes to "Time up!".

It's just a stripped down version of your own code from the first example you posted. You were calling cancel() on the Time, instead of the object that extended TimerTask.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

these are the errors i have gotten now sir ( after removing exceptions)

java.io.FileNotFoundException: t.txt (The system cannot find the file specified)

Most likely the file you are trying to read is not located in the same directory as your java class. You can either move it there, or supply the full path name to the file in your program.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I really would like to get this right and understand it as all my projects from here on are going to require me to manipulate data from a single file as input for the methods which will all be called from the the main(). This is what the instructor requires.

Whether or not its best practice is a totally different topic.

Actually, "best practice" doesn't really come into it. It's the intended usage of the language. Making everything static and manipulating it in main() could only be described as "unintended practice" or more appropriately "worst practice". Java is entirely an object-oriented language. To teach it otherwise is a disservice to students.

Your code can easily be converted to an appropriate object-oriented version with a few simple changes. The only static method that is needed here is main(). Any others can be normal public methods of the class. All variables needed internally by the class should be declared private. The static main() method simply serves as entry point or driver to "set up" and use the object that you create, like so

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

/** Not really a good descriptive class name, but I don't know 
 *  what you're planning to do with it. You can pick a better one.
 */
public class FileProcessor {

    private Scanner filescan = null;

    /** Create an instance of FileProcessor for the given File. */
    public FileProcessor(File targetFile) throws FileNotFoundException {
        filescan = new Scanner(targetFile);
    }

    /** …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, since you didn't state the runtime errors, I'm going to guess they stem from not being able to locate the file?

(Just an aside, never throw exceptions from main(). What is going to catch them?)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Move the scanner initialization into main() then, since you don't actually construct an instance of "program1".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In the first version, I think the only problem is that you are calling cancel on the timer, instead of the timekeeping task. I ran this simplified example here and it works just fine.

import java.util.Timer;
import java.util.TimerTask;

public class FrameThread extends javax.swing.JFrame {

    Timer timer;
    TimeKeeping timeKeeperTask = null;
    boolean timerRunning = false;

    public FrameThread() {
        initComponents();
        timer = new Timer();
    }

    private class TimeKeeping extends TimerTask {
        public void run() {
            timerRunning = false;
            jLabel1.setText("time up!");
            System.out.println("Timer expired");
        }
    }

private void formKeyPressed(java.awt.event.KeyEvent evt) {
    //Rest of the function that is not relevant to problem
//        repaint();

    if (timerRunning) // boolean check, if true execute
    {
        System.out.println("Cancel timer");
        timeKeeperTask.cancel();
    }
    System.out.println("Start new timer");
    jLabel1.setText("running");
    timeKeeperTask = new TimeKeeping();
    timer.schedule(timeKeeperTask, 2000);
    timerRunning = true;
    System.out.println("New timer started");

}

    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });
        getContentPane().setLayout(new java.awt.FlowLayout());

        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1);

        pack();
    }

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

    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration

}
peter_budo commented: Thank you for another great example of code :) +10
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yeah, the leak development really sucks. :(

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Want to know what? This isn't even a question. Why don't you read up on the two of them on the Eclipse site?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

AudioInputStream.read(byte[]) will read into a byte array buffer.
This example may be of use: http://www.exampledepot.com/egs/javax.sound.sampled/StreamAudio.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So declare "filescan" static then.

static Scanner filescan = null;

It's worth noting that making everything static and calling it from main() is not how Java is meant to be used, though intro courses often start with such programs. Java is an object-oriented language and should be taught as such. Making it all static relegates it to a procedural program and defeats the whole purpose.

stephen84s commented: Yep gives me heart burns when I see Java used like this +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Bookmark the Swing tutorials.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

tried hard to align but give up

That would be because you failed to read this prominent Announcement: Please use BB Code and Inlinecode tags at the top of the forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps he is just looking for a way to control his thermostat from his PC...
:P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you create an instance of SimpleDateFormat using a pattern that corresponds to your intput, you can use the parse(String) method to convert the string input to a Date object, which you can then use to get the day of the week. Calendar is what you should really use for this, but I'm not sure what the specifics of your assignment are (and the whole date/calendar thing is pretty much a mess anyway).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I found this article interesting: Bailout Boondoggle.

I would agree with nearly every point made there.

This part in particular is what really galls me about the current Republican party:

There does exist, however, “Big Government Republicanism.” Big Government Republicanism, hand in hand with Neo-conservatism, has brought us welfare for pharmaceutical companies, McCain-Feingold, the Patriot Act and the notion that we can impose our will on all the nations of the world.

Fiscal conservatism and personal responsibility aren't even on the radar of the Republicans these days and have been replaced by cronyism, social conservatism, and right-wing authoritarianism.

Dave Sinkula commented: Yup. +17
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And perhaps you're smart enough to figure out why no one is going to help you with this, given the progress of this thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
public class Program1 {

    Scanner scanner = null;
    
    public Program1(){
        try {
            scanner = new Scanner(new File("t.txt"));
        } catch (FileNotFoundException fe){
            fe.printStackTrace();
        }
    }

    public static void main(String[] args) {
        
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Make it a class level variable - not a public static member.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you need to look up pseudocode then, because you have nothing like it.

You need to outline the steps in a logical format that describes the process the program needs to complete.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Only if you start with an effort to outline your thoughts on how to implement the program or some code that you have written to start with.

Write it in pseudocode if you don't understand how to do it in Java and ask specific questions about the portions that you are unsure of.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

this my hel;p u

Sure, maybe... if he was using PHP, but since this is the Java forum and his code is Java, your suggestion seems to fall a little bit short of helpful.

And this isn't a chat room, so you can leave the IM-speak at the door.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"stinkin java won't read the "sdf"" because you haven't "stinkin" declared it properly in any of the code you posted. You would need to do this:

SimpleDateFormat  sdf = new SimpleDateFormat ("EEEE MMMM DD, YYYY");

and even then, masijade's right - it isn't going to work your class just because you called it "date".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

++ what Vernon said.

Also, you really need to learn to indent code blocks. Being able to discern the logical structure of your program at a glance is well worth the time it takes to indent properly. Coding conventions weren't developed just to make things "prettier".
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The errors are quite clear. You are trying to use "input" but you have not defined it, and you are trying to redeclare "String inputValue" when you have already declared it a few lines above.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Nah, I think he meant MP3-player :)

I think his output would be rather garbled.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to learn your employer's business domain and the technical details of that domain and your companies offerings, which your employer should provide guidance on, unless you did misrepresent yourself as AD suggested.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't - it's null. It has no value and the only context your method has for a relationship to a class is the parameter type, which you have denoted as Object.

You don't mention the larger context of this usage, but it raises suspicion of a design problem that would be better addressed with an interface for the parameter or behavioral design pattern.

Edit: Posted at the same time as masijade. Answer pertains to the original question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Sun Swing tutorials also cover this: http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

Keep that tutorial trail bookmarked for future reference on using Swing components.

stephen84s commented: Yep the right place to go to. +3
Alex Edwards commented: Great recommendation =) +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

String.split(java.lang.String) is also very useful for such things.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Keep in mind that updates to Swing components should be done on the AWT event queue.
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Alex Edwards commented: Yes. Sorry for the late rep-bump, but information like this is imperative! =) +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

public void update(....){
//complete here
.....

Brilliant. Absolutely brilliant.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What code have you tried? What problems are occurring with it? Have you studied the Sun tutorials and the APIs related to this code?

"Please solve my porblem friends"(sic) doesn't show any effort on your part.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are some tricky nuances to clone() and you are probably best served by using a copy constructor in it's stead.
http://www.javapractices.com/topic/TopicAction.do?Id=71

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are no macros in Java. You would define a class or interface constant for that purpose.

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

I suppose we're to just reach down the "tubes" and put this together for you?
;)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I gave you a link directly to the MySQL doc on it. Did you bother to read it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are trying to store a serialized object then you'd need to use the BLOB type.

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

He means references to them.

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

Use their JDBC driver: http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

Do not use the JdbcOdbc bridge.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Alex Edwards commented: +1 for quoting Sun =) +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He is saying that frame2 will need a reference to frame1. Your add button code will need to call methods on frame1 to set the data that you wish to display.