ahh... ok. your welcome.Originally Posted by jerx d great
apply dayon sa NSP. tun-i ang OOP, network programming, etc.
maau didto to start your career.
OT:Originally Posted by jerx d great
Yup. BTW Dili ko programmer karon. Computer Science ko grad pero lahi ako trabaho karon. Laayo ra kaau sa akong course. Heheh...
mao bah!!
unsa diay work nimo ron bro??
mayng gani ka wla pa jud mawla imong memory sa java sa??
asa ka ni grad bro??
PM'ed you bro.Originally Posted by jerx d great
@bai cen, what if imong i read ug balik ang imong gi write bro!! unsa nimo pag retrieve niya!?
Since na saved naman ang state sa Object. Mao ni ang pag-retrieve.Originally Posted by jerx d great
Code:inputStream = new ObjectInputStream(new FileInputStream("jerus.records")); temp=(Animal) inputStream.readObject(); // since inputStream.readObject() returns "Object" it is important to // morph the object into "animal Object" temp.getSpeciesName(); // returns String temp.getPopulation(); // returns String temp.getGrowthRate(); // returns String
but bro, using this program nga akong gi post karon, unsaon mang pag butang niya sa textArea bro!! dli man jud siya modawat?? mo error man siya!?? morag ang akong problema bro sa, kay kanang akng gi bold, naa kay solution ana bro??
dara ang code ai...
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class Display_Records extends JFrame{
public static final int width = 610;
public static final int height = 250;
Create_Record x = new Create_Record();
public Display_Records(){
JPanel North;
JPanel South;
addWindowListener(new WindowTerminator());
setTitle("Display Records");
setSize(width,height);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JLabel speciesName = new JLabel("Species Name");
JLabel population = new JLabel("Population");
JLabel growthRate = new JLabel("Growth Rate");
JLabel projectedGrowthRate = new JLabel("Projected Growth Rate");
JTextArea content = new JTextArea(5,55);
North = new JPanel();
North.setLayout(new GridLayout(0,4));
North.add(speciesName);
North.add(population);
North.add(growthRate);
North.add(projectedGrowthRate);
contentPane.add(North,BorderLayout.NORTH);
ObjectInputStream inputStream = null;
try{
inputStream = new ObjectInputStream(new FileInputStream("jerus.records"));
}
catch(IOException e){
displayErrors();
}
Animal line1 = null;
try{
line1 = (Animal)inputStream.readObject();
line1.getSpeciesName();
line1.getPopulation();
line1.getGrowthRate();
content.setText(line1);
inputStream.close();
}
catch(Exception ex){
displayErrors();
}
South = new JPanel();
South.setLayout(new FlowLayout());
South.add(content);
contentPane.add(South);
}
public void displayErrors(){
JFrame errors = new JFrame();
errors.setLayout(new FlowLayout());
errors.setSize(100,100);
errors.setTitle("Error");
JLabel errorMessage = new JLabel("Error Opening File!!");
errors.add(errorMessage);
errors.setVisible(true);
errors.pack();
}
}
Wrong...
Wrong since line1 is an Object Animal. Pwede ra unta to line1.toString() ang gamiton pero wala nimo gi-override ang object.toString() method sa Object Animal.Code:line1 = (Animal)inputStream.readObject(); line1.getSpeciesName(); line1.getPopulation(); line1.getGrowthRate(); content.setText(line1); inputStream.close();
Solution...
Code:String text=""; line1 = (Animal)inputStream.readObject(); text="Name: " + line1.getSpeciesName() +"\n"; text=text + "Population: " + line1.getPopulation() + "\n"; text=text+ "Growth Rate: " + line1.getGrowthRate()+ "\n"; content.setText(text); inputStream.close();
Similar Threads |
|