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.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class JTableStoreExample extends JFrame {
JTable table;
public JTableStoreExample() {
super("JTableStoreExample");
// setDefaultCloseOperation(EXIT_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
((DefaultTableModel) table.getModel()).getDataVector()
.removeAllElements();
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("c:/jtable.sav"));
oos.writeObject(table);
oos.flush();
oos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
setVisible(false);
dispose();
System.exit(0);
}
});
DefaultTableModel model = new DefaultTableModel(1, 4);
try {
table = loadJTable();
table.setModel(model);
} catch (Exception e) {
e.printStackTrace();
table = new JTable(model);
}
add(new JScrollPane(table), BorderLayout.CENTER);
pack();
setVisible(true);
}
private JTable loadJTable() throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"c:/jtable.sav"));
try {
return (JTable) ois.readObject();
} finally {
if (ois != null) {
ois.close();
}
}
}
public static void main(String[] args) {
new JTableStoreExample();
}
}
package de.tutorials;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
public class JTableStoreExample extends JFrame {
JTable table;
public JTableStoreExample() {
super("JTableStoreExample");
// setDefaultCloseOperation(EXIT_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("c:/jtable.sav"));
oos.writeObject(table.getColumnModel());
oos.flush();
oos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
setVisible(false);
dispose();
System.exit(0);
}
});
DefaultTableModel model = new DefaultTableModel(1, 4);
table = new JTable(model);
try {
TableColumnModel columnModel = loadJTableColumnModel();
table.setColumnModel(columnModel);
} catch (Exception e) {
e.printStackTrace();
}
add(new JScrollPane(table), BorderLayout.CENTER);
pack();
setVisible(true);
}
private TableColumnModel loadJTableColumnModel() throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"c:/jtable.sav"));
try {
return (TableColumnModel) ois.readObject();
} finally {
if (ois != null) {
ois.close();
}
}
}
public static void main(String[] args) {
new JTableStoreExample();
}
}
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
public class TableStore extends JFrame {
JTable table;
public TableStore() {
super("JTableStoreExample");
// setDefaultCloseOperation(EXIT_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("c:/jtable.sav"));
oos.writeObject(table.getColumnModel());
oos.flush();
oos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
setVisible(false);
dispose();
System.exit(0);
}
});
DefaultTableModel model = new DefaultTableModel(1, 4);
try {
table = new JTable();
table.setModel(model);
table.setColumnModel(loadTableColumnModel());
} catch (Exception e) {
e.printStackTrace();
table = new JTable(model);
}
add(new JScrollPane(table), BorderLayout.CENTER);
pack();
setVisible(true);
}
private TableColumnModel loadTableColumnModel() throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"c:/jtable.sav"));
try {
return (TableColumnModel) ois.readObject();
} finally {
if (ois != null) {
ois.close();
}
}
}
public static void main(String[] args) {
new TableStore();
}
}