Такая же проблема, но еще и с TextArea.
| Код | //package untitled1; import java.util.*; import java.io.*; import java.lang.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import borland.jbcl.layout.*; import borland.jbcl.control.*;
public class sv1 extends Applet implements ActionListener{ XYLayout xYLayout1 = new XYLayout(); boolean isStandalone = false; public String msg; Button get,put,getT,putT; TextArea ta;
//Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); }
//Construct the applet public sv1() { }
//Initialize the applet public void init() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } setLayout(new FlowLayout(FlowLayout.CENTER)); Button get = new Button("Get"); Button put = new Button("Put"); Button getT = new Button("GetTxt"); Button putT = new Button("PutTxt"); Button prop = new Button("Property"); setLayout(new FlowLayout(FlowLayout.LEFT));
ta=new TextArea("пример текста",10,30); // <-- Пишет абракадаброй
add(ta); add(put); add(get); add(getT); add(putT); add(prop); String tt=ta.getText();
get.addActionListener(this); // put.addActionListener(this); putT.addActionListener(this); getT.addActionListener(this);
} public void actionPerformed(ActionEvent ae){ String str=ae.getActionCommand();
if(str.equals("Get"))ta.setText(getByt()); else if(str.equals("Put"))putByt(ta.getText()); else if(str.equals("GetTxt"))ta.setText(getTxt()); else if(str.equals("PutTxt"))putTxt(ta.getText());
repaint(); } //Component initialization public void jbInit() throws Exception{ xYLayout1.setWidth(400); xYLayout1.setHeight(300); this.setLayout(xYLayout1); }
//Start the applet public void start() { }
//Stop the applet public void stop() { }
//Destroy the applet public void destroy() { }
//Get Applet information public String getAppletInfo() { return "Applet Information"; }
//Get parameter info public String[][] getParameterInfo() { return null; } public void paint(Graphics g){
g.drawString(msg,10,100); } public void putTxt(String s){ try{ ByteArrayOutputStream f=new ByteArrayOutputStream(); byte b[]=s.getBytes(); f.write(b); b=f.toString("Windows-1251").getBytes("Windows-1251"); f.reset(); f.write(b); OutputStream f2=new FileOutputStream("text_for_java.txt"); f.writeTo(f2); f2.close(); }catch(IOException e){} } public String getTxt(){ String t=""; try{
InputStream f2=new FileInputStream("text_for_java.txt"); int a= f2.available(); byte b[]=new byte[a]; DataInputStream bao=new DataInputStream(f2);
bao.read(b);
//ta.setText(new String(b,"UTF8")); t+=new String(b); bao.close(); } catch(IOException ioe){}
return t; }
public void putByt(String t){ try{ //String t=ta.getText(); byte buf[]=t.getBytes("Windows-1251"); //byte buf[]=t.getBytes(); OutputStream f2=new FileOutputStream("text_for_java.dat"); DataOutputStream bao=new DataOutputStream(f2);
bao.writeBytes(new String(buf,"Windows-1251")); //bao.writeBytes(t); bao.close(); } catch(IOException ioe){} }
public String getByt(){ String t=""; try{
InputStream f2=new FileInputStream("text_for_java.dat"); int a= f2.available(); byte b[]=new byte[a]; DataInputStream bao=new DataInputStream(f2);
bao.read(b);
//ta.setText(new String(b,"UTF8")); t+=new String(b,"Windows-1251"); bao.close(); } catch(IOException ioe){}
return t; }
//Main method static public void main(String[] args) { sv1 applet = new sv1(); applet.isStandalone = true; DecoratedFrame frame = new DecoratedFrame(); frame.setTitle("Аплет LEV.SU"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); //applet.paint(); frame.pack(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); } }
|
В форме TextArea текст вводиться с клавиатуры вот так ïðèìåð Код компилил на JBuilder 1.1 Конечно устаревшая вешь но по идее это ведь не должно играть роли. |