Проблема с апплетом

Модератор: Absurd

Ответить
west3940
Сообщения: 1
Зарегистрирован: 27 мар 2011, 15:51

27 мар 2011, 15:55

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication15;

import java.applet.Applet;
import java.awt.*;
import java.util.Scanner;
//import java.io.*;


import java.util.ArrayList;
import java.util.List;

/**
*
* @author nastia
*/
public class NewApplet1 extends Applet {
TextField tf=null;
TextField tf1=null;

Button bt=null;
Label l=null;
String str=null;




/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
tf=new TextField("vvesti slova");

//tf.addTextListener(null);
add (tf);

bt=new Button("OK");
//bt.addActionListener(null);
add(bt);
l=new Label("otvet");
add(l);
// TODO start asynchronous download of heavy resources
}
public void start(Event evt,Object obj)
// public boolean action(Event evt,Object obj)
{

if(evt.target==bt)
{
str=tf.getText();


String sl=str;
System.out.println(sl);
System.out.println(sl);
Scanner in = new Scanner(System.in);
System.out.println(sl);
String sl,g;
String a = new String();
sak = in.nextLine();
in.close();

String[] words = sl.split("\\s*;\\s*");
if (words.length == 0 )
{
System.err.println("No words found");
System.exit(1);
}
String firstWord = words[0];
Character centralChar = getCentralChar(firstWord);
if (centralChar == null)
{
System.err.println("First word '" + firstWord + "' does not have central char");
System.exit(1);
}
char c = centralChar;
List<String> result = new ArrayList<String>();
for (String word : words) {
if (word.indexOf(c) != -1){
result.add(word);
}
}
System.out.println("result = " + result);
l.setText("result = " + result);
}
}
private static Character getCentralChar(String sl) {
if (sl == null || sl.length() == 0 || sl.length() % 2 == 0) {
return null;


}

return sl.charAt(sl.length() / 2);
}
}
Ответить