|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 | |
|
Member (8 bit)
Join Date: Feb 2001
Posts: 156
|
java problem (maybe ultraedit)
ok.... I'm writing 2 diff class files. A dice.java that handles the random numbers and stuff and a diceinterface.java to handle the GUI and other stuff. DiceInterface runs dice. Anyway here is my problem. My program did what I wanted it to but then I realized I was suppose to have some other stuff so I added what I thought I was suppose to have. What are in the comments are what I thought I was suppose to have. but that isn't where it was originally placed. Anyway I put that in and then compiled then compiled the diceinterface.java and when I compiled the diceinterface.java it came back with this.
Quote:
Dice.java Code:
public class Dice extends Object{
private int currentSide;
private int totalRolls;
private int average;
private int sum;
public Dice(){
currentSide = 0;
totalRolls = 0;
average = 0;
sum = 0;
}
public int setCurrentSide(){
return currentSide;
}
public String toString(){
String str;
str = "Current Side: " + currentSide + "\n" +
"Total Rolls: " + totalRolls + "\n" +
"Average: " + average + "\n";
return str;
}
public void roll(){
currentSide = (int)(Math.random() * 6) + 1;
totalRolls++;
sum += currentSide;
average = (int) Math.round(sum / totalRolls);
}
public void reset(){
currentSide = 0;
totalRolls = 0;
sum = 0;
average = 0;
}
}
/*
public int getCurrentSide(){
return currentSide;
}
public int getTotalRolls(){
return totalRolls;
}
public int getAverage(){
return average;
}
*/
Code:
import java.awt.*;
import BreezyGUI.*;
public class DiceInterface extends GBFrame{
Label d1Label = addLabel ("Dice 1", 1, 1, 1, 1);
Label d1AvgLabel = addLabel ("Average", 1, 3, 1, 1);
Label d2Label = addLabel ("Dice 2", 2, 1, 1, 1);
Label d2AvgLabel = addLabel ("Average", 2, 3, 1, 1);
Label totalRollsLabel = addLabel ("Total Rolls", 3, 1, 2, 1);
/*
TextArea d1CurrentField = addTextArea (0, 1, 2, 1, 1);
TextArea d1AvgField = addTextArea (0, 1, 4, 1, 1);
TextArea d2CurrentField = addTextArea (0, 2, 2, 1, 1);
TextArea d2AvgField = addTextArea (0, 2, 4, 1, 1);
TextArea totalRollsField = addTextArea (0, 3, 3, 1, 1);
*/
TextArea displayField = addTextArea ("",5,1,4,4);
Button rollButton = addButton ("Roll Dice", 4, 1, 2, 1);
Button resetButton = addButton ("Reset", 4, 3, 2, 1);
private Dice d1;
private Dice d2;
public DiceInterface(){
d1 = new Dice();
d2 = new Dice();
setTitle("Roll'em Boys");
}
public void buttonClicked (Button buttonObj){
if (buttonObj == rollButton){
d1.roll();
d2.roll();
displayField.setText("Dice 1 \n" + d1.toString());
d2DisplayField.setText("Dice 2 \n" + d2.toString());
//displayField.setText(d2.toString());
}
if (buttonObj == resetButton){
d1.reset();
d2.reset();
}
}
public static void main (String[] args){
Frame frm = new DiceInterface();
frm.setSize (400, 400);
frm.setVisible (true);
}
}
Josh (hope you can understand what I'm talking about) |
|
|
|
|
|
|
#2 |
|
Member (13 bit)
Join Date: Jul 2000
Location: Fullerton, CA
Posts: 7,030
|
Hi Josh,
Were you able to compile the code before? I have not used UltraEdit before but my guess is that you have to set the Java compile/run tool settings before you can compile. I ask because it looks like "DiceInterface/java" should be "DiceInterface.java" and the compiler is looking for the first file (which doesn't exist, hence the "main" error).
__________________
"A witty saying proves nothing." - Voltaire |
|
|
|
|
|
#3 |
|
Registered User
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
|
in the DiceInterface.java
why are you import import BreezyGUI.*; should it be Dice???? and also you should import javax.swing.*; into DiceInterface... and the main's wrong;; should be as follow Code:
public static void main (String[] args){
DiceInterface frm = new DiceInterface();
frm.setSize (400, 400);
frm.setVisible (true);
}
Last edited by c-learner; 03-21-2002 at 12:48 PM. |
|
|
|
|
|
#4 |
|
Registered User
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
|
try this
Code:
import java.io.*;
public class Dice extends Object{
private int currentSide;
private int totalRolls;
private int average;
private int sum;
public Dice(){
currentSide = 0;
totalRolls = 0;
average = 0;
sum = 0;
}
public int setCurrentSide(){
return currentSide;
}
public String toString(){
String str;
str = "Current Side: " + currentSide + "\n" +
"Total Rolls: " + totalRolls + "\n" +
"Average: " + average + "\n";
return str;
}
public void roll(){
currentSide = (int)(Math.random() * 6) + 1;
totalRolls++;
sum += currentSide;
average = (int) Math.round(sum / totalRolls);
}
public void reset(){
currentSide = 0;
totalRolls = 0;
sum = 0;
average = 0;
}
}
/*
public int getCurrentSide(){
return currentSide;
}
public int getTotalRolls(){
return totalRolls;
}
public int getAverage(){
return average;
}
*/
Code:
import java.awt.*;
import javax.swing.*;
public class DiceInterface extends JFrame{
Label d1Label = addLabel ("Dice 1", 1, 1, 1, 1);
Label d1AvgLabel = addLabel ("Average", 1, 3, 1, 1);
Label d2Label = addLabel ("Dice 2", 2, 1, 1, 1);
Label d2AvgLabel = addLabel ("Average", 2, 3, 1, 1);
Label totalRollsLabel = addLabel ("Total Rolls", 3, 1, 2, 1);
/*
TextArea d1CurrentField = addTextArea (0, 1, 2, 1, 1);
TextArea d1AvgField = addTextArea (0, 1, 4, 1, 1);
TextArea d2CurrentField = addTextArea (0, 2, 2, 1, 1);
TextArea d2AvgField = addTextArea (0, 2, 4, 1, 1);
TextArea totalRollsField = addTextArea (0, 3, 3, 1, 1);
*/
TextArea displayField = addTextArea ("",5,1,4,4);
Button rollButton = addButton ("Roll Dice", 4, 1, 2, 1);
Button resetButton = addButton ("Reset", 4, 3, 2, 1);
private Dice d1;
private Dice d2;
public DiceInterface(){
setTitle("Roll'em Boys");
d1 = new Dice();
d2 = new Dice();
}
public void buttonClicked (Button buttonObj){
if (buttonObj == rollButton){
d1.roll();
d2.roll();
displayField.setText("Dice 1 \n" + d1.toString());
d2DisplayField.setText("Dice 2 \n" + d2.toString());
//displayField.setText(d2.toString());
}
if (buttonObj == resetButton){
d1.reset();
d2.reset();
}
}
public static void main (String[] args){
Frame frm = new DiceInterface();
frm.setSize (400, 400);
frm.setVisible (true);
}
}
Last edited by c-learner; 03-21-2002 at 12:47 PM. |
|
|
|
|
|
#5 |
|
Member (8 bit)
Join Date: Feb 2001
Posts: 156
|
Hey thanks for the help guys.... I have UltraEdit set up right. I've been using it all semester. It just does crazy stuff sometimes?!?!? Ugh!
I am importing BreezyGUI b/c I'm using it to write the GUI. It's some crap that's in our book. The main method is correct. It is suppose to be Frame frm = new DiceInterface(); I will try deleting those *.java files and retype them as completely new files they way I have the code written down (it worked the first time). Thanks for the help guys. Josh |
|
|
|
|
|
#6 |
|
Registered User
Join Date: Dec 2000
Location: where justice defined.
Posts: 174
|
one question, what version of Java are you learning???
|
|
|
|
|
|
#7 |
|
Member (8 bit)
Join Date: Feb 2001
Posts: 156
|
ummm maybe something like 1.3.1 or something like that. Not for sure exactly. The BreezyGUI is not from java. It is classes written by the author of the text book we are using (I think he did. Don't really know) but they come on a cd with the book or you can download them from the internet.
Anyway.... I did what I said and just deleted those files and made 2 new ones with the same info and it worked. UltraEdit just did something to those files. Now I've completely gotten the program written. Thanks for the help guys. Josh |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|