JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are just using standard Swing components, so there is no need for you to write (or even think about) a paint method. Swing will paint all those components for you.
Why exactly do you want to write a custom ppaint method???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

create an array to display it.

did you mean that?

stultuske commented: dumb typo's when doing too many things simultaneously :) +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 28-35 you put the data into every row of the array, rather than just into the current row

then in 38-43 you overwrite your values again when you should be just printing them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just have one paintComponent() method (for your JPanel) and no paint() methods. That's all.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are forcing a repaint of the whole applet every time, which may be the cause of your flickering.
In any case it's much better to put your animation in a JPanel, and override paintComponent for the JPanel to do your drawing. Add that JPanel to your applet and don't mess with the applet painting at all (at line 62 just call repaint() on yur JPanel).

ps Sorry, the .java was there and I was being stupid.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if (Level_0.getValueAt(row, col) = true)

You have a = (assignment) where you should have == (equals) (plus then see posts above)

if (something == true) //row and col is the location of ckbox in the table Level_0
   {Level_0.setValueAt(row, col).setSelected(false);}
else
   {Level_0.getValueAt(row, col).setSelected(true);}

is a really long and tortuous way to say

Level_0.getValueAt(row, col).setSelected(! something);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I coudb't see any source code in that zip. How are you handling the screenpaints? Are you overriding Swing's default double-buffering in any way?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are quite a few threads here on this topic. Basically Java doesn't do .exe files because they are operating system dependent. An executable jar will run on any system witha JRE installed. There are some products around that will package up a jar with a jre to give a single exceutable file - I'm sure you can find them via Google.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

what's wrong with my formula?

sin. cos etc use angles in radians (Google it), you have supplied an angle in degrees

Pi radians is 180 degrees, so ddanbe' formula should be theta = theta * Math.PI / 180;
(sorry ddanbe)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A JPanel object is initialized to use a FlowLayout, unless you specify differently when creating the JPanel. So in the second case you are adding to a FlowLayout (using a BorderLayout parameter for an unspecified result)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

