Topic: JTextArea 事件,请教,谢谢。

  Print this page

1.JTextArea 事件,请教,谢谢。 Copy to clipboard
Posted by: yidengjiang
Posted on: 2004-05-01 18:13

第一次写JTextArea 事件,不是很熟悉,编译出错,请指教。
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.text.*;

public class addSchool extends JFrame implements ActionListener,DocumentListener
{
public static void main(String args[])
{
new addSchool();
}


private JButton addButton,updateButton,deleteButton,exitButton;
private Connection con1;
private Statement state1;
private ResultSet rst1;
private JTextArea textArea1;
private JScrollPane scroller1;
public addSchool()
{
super("添加学校");
Container c=getContentPane();
c.setLayout(null);
//connect_db();

addButton=new JButton("添加学校");
addButton.addActionListener(this);
addButton.setBounds(220,20,100,30);
c.add(addButton);

updateButton=new JButton("修改学校");
updateButton.addActionListener(this);
updateButton.setBounds(220,70,100,30);
c.add(updateButton);

deleteButton=new JButton("删除学校");
deleteButton.addActionListener(this);
deleteButton.setBounds(220,120,100,30);
c.add(deleteButton);

exitButton=new JButton("退出");
exitButton.addActionListener(this);
exitButton.setBounds(250,170,60,30);
c.add(exitButton);








textArea1=new JTextArea();
textArea1.getDocument().addDocumentListener(this);

scroller1=new JScrollPane(textArea1);
scroller1.setBounds(10,10,150,200);
c.add(scroller1);




setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200,200,350,250);
setVisible(true);




}





public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addButton)
{

}
if(e.getSource()==updateButton)
{

}
if(e.getSource()==deleteButton)
{

}
if(e.getSource()==exitButton)
{
//setVisible(false);
dispose();
}
}

public void showDE(DocumentEvent e)
{
Element eroot=textArea1.getDocument().getDefaultRootElement();
DocumentEvent.ElementChange echange=e.getChange(eroot);

if(echange==null)
{
System.out.println("没有找到节点");

}
else
{
System.out.println(echange.getIndex());
}

}
public void changeUpdate(DocumentEvent e)
{
showDEEnvelope;
}
public void insertUpdate(DocumentEvent e)
{
showDEEnvelope;
}
public void removeUpdate(DocumentEvent e)
{
showDEEnvelope;
}
}

2.Re:JTextArea 事件,请教,谢谢。 [Re: yidengjiang] Copy to clipboard
Posted by: kam
Posted on: 2004-05-01 22:18

可否post 出錯的訊息.....

3.Re:JTextArea 事件,请教,谢谢。 [Re: yidengjiang] Copy to clipboard
Posted by: yidengjiang
Posted on: 2004-05-04 10:29

谢谢大家
是我自己粗心
把public void changeUpdate(DocumentEvent e)里少写了一个d
本来应该是public void changedUpdate(DocumentEvent e)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923