JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i want to learn C# ...

Then maybe Java isn't the way to do that. The languages are almost identical, but the vast libraries that you use with them are totally different (.net vs Java API). Learn one language and you have 90%+ of the other (either way), but about 100% of the time spent on one library will be wasted when it comes to the other. Given that learning a decent subest of either library is hugely bigger than learning either language, I would advise that the best way to learn c#/.net is just is just to do that, and don't get distracted into Java.
On the other hand I think there is much merit in pbj.codez's suggestion that you start with something easier to get the basics of programming - Python, or maybe even JavaScript.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I believe my student discovered a mistake in Java
...
num = num++; should (as it does in C++) assign num to num then increment num.
...
invokes undefined behaviour.... Ah HA! That sounds like the correct answer. ... depending on the compiler!

From the above quotes I suspect you do not have the correct answer in your mind. The behaviour is not a mistake, c++ is irrelevant, and the behaviour is not undefined or compiler-dependent.

The Java Language Specification makes it perfectly clear what the behaviour should be, and what you observe is exactly what the JLS says it should do. No mistake, no ambiguity, no possibility of variation for any valid java compiler. Please refer to the JLS sections that I posted earlier.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just in case this is a real question, here's a real answer:
No, it doesn't fail. It does exactly what the Java Language Spec says it should.

Java Language Spec 15.14 (postfix Operators)

... the value 1 is added to the value of the variable and the sum is stored back into the variable ... The value of the postfix increment expression is the value of the variable before the new value is stored.

and 15.26 (Assignment operators)

the right-hand operand is evaluated ... the value of the right-hand operand is converted to the type of the lefthand variable ... the result of the conversion is stored into the variable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that's right.
I did a similar thing for use as a teaching aid in tutorials, and it looks a lot like yours - a JPanel with paintComponent overidden to draw all the game objects, and a hierarchy of game objects that do not need to be JComponents or anything else. Perhaps the only interesting difference is that I separated the behaviour of the game objects from their display - that's because I was modelling things like gravity, air resistance, and lossy bouncing in the objects themselves, and if I put all that with stuff like drawing animated GIFs all in one class it got far too big.

The one area I found really hard was handling collisions between non-rectangular objects, especially when there are lots of objects. It took ages to get an implementation that could show dozens or even hundreds of balls all bouncing off each other.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Alternatively... why would you accept all the overhead and potential conflict of using a very large and complex class like JPanel when you don't use any of its methods?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lots of if (...) { without any matching } that I can see. Indent the code according to the actual brackets and see if that makes sense

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

so i guess the instanceOf check was a best-practices example for code in general

Yes - because if you get it wrong you get a horrible cast execption at run time, very messy.

Sorry, I don't have any useful info/experience comparing DefaultEditorKit vs UndoManager.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

They both refer to the same object (address on the heap), but for compile-time checking the compiler knows that styledDoc must always refer to some kind of StyledDocument and doc must always refer to some kind of AbstractDocument. The cast is telling the compiler that you expect these types to be compatible in this particular piece of code.
Note that StyledDocument is an interface, with two standard classes that implement it, viz: DefaultStyledDocument and HTMLDocument. As it happens, both of those classes extend (directly or indirectly) AbstractDocument, so the cast will be OK, but in general, you cannot be sure that a class that implements StyledDocument will extend AbstractDocument, so the two types are quite diferent.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In that case,, yes. But to make things clearer people often use the same names for the variables and the parameters

class X {
   String name;
   public X(String name) {
      this.name = name;  // now I need "this" to refer to the variable not the parameter
   }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

javascript is a simple language mostly used for adding functionality to web pages. It's pretty easy and quick to learn.
Java is a full-scale programming language with a vast API library of thousands of functions that you can use for a huge range of systems. It's very widely used to program complex commercial application and servers. It's a serious investment of time and effort to learn to use it well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Part 3 (last) the client's main run mthod

