import java.awt.event.*;
import javax.swing.*;
public class RegionMatches extends JFrame implements ActionListener{
private JFrame frm;
private JTextField txt1;
private JTextField txt2;
private JTextField txt3;
private JTextField txt4;
private JTextField txt5;
private JButton btn1;
private JLabel lbl;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;
public RegionMatches() {
frm = new JFrame("String charakteristik vergleichen ...");
frm.setLocation(100, 100);
frm.setSize(450, 200);
frm.setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
txt1 = new JTextField();
txt1.setLocation(20, 20);
txt1.setSize(200,20);
frm.add(txt1);
txt2 = new JTextField();
txt2.setLocation(20, 50);
txt2.setSize(200,20);
frm.add(txt2);
lbl2 = new JLabel("Index String1:");
lbl2.setLocation(20, 80);
lbl2.setSize(100, 20);
frm.add(lbl2);
txt3 = new JTextField();
txt3.setLocation(110, 80);
txt3.setSize(20,20);
frm.add(txt3);
lbl3 = new JLabel("Index String2:");
lbl3.setLocation(150, 80);
lbl3.setSize(100, 20);
frm.add(lbl3);
txt4 = new JTextField();
txt4.setLocation(240, 80);
txt4.setSize(20,20);
frm.add(txt4);
lbl4 = new JLabel("Anzahl der Chars:");
lbl4.setLocation(280, 80);
lbl4.setSize(100, 20);
frm.add(lbl4);
txt5 = new JTextField();
txt5.setLocation(390, 80);
txt5.setSize(20,20);
frm.add(txt5);
btn1 = new JButton("Vergleichen...");
btn1.setLocation(250, 20);
btn1.setSize(150, 50);
btn1.addActionListener((ActionListener) this);
frm.add(btn1);
lbl = new JLabel("blubb");
lbl.setLocation(20, 110);
lbl.setSize(350, 20);
frm.add(lbl);
frm.setVisible(true);
}
public static void main(String[] args) {
RegionMatches rgn = new RegionMatches();
}
public void actionPerformed(ActionEvent ae) {
String a = txt1.getText();
String b = txt2.getText();
boolean c = a.regionMatches(Integer.parseInt(txt3.getText()), b, Integer.parseInt(txt4.getText()), Integer.parseInt(txt5.getText()));
String ausgabe = "Das Ergebniss des vergleichs ergibt: Die Strings sind " + ((c == true)? "gleich":"unterschiedlich");
lbl.setText(ausgabe);
}
}