drew taylor

Greenhorn
+ Follow
since Feb 20, 2006
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 drew taylor

I'm trying to read the data from the text file, but the following code only seems to read the first line, why is this?

Thanks,

try {
File file = new File(fileName);
FileReader reader = new FileReader(file);
BufferedReader in = new BufferedReader(reader);
String string;
while ((string = in.readLine()) != null) {
System.out.println(string);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
15 years ago
Thanks guys, I just added true after the filename to write to and it worked
[ April 06, 2008: Message edited by: drew taylor ]
15 years ago
Hi,

Can anyone see why the code below doesn't append (text entered by user in GUI) to the end of the text file? It just overwrites the original text in the file:

// Write text to file
out.append(textBox.getText());
out.println();
out.close();

I have also tried:

out.append(textBox.getText() + '\n'); but the original text was still overwritten.

Any suggestions?

Thanks,
15 years ago
Hi, I have spent ages trying to get this to work. I'm trying to store the value of a textBox into a textFile when the button is clicked.

Instead of out.println("This is line 1"); would I use something like:

out.println(textBox.text) ??

15 years ago
Hi, I have spent ages trying to get this to work. I'm trying to store the value of a textBox into a textFile when the button is clicked.

Instead of out.println("This is line 1"); would I use something like:

out.println(textBox.text) ??

15 years ago
Hi,

Any help or suggestions will be very much appreciated

I'm trying to insert an object reference into an array where the next value in the array is null. So far I have the following code although I'm not sure if this is the correct way to do this:


// Takes a teacher object reference an inserts into array where
// next value is null.
public void insertTeacher(Teacher teacher) {

count = teacherList.length;

if (teacherList.length == 0) // Insert at index 0 if array is empty
teacherList[0] = teacher;
else
{

for (int i = 0; i < count; i++)
{
if (i < count)
insert where teacherList[i] = null ???



Am I going in the right direction with this? Can someone provide me with example code for 'insert where teacherList = null' ?
16 years ago
Ok, here is my code in the main class where I intstantiate a new student object: ( I have included the while loop I tried to make 10 objects and add them to an ArrayList in the ClassRoom class which doesn't work)


The other code I have are the constructors in the ClassRoom class and Student class.

What does making a service to create random objects involve?
16 years ago
I have a Student class that sets up random student attributes, and I have a ClassRoom class that contains an ArrayList to store student reference variables. Given that a set of 10 students will need to be created often and assigned to a classRoom, how can Instantaite 10 different student objects at the same time?

I tried making a while loop to loop 10 times but it only created the same object over and over and added it on top of the first one in the ArrayList in the ClassRoom class.

So how can I make 10 different objects without 10 separate object declarations that, when called will always replace the previously instatiated objects with the same reference variable names?
16 years ago
Hi, I am new to java and I was hoping somebody could explain how to do the following or provide me a code snippet - any help would be appresiated

I need a method that can loop and prompt the user to enter 2 numbers as int.

Would I use the scanner class to get the user input? Then I need to add them to an ArrayList which can store the two numbers, loop and output the values.
16 years ago
I want to call a method (setSquare()) when a JLabel is clicked by the user, the following code should work:

private void grid11MouseClicked(java.awt.event.MouseEvent evt) {

setSquare();
}


But I get this error, please can someone tell me what this means? The method is already defined in the class and I have imported javax.swing etc

Frame.java:181: setSquare(javax.swing.JLabel) in p1.Frame cannot be applied to ()
16 years ago
Hi,

Please help me if you can.

I'm using netbeans, I have a Dog class with a bark() method which contains an If/Else Statement:

void bark() {
if (size > 60) {
System.out.println("Woof! Woof!");
} // If

if (size > 14) {
System.out.println("Ruff! Ruff!");
} // If

else {
System.out.println("Yip! Yip!");
} }

When I call this method from the Dog class with a new Dog object (after I have initialised it with a value of 64, the If statements execute If size > 60 AND if size > 14 and it didn't before! Why is this? It used to just execute the top If statement.

The only thing I can think of is that I was trying to define set CLASSPATH on the command prompt the other day (to no success even though it was pointing right to the folder for javac etc) but I don't think this would cause an If statement to execute like this?
16 years ago
Java and Netbeans work ok, but when I try and compile java files in the command prompt it says javac isn't a program! Why is this?
16 years ago
I think I got it to work. I'm trying to modify an existing example class that gets the html information about a specified website. I did the following:

Instead of having:

while (in.hasNextLine()) {
System.out.println(" " + in.nextLine());
}

I modified it to:

Scanner in = new Scanner(u.getInputStream());

int i = 6;

while (i > 0) {
System.out.println(" " + in.nextLine());
i = i -1;
}
16 years ago
Please can someone help me with the following? I have tried looking on the net for an example progeam or a tutorial but I didn't find anything.

How can I make it so that my program prints out a specifed number of lines from a file (i.e a text file, html document)

Any hints, example code will be appresiated!
16 years ago
Please can someone tell me how can I call the method inside the System.out.println? I keep getting an error.

Dog bigDog = new Dog();
bigDog.name = "BigDoggy";

System.out.println("BigDoggy says: ") + bigDog.name() ;
16 years ago