你看看下面的程序段:
下面是初始化部分: //init JButton...
reloadWebXML = new JButton ("Reload Web.xml file");
//init reloadWebXML button mouse click event...
reloadWebXML.addActionListener (new java.awt.event.ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
//Add crlf to web.xml file...
modifyXMLFile (webXMLPath.getText (), true);
//Remove crlf from web.xml file at the end...
modifyXMLFile (webXMLPath.getText (), false); JOptionPane.showMessageDialog (null, "OK!");
}
});modifyXMLFile是另外一个方法;
下面是初始化部分: //init JButton...
reloadWebXML = new JButton ("Reload Web.xml file");
//init reloadWebXML button mouse click event...
reloadWebXML.addActionListener (new java.awt.event.ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
//Add crlf to web.xml file...
modifyXMLFile (webXMLPath.getText (), true);
//Remove crlf from web.xml file at the end...
modifyXMLFile (webXMLPath.getText (), false); JOptionPane.showMessageDialog (null, "OK!");
}
});modifyXMLFile是另外一个方法;
killme2008(我不会编程)
“java高手请进”,这样的标题会很让人反感的。
newBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
//中间加你要干的事情;
//Exp:c13.setText("改变了!!!");
}
}
);
其他按钮类似。
import javax.swing.*;
import java.awt.*;public class GUIDemo2
{
public static void main(String[] args)
{
//图形界面的屏幕显示部分
JFrame frame=new JFrame("例子");
final JTextField Text=new JTextField("学好JAVA用处大!!!");
JButton Button1 =new JButton("按扭");
JButton Button2 =new JButton("退出");
final JCheckBox cb=new JCheckBox();
frame.getContentPane().setLayout(new FlowLayout( ));
frame.getContentPane().add(Text);
frame.getContentPane().add(Button1);
frame.getContentPane().add(Button2);
frame.getContentPane().add(cb);
frame.pack();
frame.setVisible(true);
Text.setEditable(false); //图形界面的事件处理部分
Button1.addActionListener(new ActionListener() { //内隐类
public void actionPerformed(ActionEvent e) {
Text.setText("这是JTextField和JButton的一个示例");
}
});
Button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent f) { //actionPerformed不可更改
System.exit(0);
}
});
cb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent f){
//cb.setBorderPainted(true);
//cb.setBorderPaintedFlat(true);
//cb.setBackground(Color.red);
cb.setForeground(Color.red); }
});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}