Đang tải... (xem toàn văn)
This chapter presents the following content: GUI overview, event-driven programming basics, GUI classes and packages, a simple window program, JFrame Class, Java components, JLabel component, JTextField Component, Component Listeners, interfaces, inner classes, anonymous inner classes, jbutton component, JOptionPane Dialog Box, distinguishing between multiple events, using GetActionCommand to distinguish between multiple events (optional), color.
CSC241: Object Oriented Programming Lecture No 32 Previous Lecture • Stream and classes • Input and Output stream • iostream class • ios class – Formatting Flags – Error-Status Bits – Formatted File I/O » Reading data » Writing data Today’s Lecture • File operations • Formatted File I/O • Reading data • Writing data • Character I/O • Binary I/O • Object I/O Character I/O • • put() and get() functions, can be used to output and input single characters These are member of ostream and istream, respectively Go to program • Another way is to use rdbuf() function ifstream infile(“TEST.TXT”); cout name; cout > age; } }; main() { person pers; pers.getData(); ofstream outfile(“PERSON.DAT”, ios::binary); outfile.write(reinterpret_cast(&pers), sizeof(pers)); Go to program Compatible Data Structures • • • • Reading and writing object can – belong to same class of objects – or if classes are different then they must have same data members (without virtual functions) Person class object occupy 40 + = 44 bytes Make sure a class used to read an object is identical to the class used to write it Also not attempt disk I/O with objects that have pointer data members Go to program 10 I/O with Multiple Objects class person { protected: char name[40]; int age; public: void getData() { cout name; cout age; } void showData() { cout