• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Start: Applet not initialized

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing an applet that randomly selects 10 cards and then displays them. I can compile my code fine but when I run it, the applet viewer says Start: Applet not initialized. I am unsure what is wrong with my code, can anyone help?


import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.applet.Applet;
import java.lang.Math;
import java.util.Random;

public class unit12Assignment extends Applet
{
Image card1, card2, card3, card4, card5, card6, card7, card8, card9, card10, card11, card12, card13;
Image card14, card15, card16, card17, card18, card19, card20, card21, card22, card23, card24, card25, card26;
Image card27, card28, card29, card30, card31, card32, card33, card34, card35, card36, card37, card38, card39;
Image card40, card41, card42, card43, card44, card45, card46, card47, card48, card49, card50, card51, card52;

public void init()
{
Image[] card = new Image[52];

card[0] = getImage( getDocumentBase(), "c1.gif" );
card[1] = getImage( getDocumentBase(), "c2.gif" );
card[2] = getImage( getDocumentBase(), "c3.gif" );
card[3] = getImage( getDocumentBase(), "c4.gif" );
card[4] = getImage( getDocumentBase(), "c5.gif" );
card[5] = getImage( getDocumentBase(), "c6.gif" );
card[6] = getImage( getDocumentBase(), "c7.gif" );
card[7] = getImage( getDocumentBase(), "c8.gif" );
card[8] = getImage( getDocumentBase(), "c9.gif" );
card[9] = getImage( getDocumentBase(), "c10.gif" );
card[10] = getImage( getDocumentBase(), "cj.gif" );
card[11] = getImage( getDocumentBase(), "cq.gif" );
card[12] = getImage( getDocumentBase(), "ck.gif" );
card[13] = getImage( getDocumentBase(), "d1.gif" );
card[14] = getImage( getDocumentBase(), "d2.gif" );
card[15] = getImage( getDocumentBase(), "d3.gif" );
card[16] = getImage( getDocumentBase(), "d4.gif" );
card[17] = getImage( getDocumentBase(), "d5.gif" );
card[18] = getImage( getDocumentBase(), "d6.gif" );
card[19] = getImage( getDocumentBase(), "d7.gif" );
card[20] = getImage( getDocumentBase(), "d8.gif" );
card[21] = getImage( getDocumentBase(), "d9.gif" );
card[22] = getImage( getDocumentBase(), "d10.gif" );
card[23] = getImage( getDocumentBase(), "dj.gif" );
card[24] = getImage( getDocumentBase(), "dq.gif" );
card[25] = getImage( getDocumentBase(), "dk.gif" );
card[26] = getImage( getDocumentBase(), "h1.gif" );
card[27] = getImage( getDocumentBase(), "h2.gif" );
card[28] = getImage( getDocumentBase(), "h3.gif" );
card[29] = getImage( getDocumentBase(), "h4.gif" );
card[30] = getImage( getDocumentBase(), "h5.gif" );
card[31] = getImage( getDocumentBase(), "h6.gif" );
card[32] = getImage( getDocumentBase(), "h7.gif" );
card[33] = getImage( getDocumentBase(), "h8.gif" );
card[34] = getImage( getDocumentBase(), "h9.gif" );
card[35] = getImage( getDocumentBase(), "h10.gif" );
card[36] = getImage( getDocumentBase(), "hj.gif" );
card[37] = getImage( getDocumentBase(), "hq.gif" );
card[38] = getImage( getDocumentBase(), "hk.gif" );
card[39] = getImage( getDocumentBase(), "s1.gif" );
card[40] = getImage( getDocumentBase(), "s2.gif" );
card[41] = getImage( getDocumentBase(), "s3.gif" );
card[42] = getImage( getDocumentBase(), "s4.gif" );
card[43] = getImage( getDocumentBase(), "s5.gif" );
card[44] = getImage( getDocumentBase(), "s6.gif" );
card[45] = getImage( getDocumentBase(), "s7.gif" );
card[46] = getImage( getDocumentBase(), "s8.gif" );
card[47] = getImage( getDocumentBase(), "s9.gif" );
card[48] = getImage( getDocumentBase(), "s10.gif" );
card[49] = getImage( getDocumentBase(), "sj.gif" );
card[50] = getImage( getDocumentBase(), "sq.gif" );
card[51] = getImage( getDocumentBase(), "sk.gif" );

String cardNumber;
double cardRandom;
int cardRandomNumber;
int[] ranNum = new int[10];
Random ran = new Random();
Graphics g = null;

for (int number = 0; number <= 9; )
{
cardRandom = ran.nextInt(52) + 1;
cardRandomNumber = (int)Math.round( cardRandom );

if ( cardRandomNumber > 0 && cardRandomNumber <= 52 )
{
ranNum[number] = cardRandomNumber;
number++;
}
}
paint( g, ranNum, card );
}

public void paint(Graphics g, int[] ranNumber, Image[] cards)
{
setBackground( Color.green );
g.drawImage( cards[ranNumber[0]], 10, 10, this);
}
}
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are probably error messages in the Java Console; post those here.
 
Albert Dong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:There are probably error messages in the Java Console; post those here.



No idea what you mean. It compiled fine.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Graphics g = null;
...
paint( g, ranNum, card );

does something look strange here?
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Albert Dong wrote:

Ulf Dittmer wrote:There are probably error messages in the Java Console; post those here.



No idea what you mean. It compiled fine.



That response makes it sound like you are entirely unfamiliar with the possibility that you might have errors at run-time. That being the case, you should stick to writing ordinary applications until you get a bit more experience with the language. Applets are not a technology for beginners.
 
Albert Dong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Dunn wrote:Graphics g = null;
...
paint( g, ranNum, card );

does something look strange here?



I had no idea what to set it too so I out null there as a temp.
 
Albert Dong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Albert Dong wrote:

Ulf Dittmer wrote:There are probably error messages in the Java Console; post those here.



No idea what you mean. It compiled fine.



That response makes it sound like you are entirely unfamiliar with the possibility that you might have errors at run-time. That being the case, you should stick to writing ordinary applications until you get a bit more experience with the language. Applets are not a technology for beginners.



It's homework.
 
I'm still in control here. LOOK at this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic