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

Anish Patel

Greenhorn
+ Follow
since May 25, 2001
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 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.*;
import java.io.*;
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.
thanx

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!!!
P.S THANX AGAIN
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
{//1
private Controller controlObj;//decleration part
private Pump pumpObj;
private Panel petrolPan, conPan, pumpPan;
public fuel()
{//fuel

}//fuel
public void update(Graphics g) //avoids flicker
{
paint(g);
}

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?
g.setColor(Color.red);
//else//if not black
g.setColor(Color.black);
g.fillOval(100,100,50,50);
}//end paint

public void init()//set up the fuel system
{//init
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
}//init

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);
totalTF.setText("");
conPan.add(totalTF);

conBut = new Button("Enable");//new customer
conBut.addActionListener(this);
conPan.add(conBut);
}
public void actionPerformed(ActionEvent ae)
{//ap
if (ae.getSource() == conBut)
showStatus ("jeff");
controlObj.resetPump();
}//ap

public void resetPump()
{//16
totalTF.setText("88888888");
pumpObj.priceTF.setText("88888888");
pumpObj.litresTF.setText("88888888");
waitaMo( );
totalTF.setText("");
pumpObj.litresTF.setText("");
pumpObj.priceTF.setText("�00.00");

}//16
public void waitaMo( )
{//17
long nowTime = System.currentTimeMillis( );
long t = 0;
do
{//18
t = t + 1; //or, do nothing at all and save a bit of typing
}while(System.currentTimeMillis()<(nowTime+1000));//18
}//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
}//endrun


}
class Pumpimplements ActionListener, ItemListener, Runnable
{//classpump
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()
{//pubpump
petrolLab = new Label ("TYPE");
pumpPan.add(petrolLab);

petrolTF = new TextField(12);
petrolTF.setText("");
pumpPan.add(petrolTF);

litresLab = new Label("LITRES");
pumpPan.add(litresLab);

litresTF = new TextField(12);
litresTF.setText("");
pumpPan.add(litresTF);

priceLab = new Label("�");
pumpPan.add(priceLab);

priceTF = new TextField(12);
priceTF.setText("");
pumpPan.add(priceTF);

pumpBut = new Button("PUMP");//new customer
pumpBut.addActionListener(this);
pumpPan.add(pumpBut);

bGrp = new CheckboxGroup();
lrp = new Checkbox("LRP", false, bGrp);
ul = new Checkbox("UL", false, bGrp);
dsl = new Checkbox("DSL", false, bGrp);
lrp.addItemListener(this);
ul.addItemListener(this);
dsl.addItemListener(this);
pumpPan.add(lrp);
pumpPan.add(ul);
pumpPan.add(dsl);

}//pubpump


public void actionPerformed(ActionEvent ae)
{//ap
if(ae.getSource()==pumpBut)
{
pumpOn();
}
if(ae.getSource()==pumpBut)
{
pumpOff();
}
}//ap

public void itemStateChanged(ItemEvent ie)
{//ic
if (ie.getSource() == lrp)
petrolTF.setText("lrp");
pumpPrice = 00.79;

if (ie.getSource() == ul)
petrolTF.setText("ul");
pumpPrice = 00.83;

if (ie.getSource() == dsl)
petrolTF.setText("dsl");
pumpPrice = 00.67;

}//ic

public void pumpOn()
{
showStatus("pump me");
on = true;
counterThread = new Thread (this, "");
counterThread.start();
}//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
repaint();
try
{
counterThread.sleep(100);
}
catch (InterruptedException ie)
{
}
}// end while
}//end run

}//classpump
}//1
20 years ago