More I/O
Comma-Separated Values
Binary Files
- Primitives stored in native formats
- Usually using the same format as the computer
- Not human readable, but efficient.
Serializable
- Serializable declares that a class can be serialized (written to binary file)
import java.io.Serializable;
public class Species implements Serializable;
{
private String name1;
private int population;
private double growthRate;
private transient int tempVar // not serialized
}
Mine Sweeper
How to figure out if a button was pressed, and if so, which button?
actionPerformed( event e )
Object source = e.getSource(); // pseudo-code
for(int r=0; r<minefield.length; r++) {
for (int c = 0; c < minefield[r].length; c++) {
if (source == minefield[r][c]) {
}
}
}
public class MineSweeper extends JPanel
implements ActionListener, MouseListener?, MouseMotionListener?, KeyListener, WindowListener
{
public static void main(String[] args)
{
JFrame = new JFrame("MineSweeper");
JFrame.setSize(WIDTH, HEIGHT);
mineField[r][c] = new JButton("");
mineField[r][c].addActionListener(this);
this.add(mineField[r][c]);
this.setLayout(new GridLayout(3,3));