Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Anish Patel

+ Follow
since May 25, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anish Patel

hyi i am currently working on a project at the moment its a little program that reads in a file and is then stored as as array but the loop will only read 7 items of the array how can i extended so it reads more ps the stuff on the file is details of endangered species i,e there name, count, etc so if you could please have a look at the code at make some modification i would be very greatfull

package myprojects.testarray;
import java.awt.*;
import java.awt.event.*;
class Testarray {

public static void main(String args[]) {
// A simple example of how to read in animal descriptions and plonk
// them in an array.

// Remember that count should really be an integer and a bit of conversion will have
// to occur.

// Also note that this example reads in 7 animals, but your version should detect
// the end of the file (i.e. use a different sort of loop).

String name[ ] = new String[1000];
String count[] = new String[1000];
String species[] = new String[1000];
String country[] = new String[1000];
try {
File inFile = new File("F:\\animals.dat");
// Create a file stream, wrapping the file
FileReader fileReader = new FileReader(inFile);
// Create a second wrapper,
BufferedReader bufReader = new BufferedReader(fileReader);
// Read in the first line...
String s;
// Read in 7 animals (how can this be improved?)
for (int i=0; i<7; i++) {
name[i] = bufReader.readLine();
count[i] = bufReader.readLine();
species[i] = bufReader.readLine();
country[i] = bufReader.readLine();
System.out.println("Name "+i+" is "+name[i]);
System.out.println("Count "+i+" is "+count[i]);
System.out.println("species "+i+" is "+species[i]);
System.out.println("Found in "+i+" is "+country[i]);


System.out.println("Starting Testarray...");
Testarray mainFrame = new Testarray();

catch (IOException e) {
System.out.println("IOException "+e);

19 years ago
hi i have created a vector with three elements salaried employee, nonsalaried employee and directors
i have also created text field using swing also lable which there details i.e. there name, payroll number,etc and i want to know i can insert the data from the vector in to the text fields
any help would be greatfull
20 years ago
thamks much appreciated
20 years ago
well i have set up an office class which contains the name of the company and displays the out put.
i have also set up an employee class which contains the names of the emploees and there details, under the method setEmployeeDetails(), and also there is a method in the employee class that displays the details of the employee.
In the office class i have create three objects which corresponds too 3 different employees, and then data is passesd into the objects like name and payroll number etc using the display details method in the employee class. i hope i have not confused you i am quite new to this.

20 years ago
i was wondering how would set up text boxes that store eg employee details i.e. Name, address, payroll number, date of joinning and also have buttons that i can add new employees and erase employees from the list, and a button that skips to the next employee
Any help would be greatly appreciated
20 years ago
Thanks so munch manfred that means alot to me what you have done.
one last small thing once the user presses the pump button the second time i want the cost to be displayed on the controllers text box so how would i do that!!!
20 years ago
I am currently doing a project which involves constructing a petrol station
However I think it is my thread that is not working. The situation works likes this, the
User clicks one of the checkboxes which represents a type of fuel then that should start the indicator
Flashing to tell the controller someone is requesting fuel (however not working also) from there the
Controller presses the enable button which turns the indicator light of f(switches to black) and then clears at the same time the controllers textbox, the price textbox and the litres text box (that is working). However if you look in the item state changed part in the pump class you can see I have the price set as the variable and the formula to work it out at the bottom. But when I press the pump button the metre does not go round like at petrol station, nothing happens, and when the pump button is pressed again the meter should stop
Displaying the cost of the fuel and amount of litres used and the price should also be displayed on the controllers textbox as well. If you could help I would be very greatfull thankyou. (code shown below)
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class fuel extends Applet
private Controller controlObj;//decleration part
private Pump pumpObj;
private Panel petrolPan, conPan, pumpPan;
public fuel()

public void update(Graphics g) //avoids flicker

public void paint(Graphics g)
{//here the paint( ) method is reading variable LEDlight that is changed by our thread
//run toggles LEDlight every 1/2 sec; note that run explicitly calls repaint()
//which calls update()
//if (LEDlight == true) //LEDon?
//else//if not black
}//end paint

public void init()//set up the fuel system
petrolPan = new Panel();
petrolPan.setLayout(new GridLayout(2,0));//two rows,
add(petrolPan);//attach to applet surface

conPan = new Panel();//panel to display controller
conPan.setBackground(new Color(67,25,175));
petrolPan.add(conPan);//dispaly on market panel

pumpPan = new Panel();//panel for a till
pumpPan.setBackground(new Color(110,103,43));
petrolPan.add(pumpPan);//dispaly on market panel

controlObj = new Controller();//instantiation part
pumpObj = new Pump();// new Pump object

class Controller implements ActionListener, Runnable
private TextField totalTF;
private Button conBut;
Button startBut,stopBut;
Thread LEDThread; //step 3
boolean LEDon; //Changed - can now be set to false by Stop Button
boolean LEDlight=false;

public Controller()
totalTF = new TextField(12);

conBut = new Button("Enable");//new customer
public void actionPerformed(ActionEvent ae)
if (ae.getSource() == conBut)
showStatus ("jeff");

public void resetPump()
waitaMo( );

public void waitaMo( )
long nowTime = System.currentTimeMillis( );
long t = 0;
t = t + 1; //or, do nothing at all and save a bit of typing
}//end waitamo

public void run() //step 6
//for(; //loop forever REMOVED NOW
while (LEDon == true)
LEDlight = !LEDlight; //toggle the LED status
repaint();//call paint so it draws the LED in its new state
try{//we'll talk about try..catch next week
LEDThread.sleep(500); //wait for 500 milliseconds (1/2 second)
}catch(InterruptedException e)
showStatus("Thread timed out");
showStatus("LED = "+LEDlight);
}//end while
//}//endfor REMOVED

class Pumpimplements ActionListener, ItemListener, Runnable
private Label petrolLab, litresLab, priceLab;
private TextField petrolTF, litresTF, priceTF;
private Button pumpBut;
private boolean tillStatus = false;
private CheckboxGroup bGrp;
private Checkbox lrp, ul, dsl;
Thread counterThread;
boolean on=false;
private double value=0;
private double litre =1;
boolean pumping = true;
double pumpPrice, total;
public Pump()
petrolLab = new Label ("TYPE");

petrolTF = new TextField(12);

litresLab = new Label("LITRES");

litresTF = new TextField(12);

priceLab = new Label("�");

priceTF = new TextField(12);

pumpBut = new Button("PUMP");//new customer

bGrp = new CheckboxGroup();
lrp = new Checkbox("LRP", false, bGrp);
ul = new Checkbox("UL", false, bGrp);
dsl = new Checkbox("DSL", false, bGrp);


public void actionPerformed(ActionEvent ae)

public void itemStateChanged(ItemEvent ie)
if (ie.getSource() == lrp)
pumpPrice = 00.79;

if (ie.getSource() == ul)
pumpPrice = 00.83;

if (ie.getSource() == dsl)
pumpPrice = 00.67;


public void pumpOn()
showStatus("pump me");
on = true;
counterThread = new Thread (this, "");
}//end pumpon

public void pumpOff()
on = false;

public void run()
while (on==true)
value = value+litre;
litresTF.setText("" + value);
total = value * pumpPrice;
priceTF.setText("" + total); // output needs formatting properly
catch (InterruptedException ie)
}// end while
}//end run

20 years ago