Scott Pedigo

Greenhorn
+ Follow
since Feb 15, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Scott Pedigo



[This message has been edited by Scott Pedigo (edited February 19, 2001).]
23 years ago
Use the setForeground() (and setBackground()) methods.
There are some standard colors you can use which are static in class Color.
Example:
TextField myText = new TextField();
myText.setForeground(Color.red);
23 years ago
I never actually did anything like this, and I don't have a SDK at work (where I am goofing off answering questions) but here is an attempt:


[This message has been edited by Scott Pedigo (edited February 16, 2001).]
23 years ago
Well, inherited from Component you have method setSize(int, int),
and if you want you can override getPreferredSize and/or getMinimumSize() which are inherited from Container. The latter will prevent the table being resized to something you don't want. None of these will give you ten rows - they'll just set the size of the whole table, and depending on the font size you'll get more or less rows.
However below is probably what you want.
I got this excerpt directly from the Javadocs and pasted it in
here. I suggest putting a bookmark in your browser to http://java.sun.com/j2se/1.3/docs/api/index.html
"The JTable has many facilities that make it possible to customize its rendering and editing but provides
defaults for these features so that simple tables can be set up easily. For example, to set up a table with 10
rows and 10 columns of numbers:

I also found this for JTable:
setPreferredScrollableViewportSize(Dimension size)

[This message has been edited by Scott Pedigo (edited February 16, 2001).]
23 years ago
I can't give a good answer without knowing more about what you are really trying to do. I.e. what is wrong with using invalidate? Under what circumstances do the components need to be redisplayed? Is the parent container being resized for example? I have an applet where I make some components visible/hidden, depending on what button is pressed. I need to invalidate the parent container to get the layout redone after modifying what is visible. Just doing a repaint() alone is not sufficient. But for some other things I have overridden the paint() method. If you do that, you can draw or display whatever you want.
23 years ago
It would be helpful to see an excerpt of the code you are using.
23 years ago
So did you try putting a repaint() after the call which brings up the dialog to see if that would fix the problem?
23 years ago
You can pretty well forget about making your applets trusted.
You have to sign the jar file with a certificate using a signing tool, but there are different signing tools and certificates depending on what platform the applet should run on. So you'd need two different versions of your signed applet, one for MSIE and one for Netscape, with the HTML page which starts the applet first detecting the browser type and then selecting the correct version.
You'd have to download the various signing tools, making sure to get versions which are compatible with the version of the JDK you are using, or the version you are targeting.
You'd have to obtain the appropriate certificates for signing the applet from VeriSign (www.verisign.com) or Thawte (www.thawte.com) which are the only two root certificate authorities (CA) you can expect to be present with all browsers. These cost a lot of money. Thawte is cheaper by far, but it still would cost you US $200 for the first year, $100 for annual renewal.
The real killer is that neither VeriSign nor Thawte will sell you such a certificate unless you are a company or an organization. You have to provide proof, such as a certified copy of the company's registration from the government. Even if you are a company, this is going to take awhile.
I just registered a company so that I could get a certificate for signing my game applet.
My suggestion, if you want to get around the sandbox, is to use the "policyeditor" and give the applet permissions. There is a description on how to do this on my websie, www.rangelaw.com, on the page labelled security. Every user of the applet would have to do this.
The final complication is that in order to use the security policy, you have to use 1.2 (Java 2) or greater, which means that your applet won't run in any browser other than Netscape 6 without a plug-in. Setting up the HTML code to check for, download, and use a plug-in is not trivial. It is so difficult, that Sun supplies and HTML converter which you can download and run your HTML page through. You can find the link for the download on the same page with the plug-in.
23 years ago
The JRE is a product from Sun which has a JVM in it.
A JVM is an implementation of Sun's specifications for something - could be hardware, could be software, could be a browser - which interprets the Java byte code, executing it on a platform.
23 years ago
I think the point that the example is trying to illustrate is that a copy of the *reference* to the integer array is passed into the method on the stack, not a separate copy of the array itself. So when in the method the value of the array element is changed, the original is changed. If a copy of the array contents were passed in on the stack, then only the copy on the stack would be changed, and the original would remain unchanged (which is not the case). The output should therefore show the change.
23 years ago
Every program, or every task in a multi-tasking system, has a chunk of memory called a stack. The size of the stack is typically fixed when the program is loaded or the task is created. Some operating systems might have a feature whereby a stack is allowed to grow, but in most cases this can't happen. When the stack is used up and the program or task tries to use more, then an exception, or corruption of the adjacent memory (and soon thereafter a crash) results. A stack is a place for for storing variables which are only needed by a method (or a function or procedure in other languages) while the method is running. When the method is called, the parameters passed by the caller, if any, are placed on the stack. Any local variables inside the method are allocated space on the stack as well. The stack is a chunk of memory which is filled from the top down. Each program or task has a stack pointer, which points to the end of the used portion of the stack. In order to add something to the stack, the pointer is moved down by the number of bytes corresponding to the size of what is to be put onto the stack. When the method returns, the stack pointer is moved back to where it was before the method was called. Incidentally, the previous position of the stack pointer is stored on the stack itself in a so-called stack frame, some basic information which goes onto the stack right at the start of the method call, before the parameters and variables.