 public void run() {

      try {
         in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
         width = in.readInt();
         height = in.readInt();
         System.out.println("Screen Watcher connected to Server. Screen size " + width
               + "x" + height);
         out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
      } catch (Exception e) {
         e.printStackTrace();
      }

      // create in-memory Image, and get access to its raw pixel data array
      image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      DataBufferInt db = (DataBufferInt) image.getRaster().getDataBuffer();
      int[] pixels = db.getData();

      JFrame frame = new JFrame("Remote Screen");
      frame.setLocation(20, 20);
      JLabel label = new ImageLabel();
      label.setIcon(new ImageIcon(image));
      frame.add(new JScrollPane(label));
      frame.pack();
      setWindowSize(frame);
      frame.setVisible(true);

      // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            shutdown();
         }
      });

      try {
         while (!shuttingDown) {
            // read updates as long as they keep coming...
            int i = 0; // index into pixel array
            while (i < pixels.length) {
               int next = in.readInt();
               if (next == -1) { // EOF from server
                  System.out.println("EOF received from server");
                  shuttingDown = true;
                  break;
               }
               if ((next & 0xFF000000) == 0) { // "Unchanged" record
                  // skip specified number of unchanged pixels
                  i += next;
               } else { // "Changed" record
                  int value = next | 0xFF000000; // RGB, with Alpha byte 255
                  int count = next >>> 24; // number of repeated values
                  for (int k = 0; k < count; k++) {
                     pixels[i++] = value;
                  }
               }
            }
            label.repaint(); 
         }
      } catch (Exception e) {
         if (shuttingDown) {
            // ignore this - applications is terminating and socket was closed. …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Part 2
These two methods are the important part of the server
First - get screen images

int sendScreen() throws IOException {
      BufferedImage image = robot.createScreenCapture(new Rectangle(width, height));
      Raster ras =  image.getData();
      DataBufferInt db = (DataBufferInt) ras.getDataBuffer();
      int[] data = db.getData();

      int bytesSent = sendIncrementalRLE(data, prevData, out);
      if (bytesSent < 0) return -1;
      // error
      prevData = data;
      out.flush();
      return bytesSent;
   }

and, at last the encoding/compression

 int sendIncrementalRLE(int[] data, int[] prevData, DataOutputStream out) {

      // Test for unchanged pixels, and just send how many they are, otherwize
      // find repeated int values in array - replace with 1 value + repeat count
      // 1st byte of ints are Alpha - not used here, so that's where
      // the count is stored. Returns no of bytes sent, -1 for error.
      //
      // Output stream format is sequence of 1 integer records describing the
      // data array in natural order (element 0 ... data.length-1)
      //
      // EOF record - int value -1 (FFFFFFFF)
      //
      // Unchanged record (sequence of >=1 unchanged pixels):
      // bits 0-7 are all 0,
      // bits 8-31 are number of consecutive unchanged pixels.
      //
      // Changed record (sequence of >=1 identical changed pixels):
      // bits 0-7 are number of consecutive pixels the same 1-254,
      //          (255 is not available because of clash with EOF)
      // bits 8-31 are the 3 byte RGB values for these pixels.
      //
      // Skipping unchanged pixels is based on a transparent pixel idea
      // from DaniWeb …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK part 1
This is the method that gets things started... it assumes you already have a socket connection betrween the client and server.

  ScreenServer(Socket clientSocket, int targetRefreshInterval) {
      // targetRefreshInterval is the desired interval (in mSecs) between
      // starting refreshes. (0 means continuous updates.)
      // Actual rate is not guaranteed.
      // Eg targetRefreshInterval = 2000 means try to refresh every 2 seconds

      try {

         robot = new Robot();
         robot.setAutoWaitForIdle(true);
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         width = screenSize.width;
         height = screenSize.height;

         System.out.println("Remote screenviewer connected, refresh interval "
               + targetRefreshInterval + "mSec");

         out = new DataOutputStream(new BufferedOutputStream(clientSocket
               .getOutputStream()));
         out.writeInt(width);
         out.writeInt(height);

         this.targetRefreshInterval = targetRefreshInterval;
         setPriority(Thread.MIN_PRIORITY);
         start(); // this class extends Thread
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

and here's the run method that loops managing the screen cature and sending

  @Override
   public void run() {
      int bytesSent;
      try {
         while (keepRunning) {
            long startTime = new Date().getTime();

            bytesSent = sendScreen();
            if (bytesSent < 0) break; // error

            long endTime = new Date().getTime();
            // System.out.println("Updated " + (bytesSent + 1023) / 1024
            // + "kB, in " + (endTime - startTime) + " mSec");

            long timeToSleep = targetRefreshInterval - (endTime - startTime);
            if (timeToSleep > 0) Thread.sleep(timeToSleep);
         }
         out.writeInt(-1); // EOF code sent to client
         out.close();
      } catch (IOException e) {
         System.out.println("Socket unavailable");
         // e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
      System.out.println("Remote screenviewer disconnected");
   }

... to be continued...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I see you creating a new output stream each time, but not closing it - maybe they are not being garbage collected?

You may also find this thread interesting - a few of us were trying to optimise compressing a stream of real-time screen images to send over a socket connection, but with lossless compression (no JPEG artifacts etc). Eventually we got pretty good results by only sending changed pixels each time, and using a simple RLE encode for the pixels we did send.
I stll have the final version in daily use here, and will be happy to share if you're interested.

bibiki commented: nice idea 2 send changed pixls +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All those "cannot be resolved" messages are telling you the compiler has encountered a name that has no definition, eg client, Item, ItemHandler ...
Some probable causes include:

  • Mis-typed name (eg capitalisation)
  • Trying to use name outside the scope in which it's defined (eg using a method's local variables outside the method)
  • Trying to access private members from outside the class
  • A syntax error that confuses the compiler about the context where this name is being used.
  • Incorrect package structure
  • Missing package or import statement(s)
  • Missing jar / jar not in class path
  • (etc etc etc)

You can click on each message to see the exact line of source code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The bits where the mistake is!

But seriously - here's a runnable example that does what you said... read and learn...

import java.awt.*;
import static java.awt.GridBagConstraints.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class SynchTables {

   // Shows a second JTable keeping its col widths synched to the first
   public static void main(String... args) {
      new SynchTables();
   }

   JTable table1, table2;

   SynchTables() {
      table1 = createDemoTable1();
      table2 = createDemoTable2();
      synchColumns();
      createColumnListener();
      createDemoWindow_totallyBoring_();
   }

   JTable createDemoTable1() {
      String[] headings = {"A", "B", "C", "D"};
      String[][] data = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}};
      JTable temp = new JTable(data, headings);
      temp.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
      return temp;
   }

   JTable createDemoTable2() {
      String[] headings = {"E", "F", "G"};
      String[][] data = {{"11", "12", "13"}, {"15", "16", "71"}};
      JTable temp = new JTable(data, headings);
      temp.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // we will manage column widths
      return temp;
   }

   void createDemoWindow_totallyBoring_() {
      // just sets up a JFrame with the tables in it - no need to read this
      JFrame frame = new JFrame("Demo");
      frame.setLayout(new GridBagLayout()); // stack components vertically...
      GridBagConstraints gc = new GridBagConstraints(0, RELATIVE, 1, 1, 0.0, 0.0,
              NORTHWEST, HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
      frame.add(table1.getTableHeader(), gc);
      frame.add(table1, gc);
      frame.add(new JLabel(" "), gc); // easy space
      frame.add(table2, gc);
      frame.setMinimumSize(new Dimension(600, 200));
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }

   void synchColumns() {
      // sets table2 column widths to be same as table1
      DefaultTableColumnModel colModel1 = (DefaultTableColumnModel) table1.getColumnModel();
      DefaultTableColumnModel colModel2 = (DefaultTableColumnModel) table2.getColumnModel();
      colModel2.getColumn(0).setPreferredWidth(
              colModel1.getColumn(0).getWidth() + colModel1.getColumn(1).getWidth());
      for (int cNumber = 2; cNumber < colModel1.getColumnCount(); cNumber++) {
         colModel2.getColumn(cNumber - 1).setPreferredWidth( …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

thanks ;)
Just a random guess - but maybe it's your AutoResizeMode on the second table???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It' a bug on line 174 of your code - you have a shadowed variable name...

... but seriously - how do you expect anyone to help debug code that can't see?

Anyway, here's the code of my small runnable working demo - maybe you can see what's different?

import java.awt.*;
import static java.awt.GridBagConstraints.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class SynchTables {

   // Shows a second JTable keeping its col widths synched to the first
   public static void main(String... args) {
      new SynchTables();
   }

   JTable table1, table2;

   SynchTables() {
      table1 = createDemoTable1();
      table2 = createDemoTable2();
      createColumnListener();
      createDemoWindow_totallyBoring_();
   }

   JTable createDemoTable1() {
      String[] headings = {"A", "B", "C", "D"};
      String[][] data = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}};
      JTable temp = new JTable(data, headings);
      temp.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
      return temp;
   }

   JTable createDemoTable2() {
      String[] headings = {"E", "F", "G", "H"};
      String[][] data = {{"11", "12", "13", "14"}, {"15", "16", "71", "18"}};
      JTable temp = new JTable(data, headings);
      temp.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // we will manage column widths
      return temp;
   }

   void createDemoWindow_totallyBoring_() {
      // just sets up a JFrame with the tables in it - no need to read this
      JFrame frame = new JFrame("Demo");
      frame.setLayout(new GridBagLayout()); // stack components vertically...
      GridBagConstraints gc = new GridBagConstraints(0, RELATIVE, 1, 1, 0.0, 0.0,
              NORTHWEST, HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
      frame.add(table1.getTableHeader(), gc);
      frame.add(table1, gc);
      frame.add(new JLabel(" "), gc); // easy space
      frame.add(table2, gc);
      frame.setMinimumSize(new Dimension(600, 200));
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }

   void createColumnListener() {
      DefaultTableColumnModel colModel1 = (DefaultTableColumnModel) table1.getColumnModel();
      colModel1.addColumnModelListener(new TableColumnModelListener() …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just took a moment to read the Terms and Conditions for the site linked above, and as far as I can see, if you have opened an account with them and are not in a location where betting is illegal, then you are allowed access and use the info they provide for your own use and without charges.
Clearly it's not quite what they intended - they assume you will be placing bets through them, but I can't find any such restriction in their contract. So I'm with pbj on this one, sorry duckman.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello Anil
I assume that you are the Anil who wrote the code that link refers to? Please remember that this is not a forum for self-promotion. The DaniWeb rules that you agreed to include "Do ensure that all posts contain relevant content and substance and are not simply vehicles for external links".
Also - thius thread is two years old - any answer would be too late anyway

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, initTeams (despite the initial lower-case letter) is a class, getTeam() is an instance method, so initTeams.getTeam();is an attempt to call an instance method using a class rather than an instance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't understand this code

String [] names = new String[theTeams.length];
for(int i=0; i<names.length; i++){
    names[i] = theTeams[i].getName();
}

You create that variable, but then let it go out of scope without using it at all, and so the array you created will be garbage collected.

 teamBox = new DefaultComboBoxModel();
jComboBox1.setModel(teamBox);

that will give you an empty combo box - you haven't put any data in the model.

If Team has a sensible toString method, then why not just
jComboBox1.setModel(new DefaultComboBoxModel(theTeams));
or maybe
jComboBox1.setModel(new DefaultComboBoxModel(names));
?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Learning the language itself from c++ ... you'll have 95% of it with a few days
Learning the API - a lifetime

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Probably refers to the different ways that numbers are typed, thousands separator, decimal point etc eg US 12,34.56 in France would be 12.345,56, and I think some countries leave a blank as the thousands separator

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Typically you would have main create the model then create the GUI, passing a ref to the model into the GUI constructor, so the GUI can use the model's accessor methods.

Model m - new Model(...) // model knows nothing about the GUI
GUI g = new GUI(m, ...)  // ... but the GUI has to use the model

This minimises the copupling between the GUI and the model, reducing it to the absolute minimum needed to make it work.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That sounds like a perfectly reasonable and interesting Java project, assuming you can get access to the live info through some kind of internet service. Downloading/copying databases is unlikely to give you the kind of real-time data you want. Finding that access must be step one, because if you can't do that (or if it's expensive) then there's no point continuing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess you could create a TableColumnModelListener to monitor changes in your JTable's TableColumnModel and get the updated widths of each TableColumn and use those to update the bottom table? A bit tortuous, but probably not very much code when you finally work it all out.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JRE is everything you need to run Java programs, primarily (1) a JVM and (2) all the class files for the Java API and (3) other bits and pieces that are needed for some of the API classes (DLLs etc)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since you don't actually do anything with those classes it doesn't matter what attributes they have, so maybe this example is a bit too simple?
Do you still have your code for two or more console-based games (tictactoe, hangman, scissors/paper/rock or whatever)?. If so it may be interesting to package those as classes into a simgle games console app where you can chose which games to play and (here's the relevenat bit) implement an interface to start a game, and get player statistics (start(), get name of game, date/time played, win/lost ...) so they all can be started and contribute to the statistics via that interface. Just a thought...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

TitledBorder is because you don't import it. It's javax.swing.border.TitledBorder, so importing javax.swing.* won't import it.

As for java.awt.GridBagConstraints, I don't know why that is giving a problem when you import java.awt.*

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like you are adding exactly the same component (not copies) to every tab - not what you want! See previous post.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are heading in the right direction. What's missing is that you print your random numbers but you don't store then in the array. There's no method you can just call to do it any better.
There's no ready method to get the largest or smallest number in the array, but as vinnitro suggests there are methods to sort the array. After it's sorted the smalles number will be the first in the array and largest number will be the last.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Swing was not part of the first version of Java - which only had java.awt
So originally swing was a java extension.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You shouild know by now that we are going to ask for the exact complete text of all your error messages. "My main problem is with blah" is not in any way helpful.

Begginnerdev commented: Yeppers +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK gyno. it's time to get real...

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You compile the program on your machine and make an executable jar file containing all your compiled classes (and any other resources it needs). You can then execute that jar file on any other machine that has a JRE installed.
See http://docs.oracle.com/javase/tutorial/deployment/jar/index.html

sash_kp commented: Yep got it! And what about running(executing) the server program which is needed to be executed on the server? After compiling shouldn't i execute them? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it's completely possible.
All you need is to run your server program on a computer that your client can connect to. For example that could be your own computer if you configure your router/firewalls to make it accessible from the web, or you could use a commercial hosting service.

sash_kp commented: Well if i host it in a server,then after uploading it to that server how to compile the java program? I mean using the cmd from my laptop? In that way what's the significance of uploading it to the server if finally i am gonna compile it in my laptop's cm +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Use MouseEntered/MouseExited. If you want more detail while its moving inside the window use mouseMoved.
Just try it!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check the API documentation for JTextField, you know, the one that starts "JTextField is a lightweight component that allows the editing of a single line of text."
Try JTextArea, "A JTextArea is a multi-line area that displays plain text"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could write a simple Java program to read a text file, delete any leading integers and write it back out. 15 minutes tops.

sash_kp commented: This would be a peculiar way for doing this. However i found a nice and simple way. In sublime text2 using macros i am able to get this thing done easily. Btw thanks for your support. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's possibly the worst first post I have ever seen!

  1. You give exactly zero idea of what kind of game - tic-tac-toe on the console, WoW-type massive online role play, chess with AI that can beat a grand master, a completely new game...?
  2. What makes you think this is a "we write your code and give it to you" web site?

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone may be able to help you from there.

iamthwee commented: nods +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Instead of a JTable, how about just a load of JLabels in a GridLayout? Keep a JLabel[][] array of refs to them so you can easily set their text from your char array.

Pobunjenik commented: GOOGLE TIME! Thanks man, you're a saint. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You confused char and Char (which doesn't exist), but apart from that I see no real fault in your post. However, anyone can vote on any post, for whatever reason they see fit, and votes without any comment are anonymous by design. I just gave you an up-vote to counter at least one of the down votes, but really... I wouldn't worry too much about it.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You should just get a zero-length String "" for the missing entries.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Some people extend JFrame, others just create JFrame in the code. I see little reason to extend JFrame unless you want to call JFrame's methods (eg setVisible) from another class, but in real life it's never that simple anyway. You don't normally need to extend anything else for your panels, buttons etc unless you have to do something special like override their normal paint methods.

For the ActionListener you can (1) implement that in your main class - that's the smallest code but limits you to one listener for all the buttons, menu items etc in that window, which leads to a huge listener with loads of nested ifs - IMHO a disaster (2) use an anonymous inner class - IMHO the simplest way to add a listner to each button or (3) use a dedicated class - which allows you to create instances with different parameters, eg for responding to the 0-9 buttons in a calculator.

Having said that, the standard beginners addActionListener is usually not a good idea anyway. Swing has Actions that encapsulate a name, an action method, accelerator key,mnemonic, enabled/disabled state etc. You create the Action then just pass that to the button's constructor to set everything up. This is especially valuable when you have a menu item, a toolbar button, and a right-click context menu item that all do the same thing, because they all share the same Action. See
http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are still passing the data to encrypt as a String. That will be corrupted for anything other than ASCII text. Get rid of the |Strings and just work with byte[]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forget the Strings. Encryption/decryption just treats everything as bytes, so the last thing you want is Java doing character "interpretation" of those bytes into/out of some random character set. Just read the input file as an array of bytes, encode that to an array of bytes and write those bytes to the output file along with/just like the key (array of bytes). Ditto for decryption.
The file extension is a special case if you assume it is pure ASCII (under 0x7f) so you can convert that String to array of bytes for writing to file, and vice-versa.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are confusing variables and objects. Variables just contain references (pointers) to an object. You create new FileWriter and BufferedWriter objects each time. Because you only use one at a time it's perfectly OK to re-use the same variables to refer to those objects.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... and throw an OfferException rather than a DivideByZeroException
ahh... the power of copy/paste...
;)

stultuske commented: :) +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have two parts to this task.
The second part is to create and start a new Thread to execute your code, but that requires a run() method (see the Thread API doc for examples etc).
So, the first part is to extract the relevant code from its current place and restructure (refactor) it so it can be called from the Thread's run() method. In its simplest form this could just be to cut that code and paste it into a run method. You'll have to messs about with your existing variables a bit to make them accessible in the run method. With a bit more work you can make it a lot tidier by refactoring the existing code into one or more methods with the appropriate values being passed in as parameters, and have a simple run() that just calls those methods. Best of all, you may even want to have a new class (extending Thread or Runnnable) to perform the function, so you create a new instance passing the values to the constructor, then just execute that in a new Thread. (This will all make more sense when you have read the API doc for Thread).