sin. cos etc use angles in radians, your data (30) looks like degrees.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The constructor you posted won't compile, so maybe post the right version?

 public FullTimeEmp(String inFirstName, String inLastName,double)
 {
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK!
Please mark this "solved" for out knowledge base.
J

ps IIM: Yes, you're right. My mistake. I've never used, or seen used, import static for anything other than constants (public static final), so i jumped to an incorrect conclusion. Thanks for clearing that up. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well, you can if you want. That is valid Java, but it doesn't match the formula you were given. Exponentiation comes before multiplication, so its
B=300000(e^-0.032t)
not
B=(300000
e)^-0.032t

ps You;ll get a more accurate result by using the built in value for e, which you can access as just
Math.E

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

import static imports any static final variables from a class (eg Colors from the Color class).
Youu probably should be using just
import com.healthmarketscience.jackcess.Database.*;
to import the classes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The easiest way to get (e to the power something) is to use Math.exp(something), eg

eToThePowerFour = Math.exp(2*2);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All your methods (except main) are (correctly) instance methods. You need to create an instance of CashDispenser to use those methods. You create an instance with (eg)
CashDispenser cashDispenser = new CashDispenser();
That creates an instance, and sets your cashDispenser variable to refer to it. Now you can call your methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We don'thave the latest code, but at a guess line 76 in withfrawFunds is the first place where you use cashDispenser? If so you presumably haven't given any value to that variable, so it's still null.
Here's a tutorial you may find useful
http://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

non-static method dispenseCash(int) cannot be referenced from a static context

Pretty much what is says.
dispenseCash is an instance method, and must be called using an instance of CashDispenser, but you try to call it just using the class name (as if it was a static method), so the compiler doesn't know which instance to use.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

byte[] is just raw data, so without knowing more about the image format there's no way to do any image processing on it. If you know the format then you can convert the byte[] to an Image, get a resized version as above, and get its raw data back out as a byte[].
What do you know about the format of the image data?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't say what kind of image you have, but ordinary Image objects have a getScaledInstance(...) method that will give you a new version of whatever size you want.

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

TokamakFusion: What is the point of this thread?

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

Sorry, I don't know the answer to that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

so i suppose functionally they are the same ?

No, one's an interface, the other is a class. Definitely not the same. Start with a quick review of this tutorial: http://docs.oracle.com/javase/tutorial/java/concepts/interface.html

The advantage is that the print service needs you to suppy some attributes and by defining that as an interface it leaves you free to implement them however you want (consistent with the interface definition of course). For most applications, where there's no need to do anything special, they provide a "default" implementation of the interface in the form of the HashPrintRequestAttributeSet class that you can use without any further effort.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

PrintRequestAttributeSet is just an interface, HashPrintRequestAttributeSet is a class that implements PrintRequestAttributeSet.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly as we guessed.... you are missing the import for client in Commands.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ yes, but the errors he has posted so far don't include any relating to the inports - if the import was there but the file couldn't be found then you would expect that to be the first error in the list.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If that answers your question then pleasse mark this thread "solved" for our knowledge base.
Thanks
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its hard just seeing fragments like this, but it looks to me like there are missing import statements for client etc in Skillinterfaces.java, Packets.java etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great! Please mark this thread "solved" for our knowledge base.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Beware of confusing your terminology here...
methods can not be "unchecked", only Exceptions can be. If you drill further into the JavaDoc you will see that all three exceptions that nextInt may throw extend RuntimeException and are therefore unchecked. The definition of nextInt() in the API source code does not have a "throws" clause; the three exceptions it can throw are just documented in the JavaDoc to be helpful.
There seems to be nothing preventing you from declaring a method as throws <some unchecked exception>, but it's not clear to me what that achieves for you.

Also: "throw" is the statement that you use to send an Exception; you are referring to the "throws" clause in a method signature that lets you know that method may throw a checked exception which you will have to deal with somehow.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Sorry - don't understand
  2. The two tables have different numbers of columns, so they can't share one column model
  3. Yes, they should be in one scrollpane, but that won't synchronise the column widths like the OP requires
  4. The setMinimumSize on line 50 is just a quickie to make the window bigger so you can re-size the columns more easily. This is just a quick proof-of-concept runnable demo, not production code.
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

OK, excellent! Please marked this "solved" for our knowledge base.
Thanks
J

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

So you set the width of table2 col 0 to the sum of the widths of table 1 cols 0 & 1. Then subsequent columns (i) in table 2 are set to the width of table 1 col (i-1).
Without your code, it's hard to comment on its details.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's just a java file I have that has a few imports, a main method that calls a constructor... so I can drop in a piece of code like yours and execute it with minimum effort.

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

OK, Ignore previous post. There's nothing wrong with your code AFAICT.
I ran your code with zero changes (copy/paste into a shell class is all), got a 294k zip file which when unzipped gave me a Excel file which when opened in Excel displayed a load of data I didn't understand, but in an obviously reasonable format.
Over to you...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you checked the file contents - eg is it an HTTP header or some such?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I need to make it pause for the input first.

That's probably the wrong way to think about it. If that's really what you want then some kind of modal window is needed, but I suggest you re-think the logic flow in terms of a user-event-driven GUI. Why did you get in the position where you were trying to use info before the user has entered it? Try thinking through and documenting what should happen from the user's viewpoint.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Never mind "suggests". Print t.Teams immediately after that line to confirm whether or not it is null. ***If ***it is null, then look in the getTeam method to see why it returned null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the assignment is illegal the compiler will tell you.
The exception tells you exactly which line the NPE happens on, so look at that line, if necessary print the variables and method returned values from that line to see which is null.

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

What's the definition of initTeams - is it static, or a local variable in a static method?