Re: Possible Array problem. Applet Compiles but does not run!
From: Andrew Thompson (SeeMySites_at_www.invalid)
Date: 12/16/04
- Next message: BladeZ: "Re: Possible Array problem. Applet Compiles but does not run!"
- Previous message: Daniel Rohe: "Re: Formatting java source code"
- In reply to: BladeZ: "Possible Array problem. Applet Compiles but does not run!"
- Next in thread: BladeZ: "Re: Possible Array problem. Applet Compiles but does not run!"
- Reply: BladeZ: "Re: Possible Array problem. Applet Compiles but does not run!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Dec 2004 14:19:15 GMT
On Thu, 16 Dec 2004 08:42:59 -0500, BladeZ wrote:
> I have this script (sorry its long but its neccessary for me to post it
> all);
SSCCE's[1] are quite welcome here, and an entire post of 126
lines is not unreasonable.
[1] <http://www.physci.org/codes/sscce.jsp>
(snip main code)
> This compiles, however it does not initialise. I Don't really understand
> what the Dos window tells me but I think the problem is in line 29;
Yes, but your line numbers do not correspond with mine.
In any case, the problem is pretty clear.. see this altered fragment
<snippet>
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MobileShop extends Applet implements ActionListener{
private Mobile phone[];
private Button priceListbutton;
private Button button[];
public int Decision = 0;
private int modelNumber = 5;
public void init() {
// this only needs to be done once, and 'init'ially.
phone = new Mobile[modelNumber];
phone[0] = new Mobile("R2D2", 3, 5, 102,false, 79.95f);
phone[1] = new Mobile("C3PO", 4, 6, 85, false, 99.95f);
phone[2] = new Mobile("UB40", 5, 12, 89, false, 129.95f);
phone[3] = new Mobile("WD40", 10, 10, 91, true, 189.95f);
phone[4] = new Mobile("RU18", 12,18, 77, true, 219.95f);
// further, it needs to have created the phones array
// *before* it gets to here!
button = new Button[modelNumber];
for(int i = 0; i < modelNumber; i++)
{
button[i] = new Button(phone[i].getmodel());
add(button[i]);
button[i].addActionListener(this);
}
} // end init
public void paint(Graphics g) {
if (Decision == 0){
for (int a = 0; a < modelNumber; a ++){
g.drawString("Name: " + phone[a].getmodel(), 90,70 + 15 * a);
}
...
</snippet>
HTH
-- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane
- Next message: BladeZ: "Re: Possible Array problem. Applet Compiles but does not run!"
- Previous message: Daniel Rohe: "Re: Formatting java source code"
- In reply to: BladeZ: "Possible Array problem. Applet Compiles but does not run!"
- Next in thread: BladeZ: "Re: Possible Array problem. Applet Compiles but does not run!"
- Reply: BladeZ: "Re: Possible Array problem. Applet Compiles but does not run!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|