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.
final String vokabel = in.readLine();
System.out.println(vokabel);
final String[] array = vokabel.split("\\.");
jTextField1.setText(array[0]);
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int r = 0;
int f = 0;
if (jTextField2.getText().equals(array[1])) {
r++;
System.out.println(r);
}
String vokabel = null;
try {
vokabel = in.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(vokabel);
String[] array = vokabel.split("\\.");
jTextField1.setText(array[0]);
jTextField2.setText(null);
}
});
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Arrays;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 06.09.2010
* @author
*/
public class Vokabeltrainer extends JFrame {
// Anfang Attribute
private JTextField jTextField1 = new JTextField();
private JTextField jTextField2 = new JTextField();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
int r = 0;
int f = 0;
public String[] array;
public String vokabel;
// Ende Attribute
public Vokabeltrainer(String title) throws Exception {
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 580;
int frameHeight = 327;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
final BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(
new File(
"C:\\Users\\Yanik\\workspace\\Vokabeltrainer\\src\\Vokabeln.txt")),
// Charset.forName("ISO-8859-1")));
Charset.forName("UTF-8")));
jTextField1.setBounds(200, 64, 361, 24);
jTextField1.setText("");
cp.add(jTextField1);
jTextField2.setBounds(200, 112, 361, 24);
jTextField2.setText("");
cp.add(jTextField2);
jButton1.setBounds(416, 240, 145, 49);
jButton1.setText("Abbrechen");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1_ActionPerformed(evt);
}
});
cp.add(jButton1);
jButton2.setBounds(256, 240, 145, 49);
jButton2.setText("Weiter");
vokabel = in.readLine();
System.out.println(vokabel);
array = vokabel.split("\\.");
jTextField1.setText(array[0]);
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (jTextField2.getText().equals(array[1])) {
r++;
System.out.println("Hallo");
}
System.out.println(r);
try {
vokabel = in.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(vokabel);
jTextField1.setText(array[0]);
jTextField2.setText(null);
}
});
cp.add(jButton2);
jLabel1.setBounds(24, 64, 149, 24);
jLabel1.setText("Deutschvokabel");
jLabel1.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(jLabel1);
jLabel2.setBounds(24, 112, 154, 24);
jLabel2.setText("Englischvokabel");
jLabel2.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(jLabel2);
// Ende Komponenten
setResizable(false);
setVisible(true);
}
// Anfang Methoden
public void jButton1_ActionPerformed(ActionEvent evt) {
System.exit(0);
}
public void jButton2_ActionPerformed(ActionEvent evt) throws Exception {
}
// Ende Methoden
public static void main(String[] args) throws Exception {
new Vokabeltrainer("Vokabeltrainer");
}
}
array = vokabel.split("\\.");
jTextField1.setText(array[0]);
jTextField2.setText(null);
package de.tutorials.forum.hilfe.yax.vokabeltrainer;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
/**
* Beschreibung
*
* @version 1.0 vom 06.09.2010
* @author
*/
public class Vokabeltrainer extends JFrame {
private static final long serialVersionUID = 6156459486834845463L;
public String[] array;
private int f = 0;
private BufferedReader in = null;
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JTextField jTextField1 = new JTextField();
private JTextField jTextField2 = new JTextField();
private int r = 0;
public String vokabel;
public static void main(String[] args) throws Exception {
new Vokabeltrainer("Vokabeltrainer");
}
public Vokabeltrainer(String title) throws Exception {
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
// Testfelder
jTextField1.setBounds(200, 64, 361, 24);
jTextField1.setText("");
cp.add(jTextField1);
jTextField2.setBounds(200, 112, 361, 24);
jTextField2.setText("");
cp.add(jTextField2);
// Buttons
jButton1.setBounds(416, 240, 145, 49);
jButton1.setText("Abbrechen");
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
jButton1_ActionPerformed(evt);
}
});
cp.add(jButton1);
jButton2.setBounds(256, 240, 145, 49);
jButton2.setText("Weiter");
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if(jTextField2.getText().equals(array[1])) {
r++;
System.out.println("Hallo");
}
System.out.println(r);
try {
vokabel = in.readLine();
} catch(IOException e) {
e.printStackTrace();
}
System.out.println(vokabel);
if(vokabel != null) {
array = vokabel.split("\\.");
jTextField1.setText(array[0]);
jTextField2.setText(null);
}
}
});
cp.add(jButton2);
// Labels
jLabel1.setBounds(24, 64, 149, 24);
jLabel1.setText("Deutschvokabel");
jLabel1.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(jLabel1);
jLabel2.setBounds(24, 112, 154, 24);
jLabel2.setText("Englischvokabel");
jLabel2.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(jLabel2);
// Ende Komponenten
// Stream zur Vokabeldatei herstellen und dafür sorgen, dass beim
// Programmende (bzw. beim Beenden der JVM) der Stream wieder sauber
// geschlossen wird
in = new BufferedReader(new InputStreamReader(new FileInputStream(
new File("vokabeln.txt")), Charset.forName("UTF-8")));
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if(in != null) {
try {
in.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
});
// Vokabeln auslesen und erste Vokabel abfragen
vokabel = in.readLine();
System.out.println(vokabel);
array = vokabel.split("\\.");
jTextField1.setText(array[0]);
// Fenstergröße zuweisen, mittig positionieren und sichtbar machen
setSize(580, 327);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
// Anfang Methoden
public void jButton1_ActionPerformed(ActionEvent evt) {
System.exit(0);
}
public void jButton2_ActionPerformed(ActionEvent evt) throws Exception {
}
// Ende Methoden
}