Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/**
*
*/
package de.tutorials;
import java.io.Serializable;
import java.util.Date;
/**
* @author Tom
*/
public class Person implements Serializable {
private String name;
private Date dateOfBirth;
public Person() {
this(null, null);
}
public Person(String name, Date dateOfBirth) {
this.name = name;
this.dateOfBirth = dateOfBirth;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object obj) {
if (obj instanceof Person) {
Person other = (Person) obj;
return this.name.equals(other.name)
&& this.dateOfBirth.equals(other.dateOfBirth);
} else {
return false;
}
}
public int hashCode() {
return this.name.hashCode() * 37 + this.dateOfBirth.hashCode();
}
public String toString() {
return "Name: " + this.name + ", dateOfBirth: " + this.dateOfBirth;
}
}
/**
*
*/
package de.tutorials;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
/**
* @author Tom
*/
public class SerializationExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Person p = new Person("Tom", new Date());
System.out.println(p);
// Auf die Festplatte speichern
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
"c:/person.ser"));
oos.writeObject(p);
oos.flush();
oos.close();
// Von der Festplatte laden
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"c:/person.ser"));
Person p2 = (Person) ois.readObject();
ois.close();
System.out.println(p2);
}
}
package GUI;
import java.io.Serializable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
public class Serialisieren implements Serializable {
private ObjectOutputStream out;
private ObjectInputStream in;
public Serialisieren(){
try {
out = new ObjectOutputStream(new FileOutputStream("c:/temp/fb.ser"));
in = new ObjectInputStream(new FileInputStream("c:/temp/fb.ser"));
}
catch (IOException io){ }
}
public void speicherObj(Object objekt) throws IOException{
out.writeObject(objekt);
out.flush();
out.close();
}
public Object ladeObj() throws IOException,ClassNotFoundException {
Object temp = in.readObject();
in.close();
return temp;
}
}
Serialisieren ser = new Serialisieren();
try{
panel = (JPanel) ser.ladeObj();
}catch....
catch (IOException io){ }
catch (IOException ioe){ ioe.printStackTrace(); }
null
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException