The Artima Developer Community
Sponsored Link

Java Answers Forum
ERRORS

2 replies on 1 page. Most recent reply: Dec 3, 2002 10:40 AM by Ernie Douglas

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Ernie Douglas

Posts: 18
Nickname: y2j
Registered: Nov, 2002

ERRORS Posted: Dec 2, 2002 2:34 PM
Reply to this message Reply
Advertisement
Could someone sort these errors out for me cause i ain't got a clue how to deal with them, i have narrowed it down to 7, which use to be 19, thanks for your help

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class guessnumber extends Applet implements Runnable, ActionListener
{
String msg;
Thread t = null;
int state;
boolean stopflag;
private Label l1, l2;
private TextField t1, t2;
private Button b1;
private int num, mynum, diff, red, blue, green, chance = 0;
private Color c;

public void init()
{
c = new Color( 0, 80, 0 );
setForeground( c );
l1 = new Label("I have kept a number between 1 and 1000.");
l2 = new Label("Can you guess this number?");
t1 = new TextField(10);
t2 = new TextField(10);
b1 = new Button("Play Again");
t2.setEditable(false);
add(l1);
add(l2);
add(t1);
add(t2);
add(b1);

t 1.addActionListener(this);
b1.addActionListener(this);
num = 1 + (int) (Math.random()*1000);
}

public void start()
{
msg = getParameter( "Guess The Number?" );
if(msg == null)
{
msg = "Message not found";
}
msg = " " + msg;
t = new Thread( this );
stopflag = false;
t.start();
}

public void run()
{
char ch;
for( ; ; )
{
try
{
repaint();
Thread.sleep(200);
ch = msg.charAt(0);
msg = msg.substring( 1, msg.length() );
msg += ch;
if(stopflag)
{
break;
}
}
catch( InterruptedException e)
{
System.out.println( "Exception" + e );
}
}
}

public void stop()
{
stopflag = true;
t = null;
}

public void paint(Graphics g)
{
g.drawString( msg, 70, 130 );
}

public void actionPerformed( ActionEvent ae )
{

if( ae.getSource() == b1 )
{
red = 255;
blue = 255;
green = 255;
c = new Color(red, green, blue);
setBackground(c);
num = 0;
num = 1 + (int) (Math.random()*1000);
chance = 0;
showStatus( "" );
t1.setEditable(true);
t2.setEditable(false);
t1.setText("");
t2.setText("");
}
else
{
mynum = Integer.parseInt(t1.getText());
chance++;
if( chance == 1 )
{
showStatus( chance + " chance over" );
}
else
{
showStatus( chance + " chances over" );
}
if( chance >= 9 )
{
t1.setText( String.valueOf(num) );
showStatus( "Your 9 chances are up" );
t1.setEditable( false );
}
diff = num - mynum;
if(diff == 0)
{
setBackground(Color.pink);
t1.setEditable(false);
t2.setText("You've done it");
t2.setEditable(false);
}
else if(Math.abs(diff)>200)
{
if(diff>0)
{
t2.setText("Too Low");
}
else
{
t2.setText("Too High");
}
}
else if(Math.abs(diff)<200)
{
if(diff>0)
{
red = 255-diff;
green = 0;
blue = 0;
c = new Color(red, green, blue);
t2.setText("");
setBackground(c);
}
else if(diff<0)
{
red = 0;
green = 0;
blue = 255 + diff;
c = new Color(red, green, blue);
t2.setText("");
setBackground(c);

if (count < 10) System.out.print ("Congrats.. you took less than 10 chances");
else
if (count == 10) System.out.print ("Congrats .. you just made it");
else
System.out.print ("you need practice");
{ JOptionPane.showMessageDialog (null,
"Illustrate the use of JOptionPane methods");
String firstName = JOptionPane.showInputDialog
("What is your first name?");
String lastName = JOptionPane.showInputDialog
("What is your last name?");
JOptionPane.showMessageDialog (null,
"Reversed it is " + lastName + ", " + firstName);
System.exit (0); // needed when using JOptionPane

}
}
}
}
}


gm

Posts: 1
Nickname: gm
Registered: Dec, 2002

Re: ERRORS Posted: Dec 3, 2002 6:30 AM
Reply to this message Reply
you're missing imports & you're confusing count & chance I think.

Ernie Douglas

Posts: 18
Nickname: y2j
Registered: Nov, 2002

Re: ERRORS Posted: Dec 3, 2002 10:40 AM
Reply to this message Reply
Thanks

Flat View: This topic has 2 replies on 1 page
Topic: Problem opening multiple workbooks in a single java program using ExcelAcce Previous Topic   Next Topic Topic: Servlet and Applet Communication

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use