There are some special instructions in most CPUs which combine moving the stack pointer and putting the contents of a register onto the stack. During a task switch, for example, many or all of the register contents are "pushed" onto the stack. When the task regains control, they are "popped" back off in reverse order. This is a so-called LIFO - last in, first out - type of buffer. Since each task has its own stack, the last part of a task switch is to change the stack pointer and the program counter (pointer to the task's code) to the stack and code of the task gaining control. So in addition to storing temporary variables, a stack is also used to store/restore a task's context.
The heap is the left over memory after the program code has been loaded into memory and the stack(s) have been allocated. There is typically a lot more of it than would be used for a single stack. If the program needs some memory for something, it can request from the operating system a chunk of memory which is taken from the heap. The operating system has to keep track of which part of the heap has been given out and which part is still free. When the program doesn't need this memory any more, in some operating systems it must explicitly give it back. If the programmer forgets to do this, he/she has what is known as a "memory leak". Some function which is called intermittently allocates memory from the heap, storing a pointer to this memory on the stack. When the function completes, the pointer on the stack is discarded, and there is now no more reference to the location of the allocated memory. So every time the function is called, a little bit more of the heap is permanently taken away and wasted. When the heap runs out, the function can no longer do what it is supposed to do and somehow fails on the next call. The program may handle this gracefully or may simply crash.
This is one of the major pitfalls in C programming. Whole industries have sprung up around making tools and test systems to find the source of memory leaks.
Java tries to prevent this by NOT requiring or even allowing the programmer to explicity free up memory allocated from the heap. A garbage collector does this automatically. This is a practical requirement for any object-oriented language. While references (pointers in C) to objects may reside on the stack, when the actual objects are instantiated the memory is typically taken from the heap. It would be extremely tedious to have to manually allocate the memory for each object one wished to instantiate. In Java you don't manually allocate the memory from heap with a call to the operating system such as the C function malloc(). When you instantiate something with "new", this happens automatically.
Note that you still aren't free of the problem of the heap running out just because it is managed automatically. If you use "new" to create enough objects, you can use up all the available heap.
23 years ago
I tried a number of editors and IDEs when I started with Java, and what irritated me, aside from the big learning curve with ones like JBuilder, is that some won't leave your code alone. High level OOD tools which generate the Java code based on XML or whatever are fine for experts on huge projects, but counterproductive when you're trying to learn Java. Some take it upon themselves to rewrite or reformat code you've written by hand. I also hate it when HTML editors do that... On the other hand, using the Notepad and command line is tedious.
I searched the Internet for Java tools, downloaded and tried several, and finally settled on Kawa, which got started as shareware from Tek-Tools and now has been sold to Allaire (who are merging with MacroMedia). It color highlights your code, but leaves it the way you wrote it. It lets you compile your code with a mouseclick using the Sun SDK which you already installed, jump from compiler error messages to the line in the source code, run your applet in an appletviewer with a mouseclick, and if you set it up right also lets you view Sun's source code for the standard Java classes as well as the Javadocs. I tried the Notepad route for about 3 days until the tedium drove me crazy and I started looking for a better way. Kawa was simple enough to use that I didn't have a problem with the learning curve. It mad me a LOT more productive. You can get a trial version of Kawa from www.allaire.com.
23 years ago
Netscape 6 and StarOffice were written in Java - you can tell from the look-and-feel and how slow they run. But they look like regular applications, so they must have a build-in JVM, which is what you need. Since Netscape 6 is based on an open source project, you might be able to get some information on how to do this by tracking that down.
23 years ago
The test part (main()) is an application which instantiates the class, not another class. The class by itself does nothing.
The following question is certainly beyond the scope of a beginning Java course, but you might as well be exposed to the general idea of protecting variables against concurrent access. What happens if - thinking of this as an analog - two librarians try to add a new book at the same time? Is is possible for one of them to get the nextId, and then before it is incremented, the other to also get the same nextId, resulting in two books with the same id?
It is definitely unlikely, but I'm not sure the possibility can be categorically excluded. For example, in a multi-threaded program where a thread is interrupted at exactly the wrong instant and then another thread gets control. You're probably thinking, 'what is a thread?'. Imagine the logic of your program as a track, with two runners running down the track at the same time. Or in this situation, two librarians. There is a way to deal with this. A method to get the nextId could be written, and declared 'synchronized'.
private synchronized int getTheNextId()
{
return nextId++;
}
The constructor would call this method instead of accessing the nextId variable directly. Only one thread is allowed to go through this method at a time. You may be wondering how nextId could be read twice without it being incremented between the first and the second access. It depends on what kind of machine instructions the CPU is capable of executing and what kind of Java byte code is generated and what the JVM does. For example, there *could* be an atomic instruction at the hardware level which does all of this - atomic meaning something that can't be divided into any more parts - an all or nothing instruction as it were. I have seen processors with special registers which increment automatically when they are read. But the above Java code might also be implemented as several separate machine code instructions - one to read the value from memory into a register, another to increment the register, and another to write the register back to memory. If a thread were interrupted just after executing the first instruction, another thread could run through the same code, and also read the memory into a register in its own context (a context is each thread's copy of the register contents).
23 years ago
I have a partly developed game with some cheesy animations
where I converted some lo-res trial images from scratch. I'd
like to display some decent animations. I have MacroMedia
Dreamweaver 4 Fireworks 4 Studio, and the Fireworks uses
PNG as its native format. Probably I could also convert some
animations or find a tool to make GIF animations. All I have found in the various O'Reilly and other books on AWT, Swing, How-To... is stuff about manipulating basic Java images. How
do I get a PNG or GIF, or at least a cell, into an image? As
in, where is a class to save me all the work?
23 years ago